staticweb: Allow empty listings at the root of a container
This is useful for testing that staticweb metadata was properly set before putting data into the container. Change-Id: I433bad1cb3f52ad60a81dcbf3209681f7068ed55
This commit is contained in:
@@ -281,7 +281,7 @@ class _StaticWebContext(WSGIContext):
|
|||||||
body = b''.join(resp)
|
body = b''.join(resp)
|
||||||
if body:
|
if body:
|
||||||
listing = json.loads(body)
|
listing = json.loads(body)
|
||||||
if not listing:
|
if prefix and not listing:
|
||||||
resp = HTTPNotFound()(env, self._start_response)
|
resp = HTTPNotFound()(env, self._start_response)
|
||||||
return self._error_response(resp, env, start_response)
|
return self._error_response(resp, env, start_response)
|
||||||
headers = {'Content-Type': 'text/html; charset=UTF-8'}
|
headers = {'Content-Type': 'text/html; charset=UTF-8'}
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ meta_map = {
|
|||||||
'web-error': 'error.html'}},
|
'web-error': 'error.html'}},
|
||||||
'c13': {'meta': {'web-listings': 'f',
|
'c13': {'meta': {'web-listings': 'f',
|
||||||
'web-listings-css': 'listing.css'}},
|
'web-listings-css': 'listing.css'}},
|
||||||
|
'c14': {'meta': {'web-listings': 't'}},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -271,6 +272,8 @@ class FakeApp(object):
|
|||||||
elif env['PATH_INFO'] == '/v1/a/c12/200error.html':
|
elif env['PATH_INFO'] == '/v1/a/c12/200error.html':
|
||||||
return Response(status='200 Ok', body='error file')(env,
|
return Response(status='200 Ok', body='error file')(env,
|
||||||
start_response)
|
start_response)
|
||||||
|
elif env['PATH_INFO'] == '/v1/a/c14':
|
||||||
|
return self.listing(env, start_response)
|
||||||
else:
|
else:
|
||||||
raise Exception('Unknown path %r' % env['PATH_INFO'])
|
raise Exception('Unknown path %r' % env['PATH_INFO'])
|
||||||
|
|
||||||
@@ -344,6 +347,13 @@ class FakeApp(object):
|
|||||||
"last_modified":"2011-03-24T04:27:52.709100"},
|
"last_modified":"2011-03-24T04:27:52.709100"},
|
||||||
{"subdir":"\u2603/\u2603/"}]
|
{"subdir":"\u2603/\u2603/"}]
|
||||||
'''.strip()
|
'''.strip()
|
||||||
|
elif env['PATH_INFO'] == '/v1/a/c14' and env['QUERY_STRING'] == \
|
||||||
|
'delimiter=/':
|
||||||
|
headers.update({'X-Container-Object-Count': '0',
|
||||||
|
'X-Container-Bytes-Used': '0',
|
||||||
|
'X-Container-Read': '.r:*',
|
||||||
|
'Content-Type': 'application/json; charset=utf-8'})
|
||||||
|
body = '[]'
|
||||||
elif 'prefix=' in env['QUERY_STRING']:
|
elif 'prefix=' in env['QUERY_STRING']:
|
||||||
return Response(status='204 No Content')(env, start_response)
|
return Response(status='204 No Content')(env, start_response)
|
||||||
else:
|
else:
|
||||||
@@ -777,6 +787,16 @@ class TestStaticWeb(unittest.TestCase):
|
|||||||
self.assertEqual(resp.status_int, 200)
|
self.assertEqual(resp.status_int, 200)
|
||||||
self.assertIn(b'index file', resp.body)
|
self.assertIn(b'index file', resp.body)
|
||||||
|
|
||||||
|
def test_container13empty(self):
|
||||||
|
resp = Request.blank(
|
||||||
|
'/v1/a/c14/').get_response(self.test_staticweb)
|
||||||
|
self.assertEqual(resp.status_int, 200)
|
||||||
|
self.assertIn(b'Listing of /v1/a/c14/', resp.body)
|
||||||
|
self.assertIn(b'</style>', resp.body)
|
||||||
|
self.assertNotIn(b'<link', resp.body)
|
||||||
|
self.assertNotIn(b'listing.css', resp.body)
|
||||||
|
self.assertNotIn(b'<td', resp.body)
|
||||||
|
|
||||||
def test_container_404_has_css(self):
|
def test_container_404_has_css(self):
|
||||||
resp = Request.blank('/v1/a/c13/').get_response(
|
resp = Request.blank('/v1/a/c13/').get_response(
|
||||||
self.test_staticweb)
|
self.test_staticweb)
|
||||||
|
|||||||
Reference in New Issue
Block a user