Esempio n. 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()

        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)
Esempio n. 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: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)
Esempio n. 3
0
    def test_copy_index(self):
        ret = (self.containers.list(), False)
        api.swift_get_containers(IsA(http.HttpRequest)).AndReturn(ret)
        self.mox.ReplayAll()

        res = self.client.get(reverse('horizon:project:containers:object_copy',
                                      args=[self.containers.first().name,
                                            self.objects.first().name]))
        self.assertTemplateUsed(res, 'project/containers/copy.html')
Esempio n. 4
0
    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:project:containers:object_copy',
                args=[self.containers.first().name,
                      self.objects.first().name]))
        self.assertTemplateUsed(res, 'project/containers/copy.html')
Esempio n. 5
0
    def test_index_no_container_selected(self):
        containers = self.containers.list()
        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, 'project/containers/index.html')
        self.assertIn('table', res.context)
        resp_containers = res.context['table'].data
        self.assertEqual(len(resp_containers), len(containers))
Esempio n. 6
0
    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, 'project/containers/index.html')
        self.assertIn('table', res.context)
        resp_containers = res.context['table'].data
        self.assertEqual(len(resp_containers), len(containers))
Esempio n. 7
0
 def get_form_kwargs(self):
     kwargs = super(CopyView, self).get_form_kwargs()
     try:
         containers = api.swift_get_containers(self.request)
     except:
         redirect = reverse("horizon:project: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
Esempio n. 8
0
 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
Esempio n. 9
0
    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)
Esempio n. 10
0
 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
Esempio n. 11
0
 def get_form_kwargs(self):
     kwargs = super(CopyView, self).get_form_kwargs()
     try:
         containers = api.swift_get_containers(self.request)
     except:
         redirect = reverse("horizon:project: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
Esempio n. 12
0
    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'))
Esempio n. 13
0
    def test_index_container_selected(self):
        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'))
Esempio n. 14
0
    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)