Example #1
0
    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)
Example #2
0
    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)
Example #3
0
    def test_swift_copy_object(self):
        container = self.containers.get(name=u"container_one\u6346")
        container_2 = self.containers.get(name=u"container_two\u6346")
        obj = self.objects.first()

        swift_api = self.stub_swiftclient()
        self.mox.StubOutWithMock(api.swift, 'swift_object_exists')
        self.mox.StubOutWithMock(container, 'get_object')
        self.mox.StubOutWithMock(obj, 'copy_to')
        # Using the non-unicode names here, see below.
        swift_api.get_container("no_unicode").AndReturn(container)
        api.swift.swift_object_exists(self.request,
                                      "also no unicode",
                                      "obj_with_no_unicode").AndReturn(False)
        container.get_object("obj_with_no_unicode").AndReturn(obj)
        obj.copy_to("also no unicode", "obj_with_no_unicode")
        self.mox.ReplayAll()

        # Unicode fails... we'll get to a successful test in a minute
        with self.assertRaises(exceptions.HorizonException):
            api.swift_copy_object(self.request,
                                  container.name,
                                  obj.name,
                                  container_2.name,
                                  obj.name)

        # Verification handled by mox. No assertions needed.
        container.name = "no_unicode"
        container_2.name = "also no unicode"
        obj.name = "obj_with_no_unicode"
        api.swift_copy_object(self.request,
                                  container.name,
                                  obj.name,
                                  container_2.name,
                                  obj.name)
Example #4
0
    def handle(self, request, data):
        orig_container_name = data['orig_container_name']
        orig_object_name = data['orig_object_name']
        new_container_name = data['new_container_name']
        new_object_name = data['new_object_name']

        api.swift_copy_object(request, orig_container_name,
                              orig_object_name, new_container_name,
                              new_object_name)

        messages.success(request,
                _('Object was successfully copied to %(container)s\%(obj)s') %
                {"container": new_container_name, "obj": new_object_name})

        return shortcuts.redirect(request.build_absolute_uri())
Example #5
0
    def handle(self, request, data):
        orig_container_name = data['orig_container_name']
        orig_object_name = data['orig_object_name']
        new_container_name = data['new_container_name']
        new_object_name = data['new_object_name']

        api.swift_copy_object(request, orig_container_name,
                              orig_object_name, new_container_name,
                              new_object_name)

        messages.success(request,
                _('Object was successfully copied to %(container)s\%(obj)s') %
                {"container": new_container_name, "obj": new_object_name})

        return shortcuts.redirect("horizon:nova:containers:object_index",
                                  data['new_container_name'])
Example #6
0
    def handle(self, request, data):
        orig_container_name = data['orig_container_name']
        orig_object_name = data['orig_object_name']
        new_container_name = data['new_container_name']
        new_object_name = data['new_object_name']

        api.swift_copy_object(request, orig_container_name, orig_object_name,
                              new_container_name, new_object_name)

        messages.success(
            request,
            _('Object was successfully copied to %(container)s\%(obj)s') % {
                "container": new_container_name,
                "obj": new_object_name
            })

        return shortcuts.redirect("horizon:nova:containers:object_index",
                                  data['new_container_name'])
Example #7
0
 def handle(self, request, data):
     object_index = "horizon:nova:containers:object_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']
     try:
         api.swift_copy_object(request,
                               orig_container,
                               orig_object,
                               new_container,
                               new_object)
         vals = {"container": new_container, "obj": new_object}
         messages.success(request, _('Object "%(obj)s" copied to container '
                                     '"%(container)s".') % vals)
     except exceptions.HorizonException, exc:
         messages.error(request, exc)
         return shortcuts.redirect(object_index, orig_container)
Example #8
0
 def handle(self, request, data):
     object_index = "horizon:nova:containers:object_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']
     try:
         api.swift_copy_object(request,
                               orig_container,
                               orig_object,
                               new_container,
                               new_object)
         vals = {"container": new_container, "obj": new_object}
         messages.success(request, _('Object "%(obj)s" copied to container '
                                     '"%(container)s".') % vals)
     except exceptions.HorizonException, exc:
         messages.error(request, exc)
         return shortcuts.redirect(object_index, orig_container)
Example #9
0
    def handle(self, request, data):
        index = "horizon:nova: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)]))
Example #10
0
    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)]))
Example #11
0
 def handle(self, request, data):
     object_index = "horizon:nova:containers:object_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']
     try:
         api.swift_copy_object(request,
                               orig_container,
                               orig_object,
                               new_container,
                               new_object)
         vals = {"container": new_container, "obj": new_object}
         messages.success(request, _('Object "%(obj)s" copied to container '
                                     '"%(container)s".') % vals)
     except:
         redirect = reverse(object_index, args=(orig_container,))
         exceptions.handle(request,
                           _("Unable to copy object."),
                           redirect=redirect)
     return shortcuts.redirect(object_index, new_container)
Example #12
0
    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()
Example #13
0
    def test_swift_copy_object(self):
        container = self.containers.get(name="container_one")
        container_2 = self.containers.get(name="container_two")
        obj = self.objects.first()

        swift_api = self.stub_swiftclient()
        self.mox.StubOutWithMock(api.swift, 'swift_object_exists')
        swift_api.get_container(container.name).AndReturn(container)
        api.swift.swift_object_exists(self.request,
                                      container_2.name,
                                      obj.name).AndReturn(False)
        self.mox.StubOutWithMock(container, 'get_object')
        container.get_object(obj.name).AndReturn(obj)
        self.mox.StubOutWithMock(obj, 'copy_to')
        obj.copy_to(container_2.name, obj.name)
        self.mox.ReplayAll()
        # Verification handled by mox. No assertions needed.
        api.swift_copy_object(self.request,
                              container.name,
                              obj.name,
                              container_2.name,
                              obj.name)
Example #14
0
    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]))