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() 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:project:containers:object_copy', args=[container_1.name, obj.name]) res = self.client.post(copy_url, formData) index_url = reverse('horizon:project:containers:index', args=[wrap_delimiter(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:project:containers:object_copy', args=[container_1.name, obj.name]) res = self.client.post(copy_url, formData) index_url = reverse('horizon:project:containers:index', args=[wrap_delimiter(container_2.name)]) self.assertRedirectsNoFollow(res, index_url)
def handle(self, request, data): index = "horizon:project:containers:index" orig_container = data['orig_container_name'] orig_object = data['orig_object_name'] new_container = data['new_container_name'] new_object = data['new_object_name'] path = data['path'] if path and not path.endswith("/"): path = path + "/" new_path = "%s%s" % (path, new_object) # Iteratively make sure all the directory markers exist. if path: path_component = "" for bit in [i for i in path.split("/") if i]: path_component += bit try: api.swift.swift_create_subfolder(request, new_container, path_component) except: redirect = reverse(index, args=(wrap_delimiter(orig_container),)) exceptions.handle(request, _("Unable to copy object."), redirect=redirect) path_component += "/" # Now copy the object itself. try: api.swift_copy_object(request, orig_container, orig_object, new_container, new_path) dest = "%s/%s" % (new_container, path) vals = {"dest": dest.rstrip("/"), "orig": orig_object.split("/")[-1], "new": new_object} messages.success(request, _('Copied "%(orig)s" to "%(dest)s" as "%(new)s".') % vals) return True except exceptions.HorizonException, exc: messages.error(request, exc) raise exceptions.Http302(reverse(index, args=[wrap_delimiter(orig_container)]))
def handle(self, request, data): index = "horizon:project:containers:index" orig_container = data['orig_container_name'] orig_object = data['orig_object_name'] new_container = data['new_container_name'] new_object = data['new_object_name'] new_path = "%s%s" % (data['path'], new_object) # Iteratively make sure all the directory markers exist. if data['path']: path_component = "" for bit in [i for i in data['path'].split("/") if i]: path_component += bit try: api.swift.swift_create_subfolder(request, new_container, path_component) except: redirect = reverse(index, args=(wrap_delimiter(orig_container),)) exceptions.handle(request, _("Unable to copy object."), redirect=redirect) path_component += "/" # Now copy the object itself. try: api.swift_copy_object(request, orig_container, orig_object, new_container, new_path) dest = "%s/%s" % (new_container, data['path']) vals = {"dest": dest.rstrip("/"), "orig": orig_object.split("/")[-1], "new": new_object} messages.success(request, _('Copied "%(orig)s" to "%(dest)s" as "%(new)s".') % vals) return True except exceptions.HorizonException, exc: messages.error(request, exc) raise exceptions.Http302(reverse(index, args=[wrap_delimiter(orig_container)]))