Merge "Use HEAD when retrieving Container details"
This commit is contained in:
commit
510eb5a5fc
@ -132,8 +132,12 @@ def swift_get_containers(request, marker=None):
|
||||
return (container_objs, False)
|
||||
|
||||
|
||||
def swift_get_container(request, container_name):
|
||||
headers, data = swift_api(request).get_object(container_name, "")
|
||||
def swift_get_container(request, container_name, with_data=True):
|
||||
if with_data:
|
||||
headers, data = swift_api(request).get_object(container_name, "")
|
||||
else:
|
||||
data = None
|
||||
headers = swift_api(request).head_container(container_name)
|
||||
timestamp = None
|
||||
try:
|
||||
ts_float = float(headers.get('x-timestamp'))
|
||||
@ -145,6 +149,7 @@ def swift_get_container(request, container_name):
|
||||
'container_object_count': headers.get('x-container-object-count'),
|
||||
'container_bytes_used': headers.get('x-container-bytes-used'),
|
||||
'timestamp': timestamp,
|
||||
'data': data,
|
||||
}
|
||||
return Container(container_info)
|
||||
|
||||
|
@ -236,7 +236,8 @@ class SwiftTests(test.TestCase):
|
||||
container = self.containers.first()
|
||||
|
||||
api.swift.swift_get_container(IsA(http.HttpRequest),
|
||||
container.name) \
|
||||
container.name,
|
||||
with_data=False) \
|
||||
.AndReturn(container)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
|
@ -234,7 +234,8 @@ class ContainerDetailView(forms.ModalFormMixin, generic.TemplateView):
|
||||
try:
|
||||
self._object = api.swift.swift_get_container(
|
||||
self.request,
|
||||
self.kwargs["container_name"])
|
||||
self.kwargs["container_name"],
|
||||
with_data=False)
|
||||
except Exception:
|
||||
redirect = reverse("horizon:project:containers:index")
|
||||
exceptions.handle(self.request,
|
||||
|
@ -42,6 +42,30 @@ class SwiftApiTests(test.APITestCase):
|
||||
self.assertEqual(len(conts), len(containers))
|
||||
self.assertFalse(more)
|
||||
|
||||
def test_swift_get_container_with_data(self):
|
||||
container = self.containers.first()
|
||||
objects = self.objects.list()
|
||||
swift_api = self.stub_swiftclient()
|
||||
swift_api.get_object(container.name, "") \
|
||||
.AndReturn((container, objects))
|
||||
self.mox.ReplayAll()
|
||||
|
||||
cont = api.swift.swift_get_container(self.request, container.name)
|
||||
self.assertEqual(cont.name, container.name)
|
||||
self.assertEqual(len(cont.data), len(objects))
|
||||
|
||||
def test_swift_get_container_without_data(self):
|
||||
container = self.containers.first()
|
||||
swift_api = self.stub_swiftclient()
|
||||
swift_api.head_container(container.name).AndReturn(container)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
cont = api.swift.swift_get_container(self.request,
|
||||
container.name,
|
||||
with_data=False)
|
||||
self.assertEqual(cont.name, container.name)
|
||||
self.assertIsNone(cont.data)
|
||||
|
||||
def test_swift_create_duplicate_container(self):
|
||||
container = self.containers.first()
|
||||
swift_api = self.stub_swiftclient(expected_calls=2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user