示例#1
0
文件: tests.py 项目: nimbis/horizon
    def test_index(self):
        self.mox.StubOutWithMock(api, "swift_get_objects")
        ret = (self.objects.list(), False)
        api.swift_get_objects(IsA(http.HttpRequest), self.containers.first().name, marker=None).AndReturn(ret)
        self.mox.ReplayAll()

        res = self.client.get(reverse("horizon:nova:containers:object_index", args=[self.containers.first().name]))
        self.assertTemplateUsed(res, "nova/objects/index.html")
        expected = [obj.name for obj in self.objects.list()]
        self.assertQuerysetEqual(res.context["table"].data, expected, lambda obj: obj.name)
示例#2
0
    def test_index(self):
        self.mox.StubOutWithMock(api, 'swift_get_objects')
        api.swift_get_objects(
                IsA(http.HttpRequest),
                self.CONTAINER_NAME,
                marker=None).AndReturn((self.swift_objects, False))

        self.mox.ReplayAll()

        res = self.client.get(reverse('horizon:nova:containers:object_index',
                                      args=[self.CONTAINER_NAME]))
        self.assertTemplateUsed(res, 'nova/objects/index.html')
        self.assertItemsEqual(res.context['table'].data, self.swift_objects)
示例#3
0
    def test_index(self):
        self.mox.StubOutWithMock(api, 'swift_get_objects')
        api.swift_get_objects(
                IsA(http.HttpRequest),
                self.CONTAINER_NAME,
                marker=None).AndReturn((self.swift_objects, False))

        self.mox.ReplayAll()

        res = self.client.get(reverse('horizon:nova:containers:object_index',
                                      args=[self.CONTAINER_NAME]))
        self.assertTemplateUsed(res, 'nova/objects/index.html')
        self.assertItemsEqual(res.context['objects'], self.swift_objects)
    def test_index(self):
        self.mox.StubOutWithMock(api, 'swift_get_objects')
        ret = (self.objects.list(), False)
        api.swift_get_objects(IsA(http.HttpRequest),
                              self.containers.first().name,
                              marker=None).AndReturn(ret)
        self.mox.ReplayAll()

        res = self.client.get(
            reverse('horizon:nova:containers:object_index',
                    args=[self.containers.first().name]))
        self.assertTemplateUsed(res, 'nova/objects/index.html')
        expected = [obj.name for obj in self.objects.list()]
        self.assertQuerysetEqual(res.context['table'].data, expected,
                                 lambda obj: obj.name)
示例#5
0
文件: views.py 项目: ehazlett/horizon
def object_index(request, container_name):
    marker = request.GET.get('marker', None)

    delete_form, handled = DeleteObject.maybe_handle(request)
    if handled:
        return handled

    filter_form, paged_objects = FilterObjects.maybe_handle(request)

    if paged_objects is None:
        filter_form.fields['container_name'].initial = container_name
        objects, more = api.swift_get_objects(request,
                                              container_name,
                                              marker=marker)
    else:
        objects, more = paged_objects

    delete_form.fields['container_name'].initial = container_name
    return shortcuts.render(request,
                            'nova/objects/index.html',
                            {'container_name': container_name,
                             'objects': objects,
                             'more': more,
                             'delete_form': delete_form,
                             'filter_form': filter_form})
示例#6
0
文件: views.py 项目: termie/horizon
def object_index(request, container_name):
    marker = request.GET.get('marker', None)

    delete_form, handled = DeleteObject.maybe_handle(request)
    if handled:
        return handled

    filter_form, paged_objects = FilterObjects.maybe_handle(request)

    if paged_objects is None:
        filter_form.fields['container_name'].initial = container_name
        objects, more = api.swift_get_objects(request,
                                              container_name,
                                              marker=marker)
    else:
        objects, more = paged_objects

    delete_form.fields['container_name'].initial = container_name
    return shortcuts.render(
        request, 'nova/objects/index.html', {
            'container_name': container_name,
            'objects': objects,
            'more': more,
            'delete_form': delete_form,
            'filter_form': filter_form
        })
示例#7
0
    def objects(self):
        """ Returns a list of objects given the subfolder's path.

        The path is from the kwargs of the request.
        """
        if not hasattr(self, "_objects"):
            objects = []
            self._more = None
            marker = self.request.GET.get('marker', None)
            container_name = self.kwargs['container_name']
            subfolder = self.kwargs['subfolder_path']
            prefix = None
            if container_name:
                self.navigation_selection = True
                if subfolder:
                    prefix = subfolder
                try:
                    objects, self._more = api.swift_get_objects(self.request,
                                                                container_name,
                                                                marker=marker,
                                                                prefix=prefix)
                except:
                    self._more = None
                    objects = []
                    msg = _('Unable to retrieve object list.')
                    exceptions.handle(self.request, msg)
            self._objects = objects
        return self._objects
示例#8
0
文件: tests.py 项目: mshabdiz/horizon
    def test_index(self):
        self.mox.StubOutWithMock(api, 'swift_get_objects')
        ret = (self.objects.list(), False)
        api.swift_get_objects(IsA(http.HttpRequest),
                              self.containers.first().name,
                              marker=None,
                              path=None).AndReturn(ret)
        self.mox.ReplayAll()

        res = self.client.get(
            reverse('horizon:nova:containers:object_index',
                    args=[self.containers.first().name]))
        self.assertTemplateUsed(res, 'nova/containers/detail.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'))
示例#9
0
文件: tests.py 项目: MrRagga-/horizon
    def test_index(self):
        self.mox.StubOutWithMock(api, 'swift_get_objects')
        ret = (self.objects.list(), False)
        api.swift_get_objects(IsA(http.HttpRequest),
                              self.containers.first().name,
                              marker=None,
                              path=None).AndReturn(ret)
        self.mox.ReplayAll()

        res = self.client.get(reverse('horizon:nova:containers:object_index',
                                      args=[self.containers.first().name]))
        self.assertTemplateUsed(res, 'nova/containers/detail.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'))
示例#10
0
文件: views.py 项目: nimbis/horizon
 def get_data(self):
     objects = []
     self._more = None
     marker = self.request.GET.get("marker", None)
     container_name = self.kwargs["container_name"]
     try:
         objects, self._more = api.swift_get_objects(self.request, container_name, marker=marker)
     except:
         msg = _("Unable to retrieve object list.")
         exceptions.handle(self.request, msg)
     return objects
示例#11
0
    def test_filter(self):
        PREFIX = 'prefix'

        formData = {'method': 'FilterObjects',
                    'container_name': self.CONTAINER_NAME,
                    'object_prefix': PREFIX,
                    }

        self.mox.StubOutWithMock(api, 'swift_get_objects')
        api.swift_get_objects(IsA(http.HttpRequest),
                              unicode(self.CONTAINER_NAME),
                              prefix=unicode(PREFIX))\
                              .AndReturn((self.swift_objects, False))

        self.mox.ReplayAll()

        res = self.client.post(reverse('horizon:nova:containers:object_index',
                                       args=[self.CONTAINER_NAME]),
                               formData)

        self.assertTemplateUsed(res, 'nova/objects/index.html')
示例#12
0
    def test_filter(self):
        PREFIX = 'prefix'

        formData = {'method': 'FilterObjects',
                    'container_name': self.CONTAINER_NAME,
                    'object_prefix': PREFIX,
                    }

        self.mox.StubOutWithMock(api, 'swift_get_objects')
        api.swift_get_objects(IsA(http.HttpRequest),
                              unicode(self.CONTAINER_NAME),
                              prefix=unicode(PREFIX))\
                              .AndReturn(self.swift_objects)

        self.mox.ReplayAll()

        res = self.client.post(reverse('horizon:nova:containers:object_index',
                                       args=[self.CONTAINER_NAME]),
                               formData)

        self.assertTemplateUsed(res, 'nova/objects/index.html')
 def get_data(self):
     objects = []
     self._more = None
     marker = self.request.GET.get('marker', None)
     container_name = self.kwargs['container_name']
     try:
         objects, self._more = api.swift_get_objects(self.request,
                                                     container_name,
                                                     marker=marker)
     except:
         msg = _('Unable to retrieve object list.')
         exceptions.handle(self.request, msg)
     return objects
示例#14
0
    def handle(self, request, data):
        object_prefix = data['object_prefix'] or None

        objects = api.swift_get_objects(request,
                                        data['container_name'],
                                        prefix=object_prefix)

        if not objects:
            messages.info(request,
                         _('There are no objects matching that prefix in %s') %
                         data['container_name'])

        return objects
示例#15
0
    def test_index_subfolders(self):
        ret = (self.objects.list(), False)
        api.swift_get_objects(IsA(http.HttpRequest),
                              self.containers.first().name,
                              marker=None,
                              path='sub1/sub2').AndReturn(ret)
        self.mox.ReplayAll()

        res = self.client.get(reverse('horizon:nova:containers:object_index',
                                      args=[self.containers.first().name,
                                            u'sub1/sub2/']))
        self.assertEquals(res.context['container_name'],
                          self.containers.first().name)
        self.assertListEqual(res.context['subfolders'],
                             [('sub1', 'sub1/'),
                              ('sub2', 'sub1/sub2/'), ])
        self.assertTemplateUsed(res, 'nova/containers/detail.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'))
示例#16
0
    def handle(self, request, data):
        object_prefix = data['object_prefix'] or None

        objects, more = api.swift_get_objects(request,
                                              data['container_name'],
                                              prefix=object_prefix)

        if not objects:
            messages.info(
                request,
                _('There are no objects matching that prefix in %s') %
                data['container_name'])

        return (objects, more)
示例#17
0
    def test_swift_get_objects(self):
        container = self.containers.first()
        objects = self.objects.list()

        swift_api = self.stub_swiftclient()
        swift_api.get_container(container.name).AndReturn(container)
        self.mox.StubOutWithMock(container, 'get_objects')
        container.get_objects(limit=1001,
                              marker=None,
                              prefix=None).AndReturn(objects)
        self.mox.ReplayAll()

        (objs, more) = api.swift_get_objects(self.request, container.name)
        self.assertEqual(len(objs), len(objects))
        self.assertFalse(more)
示例#18
0
    def test_swift_get_objects(self):
        container = self.containers.first()
        objects = self.objects.list()

        swift_api = self.stub_swiftclient()
        swift_api.get_container(container.name).AndReturn(container)
        self.mox.StubOutWithMock(container, 'get_objects')
        container.get_objects(limit=1001,
                              marker=None,
                              prefix=None).AndReturn(objects)
        self.mox.ReplayAll()

        (objs, more) = api.swift_get_objects(self.request, container.name)
        self.assertEqual(len(objs), len(objects))
        self.assertFalse(more)
示例#19
0
    def test_swift_get_objects(self):
        container = self.containers.first()
        objects = self.objects.list()

        swift_api = self.stub_swiftclient()
        swift_api.get_container(container.name,
                                limit=1001,
                                marker=None,
                                prefix=None,
                                delimiter='/',
                                full_listing=True).AndReturn([{}, objects])
        self.mox.ReplayAll()

        (objs, more) = api.swift_get_objects(self.request, container.name)
        self.assertEqual(len(objs), len(objects))
        self.assertFalse(more)