def test_copy(self): container_1 = self.containers.get(name=u"container_one\u6346") container_2 = self.containers.get(name=u"container_two\u6346") obj = self.objects.first() self.mox.StubOutWithMock(api, 'swift_get_containers') self.mox.StubOutWithMock(api, 'swift_copy_object') ret = (self.containers.list(), False) api.swift_get_containers(IsA(http.HttpRequest)).AndReturn(ret) api.swift_copy_object(IsA(http.HttpRequest), container_1.name, obj.name, container_2.name, obj.name) self.mox.ReplayAll() formData = { 'method': forms.CopyObject.__name__, 'new_container_name': container_2.name, 'new_object_name': obj.name, 'orig_container_name': container_1.name, 'orig_object_name': obj.name } copy_url = reverse('horizon:nova:containers:object_copy', args=[container_1.name, obj.name]) res = self.client.post(copy_url, formData) index_url = reverse('horizon:nova:containers:object_index', args=[container_2.name]) self.assertRedirectsNoFollow(res, index_url)
def test_copy(self): container_1 = self.containers.get(name=u"container_one\u6346") container_2 = self.containers.get(name=u"container_two\u6346") obj = self.objects.first() self.mox.StubOutWithMock(api, 'swift_get_containers') self.mox.StubOutWithMock(api, 'swift_copy_object') ret = (self.containers.list(), False) api.swift_get_containers(IsA(http.HttpRequest)).AndReturn(ret) api.swift_copy_object(IsA(http.HttpRequest), container_1.name, obj.name, container_2.name, obj.name) self.mox.ReplayAll() formData = {'method': forms.CopyObject.__name__, 'new_container_name': container_2.name, 'new_object_name': obj.name, 'orig_container_name': container_1.name, 'orig_object_name': obj.name} copy_url = reverse('horizon:nova:containers:object_copy', args=[container_1.name, obj.name]) res = self.client.post(copy_url, formData) index_url = reverse('horizon:nova:containers:object_index', args=[container_2.name]) self.assertRedirectsNoFollow(res, index_url)
def test_copy_index(self): self.mox.StubOutWithMock(api, 'swift_get_containers') ret = (self.containers.list(), False) api.swift_get_containers(IsA(http.HttpRequest)).AndReturn(ret) self.mox.ReplayAll() res = self.client.get(reverse('horizon:nova:containers:object_copy', args=[self.containers.first().name, self.objects.first().name])) self.assertTemplateUsed(res, 'nova/objects/copy.html')
def test_index(self): containers = self.containers.list() self.mox.StubOutWithMock(api, "swift_get_containers") api.swift_get_containers(IsA(http.HttpRequest), marker=None).AndReturn((containers, False)) self.mox.ReplayAll() res = self.client.get(CONTAINER_INDEX_URL) self.assertTemplateUsed(res, "nova/containers/index.html") self.assertIn("table", res.context) resp_containers = res.context["table"].data self.assertEqual(len(resp_containers), len(containers))
def test_copy_index(self): self.mox.StubOutWithMock(api, 'swift_get_containers') ret = (self.containers.list(), False) api.swift_get_containers(IsA(http.HttpRequest)).AndReturn(ret) self.mox.ReplayAll() res = self.client.get( reverse( 'horizon:nova:containers:object_copy', args=[self.containers.first().name, self.objects.first().name])) self.assertTemplateUsed(res, 'nova/containers/copy.html')
def test_index(self): containers = self.containers.list() self.mox.StubOutWithMock(api, 'swift_get_containers') api.swift_get_containers(IsA(http.HttpRequest), marker=None) \ .AndReturn((containers, False)) self.mox.ReplayAll() res = self.client.get(CONTAINER_INDEX_URL) self.assertTemplateUsed(res, 'nova/containers/index.html') self.assertIn('table', res.context) resp_containers = res.context['table'].data self.assertEqual(len(resp_containers), len(containers))
def test_index_no_container_selected(self): containers = self.containers.list() self.mox.StubOutWithMock(api, 'swift_get_containers') api.swift_get_containers(IsA(http.HttpRequest), marker=None) \ .AndReturn((containers, False)) self.mox.ReplayAll() res = self.client.get(CONTAINER_INDEX_URL) self.assertTemplateUsed(res, 'nova/containers/index.html') self.assertIn('table', res.context) resp_containers = res.context['table'].data self.assertEqual(len(resp_containers), len(containers))
def test_index(self): self.mox.StubOutWithMock(api, 'swift_get_containers') api.swift_get_containers( IsA(http.HttpRequest), marker=None).AndReturn([self.container]) self.mox.ReplayAll() res = self.client.get(CONTAINER_INDEX_URL) self.assertTemplateUsed(res, 'nova/containers/index.html') self.assertIn('containers', res.context) containers = res.context['containers'] self.assertEqual(len(containers), 1) self.assertEqual(containers[0].name, 'containerName')
def test_index(self): self.mox.StubOutWithMock(api, 'swift_get_containers') api.swift_get_containers( IsA(http.HttpRequest), marker=None).AndReturn( ([self.container], False)) self.mox.ReplayAll() res = self.client.get(CONTAINER_INDEX_URL) self.assertTemplateUsed(res, 'nova/containers/index.html') self.assertIn('containers', res.context) containers = res.context['containers'] self.assertEqual(len(containers), 1) self.assertEqual(containers[0].name, 'containerName')
def test_copy_index(self): OBJECT_NAME = 'objectName' container = self.mox.CreateMock(api.Container) container.name = self.CONTAINER_NAME self.mox.StubOutWithMock(api, 'swift_get_containers') api.swift_get_containers(IsA(http.HttpRequest)).AndReturn( ([container], False)) self.mox.ReplayAll() res = self.client.get( reverse('horizon:nova:containers:object_copy', args=[self.CONTAINER_NAME, OBJECT_NAME])) self.assertTemplateUsed(res, 'nova/objects/copy.html')
def test_copy_index(self): OBJECT_NAME = 'objectName' container = self.mox.CreateMock(api.Container) container.name = self.CONTAINER_NAME self.mox.StubOutWithMock(api, 'swift_get_containers') api.swift_get_containers( IsA(http.HttpRequest)).AndReturn(([container], False)) self.mox.ReplayAll() res = self.client.get(reverse('horizon:nova:containers:object_copy', args=[self.CONTAINER_NAME, OBJECT_NAME])) self.assertTemplateUsed(res, 'nova/objects/copy.html')
def get_form_kwargs(self): kwargs = super(CopyView, self).get_form_kwargs() try: containers = api.swift_get_containers(self.request) except: redirect = reverse("horizon:nova:containers:index") exceptions.handle(self.request, _("Unable to list containers."), redirect=redirect) kwargs["containers"] = [(c.name, c.name) for c in containers[0]] return kwargs
def get_data(self): containers = [] self._more = None marker = self.request.GET.get("marker", None) try: containers, self._more = api.swift_get_containers(self.request, marker=marker) except: msg = _("Unable to retrieve container list.") exceptions.handle(self.request, msg) return containers
def test_swift_get_containers(self): containers = self.containers.list() swift_api = self.stub_swiftclient() swift_api.get_all_containers(limit=1001, marker=None).AndReturn(containers) self.mox.ReplayAll() (conts, more) = api.swift_get_containers(self.request) self.assertEqual(len(conts), len(containers)) self.assertFalse(more)
def get_containers_data(self): containers = [] self._more = None marker = self.request.GET.get('marker', None) try: containers, self._more = api.swift_get_containers(self.request, marker=marker) except: msg = _('Unable to retrieve container list.') exceptions.handle(self.request, msg) return containers
def get_form_kwargs(self): kwargs = super(CopyView, self).get_form_kwargs() try: containers = api.swift_get_containers(self.request) except: redirect = reverse("horizon:nova:containers:index") exceptions.handle(self.request, _('Unable to list containers.'), redirect=redirect) kwargs['containers'] = [(c.name, c.name) for c in containers[0]] return kwargs
def test_index_container_selected(self): self.mox.StubOutWithMock(api, 'swift_get_containers') self.mox.StubOutWithMock(api, 'swift_get_objects') containers = (self.containers.list(), False) ret = (self.objects.list(), False) api.swift_get_containers(IsA(http.HttpRequest), marker=None).AndReturn(containers) api.swift_get_objects(IsA(http.HttpRequest), self.containers.first().name, marker=None, prefix=None).AndReturn(ret) self.mox.ReplayAll() res = self.client.get( reverse('horizon:project:containers:index', args=[wrap_delimiter(self.containers.first().name)])) self.assertTemplateUsed(res, 'project/containers/index.html') # UTF8 encoding here to ensure there aren't problems with Nose output. expected = [obj.name.encode('utf8') for obj in self.objects.list()] self.assertQuerysetEqual(res.context['objects_table'].data, expected, lambda obj: obj.name.encode('utf8'))
def test_swift_get_containers(self): containers = self.containers.list() cont_data = [c._apidict for c in containers] swift_api = self.stub_swiftclient() swift_api.get_account(limit=1001, marker=None, full_listing=True).AndReturn([{}, cont_data]) self.mox.ReplayAll() (conts, more) = api.swift_get_containers(self.request) self.assertEqual(len(conts), len(containers)) self.assertFalse(more)
def index(request): marker = request.GET.get('marker', None) delete_form, handled = DeleteContainer.maybe_handle(request) if handled: return handled containers = api.swift_get_containers(request, marker=marker) return shortcuts.render(request, 'nova/containers/index.html', {'containers': containers, 'delete_form': delete_form})
def test_copy(self): NEW_CONTAINER_NAME = self.CONTAINER_NAME NEW_OBJECT_NAME = 'newObjectName' ORIG_CONTAINER_NAME = 'origContainerName' ORIG_OBJECT_NAME = 'origObjectName' formData = {'method': 'CopyObject', 'new_container_name': NEW_CONTAINER_NAME, 'new_object_name': NEW_OBJECT_NAME, 'orig_container_name': ORIG_CONTAINER_NAME, 'orig_object_name': ORIG_OBJECT_NAME} container = self.mox.CreateMock(api.Container) container.name = self.CONTAINER_NAME self.mox.StubOutWithMock(api, 'swift_get_containers') api.swift_get_containers( IsA(http.HttpRequest)).AndReturn([container]) self.mox.StubOutWithMock(api, 'swift_copy_object') api.swift_copy_object(IsA(http.HttpRequest), ORIG_CONTAINER_NAME, ORIG_OBJECT_NAME, NEW_CONTAINER_NAME, NEW_OBJECT_NAME) self.mox.ReplayAll() res = self.client.post(reverse('horizon:nova:containers:object_copy', args=[ORIG_CONTAINER_NAME, ORIG_OBJECT_NAME]), formData) self.assertRedirectsNoFollow(res, reverse('horizon:nova:containers:object_copy', args=[ORIG_CONTAINER_NAME, ORIG_OBJECT_NAME])) self.mox.VerifyAll()
def index(request): marker = request.GET.get('marker', None) delete_form, handled = DeleteContainer.maybe_handle(request) if handled: return handled try: containers, more = api.swift_get_containers(request, marker=marker) except Exception, e: containers, more = None, None msg = _('Error retrieving container list: %s') % e LOG.exception(msg) messages.error(request, msg)
def index(request): marker = request.GET.get('marker', None) delete_form, handled = DeleteContainer.maybe_handle(request) if handled: return handled containers, more = api.swift_get_containers(request, marker=marker) return shortcuts.render(request, 'nova/containers/index.html', { 'containers': containers, 'delete_form': delete_form, 'more': more })
def test_index_container_selected(self): self.mox.StubOutWithMock(api, 'swift_get_containers') self.mox.StubOutWithMock(api, 'swift_get_objects') containers = (self.containers.list(), False) ret = (self.objects.list(), False) api.swift_get_containers(IsA(http.HttpRequest), marker=None).AndReturn(containers) api.swift_get_objects(IsA(http.HttpRequest), self.containers.first().name, marker=None, prefix=None).AndReturn(ret) self.mox.ReplayAll() res = self.client.get(reverse('horizon:nova:containers:index', args=[wrap_delimiter(self.containers .first() .name)])) self.assertTemplateUsed(res, 'nova/containers/index.html') # UTF8 encoding here to ensure there aren't problems with Nose output. expected = [obj.name.encode('utf8') for obj in self.objects.list()] self.assertQuerysetEqual(res.context['objects_table'].data, expected, lambda obj: obj.name.encode('utf8'))
def test_copy(self): NEW_CONTAINER_NAME = self.CONTAINER_NAME NEW_OBJECT_NAME = 'newObjectName' ORIG_CONTAINER_NAME = 'origContainerName' ORIG_OBJECT_NAME = 'origObjectName' formData = { 'method': 'CopyObject', 'new_container_name': NEW_CONTAINER_NAME, 'new_object_name': NEW_OBJECT_NAME, 'orig_container_name': ORIG_CONTAINER_NAME, 'orig_object_name': ORIG_OBJECT_NAME } container = self.mox.CreateMock(api.Container) container.name = self.CONTAINER_NAME self.mox.StubOutWithMock(api, 'swift_get_containers') api.swift_get_containers(IsA(http.HttpRequest)).AndReturn( ([container], False)) self.mox.StubOutWithMock(api, 'swift_copy_object') api.swift_copy_object(IsA(http.HttpRequest), ORIG_CONTAINER_NAME, ORIG_OBJECT_NAME, NEW_CONTAINER_NAME, NEW_OBJECT_NAME) self.mox.ReplayAll() res = self.client.post( reverse('horizon:nova:containers:object_copy', args=[ORIG_CONTAINER_NAME, ORIG_OBJECT_NAME]), formData) self.assertRedirectsNoFollow( res, reverse('horizon:nova:containers:object_index', args=[NEW_CONTAINER_NAME]))
def object_copy(request, container_name, object_name): containers = \ [(c.name, c.name) for c in api.swift_get_containers( request)[0]] form, handled = CopyObject.maybe_handle(request, containers=containers) if handled: return handled form.fields['new_container_name'].initial = container_name form.fields['orig_container_name'].initial = container_name form.fields['orig_object_name'].initial = object_name return shortcuts.render( request, 'nova/objects/copy.html', { 'container_name': container_name, 'object_name': object_name, 'copy_form': form })
def object_copy(request, container_name, object_name): containers = \ [(c.name, c.name) for c in api.swift_get_containers( request)] form, handled = CopyObject.maybe_handle(request, containers=containers) if handled: return handled form.fields['new_container_name'].initial = container_name form.fields['orig_container_name'].initial = container_name form.fields['orig_object_name'].initial = object_name return shortcuts.render(request, 'nova/objects/copy.html', {'container_name': container_name, 'object_name': object_name, 'copy_form': form})