Ejemplo 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()

        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)
Ejemplo 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: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)
Ejemplo n.º 3
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:nova:containers:object_copy',
                                      args=[self.containers.first().name,
                                            self.objects.first().name]))
        self.assertTemplateUsed(res, 'nova/objects/copy.html')
Ejemplo n.º 4
0
    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))
Ejemplo n.º 5
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:nova:containers:object_copy',
                args=[self.containers.first().name,
                      self.objects.first().name]))
        self.assertTemplateUsed(res, 'nova/containers/copy.html')
Ejemplo n.º 6
0
    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))
Ejemplo n.º 7
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, 'nova/containers/index.html')
        self.assertIn('table', res.context)
        resp_containers = res.context['table'].data
        self.assertEqual(len(resp_containers), len(containers))
Ejemplo n.º 8
0
    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')
Ejemplo n.º 9
0
    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')
Ejemplo n.º 10
0
    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')
Ejemplo n.º 11
0
    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')
Ejemplo n.º 12
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: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
Ejemplo n.º 13
0
 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
Ejemplo n.º 14
0
    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)
Ejemplo n.º 15
0
    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)
Ejemplo n.º 16
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
Ejemplo n.º 17
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: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
Ejemplo n.º 18
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'))
Ejemplo n.º 19
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)
Ejemplo n.º 20
0
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})
Ejemplo n.º 21
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()
Ejemplo n.º 22
0
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)
Ejemplo n.º 23
0
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)
Ejemplo n.º 24
0
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
    })
Ejemplo n.º 25
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: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'))
Ejemplo n.º 26
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]))
Ejemplo n.º 27
0
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
        })
Ejemplo n.º 28
0
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})