Esempio n. 1
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('dash_objects',
                    args=[self.TEST_TENANT, self.CONTAINER_NAME]), formData)

        self.assertTemplateUsed(res,
                                'django_openstack/dash/objects/index.html')

        self.mox.VerifyAll()
Esempio n. 2
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('dash_objects',
                                       args=[self.TEST_TENANT,
                                             self.CONTAINER_NAME]),
                               formData)

        self.assertTemplateUsed(res,
                'django_openstack/dash/objects/index.html')

        self.mox.VerifyAll()
    def test_index(self):
        self.mox.StubOutWithMock(api, 'swift_get_objects')
        api.swift_get_objects(
                IsA(http.HttpRequest),
                self.CONTAINER_NAME).AndReturn(self.swift_objects)

        self.mox.ReplayAll()

        res = self.client.get(reverse('dash_objects',
                                      args=[self.TEST_TENANT,
                                            self.CONTAINER_NAME]))
        self.assertTemplateUsed(res, 'dash_objects.html')
        self.assertItemsEqual(res.context['objects'], self.swift_objects)

        self.mox.VerifyAll()
Esempio n. 4
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)

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('dash_objects',
                    args=[self.TEST_TENANT, self.CONTAINER_NAME]))
        self.assertTemplateUsed(res,
                                'django_openstack/dash/objects/index.html')
        self.assertItemsEqual(res.context['objects'], self.swift_objects)

        self.mox.VerifyAll()
Esempio n. 5
0
    def test_container_public_get(self):
        self.mox.StubOutWithMock(api, 'swift_get_container')
        api.swift_get_container(
                IsA(http.HttpRequest), self.container.name).AndReturn(self.container)

        self.mox.StubOutWithMock(api, 'swift_get_objects')
        api.swift_get_objects(
                IsA(http.HttpRequest), self.container.name).AndReturn([self.object])
                
        self.mox.ReplayAll()

        res = self.client.get(reverse('dash_containers_public',
                              args=['tenant', self.container.name]))

        self.assertTemplateUsed(res, 'django_openstack/dash/containers/public.html')
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
Esempio n. 6
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
Esempio n. 7
0
def public(request, tenant_id, container_name):


    try:
        container = api.swift_get_container(request, container_name)
        objects = [(o.name, o.name) for o in api.swift_get_objects(request, container_name)]
    except ResponseError, e:
        messages.error(request, 'Unable to retrive container meta data for public. \
                       Perhaps you do not have right permission : %s'  % str(e))
        return shortcuts.redirect('dash_containers', tenant_id)
Esempio n. 8
0
    def test_container_public_get(self):
        self.mox.StubOutWithMock(api, 'swift_get_container')
        api.swift_get_container(IsA(http.HttpRequest),
                                self.container.name).AndReturn(self.container)

        self.mox.StubOutWithMock(api, 'swift_get_objects')
        api.swift_get_objects(IsA(http.HttpRequest),
                              self.container.name).AndReturn([self.object])

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('dash_containers_public',
                    args=['tenant', self.container.name]))

        self.assertTemplateUsed(
            res, 'django_openstack/dash/containers/public.html')
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
Esempio n. 9
0
def public(request, tenant_id, container_name):

    try:
        container = api.swift_get_container(request, container_name)
        objects = [(o.name, o.name)
                   for o in api.swift_get_objects(request, container_name)]
    except ResponseError, e:
        messages.error(
            request, 'Unable to retrive container meta data for public. \
                       Perhaps you do not have right permission : %s' % str(e))
        return shortcuts.redirect('dash_containers', tenant_id)
Esempio n. 10
0
    def test_container_public_put(self):
      
        ret_container = self.container 
        ret_container.headers = [('x-container-meta-web-index','test'),
                                 ('x-container-meta-web-listing-css', 'css'),
                                 ('x-container-meta-web-error', 'err'),
                                 ('x-container-meta-web-listing', 'fuga') ]
        formData = {'container_name':'containerName',
                    'method':'MakePublicContainer',
                    'index_object_name' : self.object.name,
                    'css_object_name' : self.object.name,
                    'html_listing' : True,
                    'public_html' : True,
                    'use_css_in_listing' : True,
                    'error' : 'errorsuffix'
                   }

        self.mox.StubOutWithMock(api, 'swift_get_container')
        api.swift_get_container(
                                IsA(http.HttpRequest), self.container.name
                                ).AndReturn(ret_container)
        
        self.mox.StubOutWithMock(api, 'swift_get_objects')
        api.swift_get_objects(
                              IsA(http.HttpRequest), self.container.name
                              ).AndReturn([self.object])

        self.mox.StubOutWithMock(api, 'swift_set_container_info')

        api.swift_set_container_info(
                                     IsA(http.HttpRequest), self.container.name,
                                     IgnoreArg())
        
        self.mox.ReplayAll()
            
        res = self.client.post(reverse('dash_containers_public', args=['tenant', self.container.name]),
                                       formData)
        #self.assertRedirectsNoFollow(res, reverse('dash_containers_public',
        #                                          args=[self.request.user.tenant_id, self.container.name]))
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
Esempio n. 11
0
    def test_container_public_put(self):

        ret_container = self.container
        ret_container.headers = [('x-container-meta-web-index', 'test'),
                                 ('x-container-meta-web-listing-css', 'css'),
                                 ('x-container-meta-web-error', 'err'),
                                 ('x-container-meta-web-listing', 'fuga')]
        formData = {
            'container_name': 'containerName',
            'method': 'MakePublicContainer',
            'index_object_name': self.object.name,
            'css_object_name': self.object.name,
            'html_listing': True,
            'public_html': True,
            'use_css_in_listing': True,
            'error': 'errorsuffix'
        }

        self.mox.StubOutWithMock(api, 'swift_get_container')
        api.swift_get_container(IsA(http.HttpRequest),
                                self.container.name).AndReturn(ret_container)

        self.mox.StubOutWithMock(api, 'swift_get_objects')
        api.swift_get_objects(IsA(http.HttpRequest),
                              self.container.name).AndReturn([self.object])

        self.mox.StubOutWithMock(api, 'swift_set_container_info')

        api.swift_set_container_info(IsA(http.HttpRequest),
                                     self.container.name, IgnoreArg())

        self.mox.ReplayAll()

        res = self.client.post(
            reverse('dash_containers_public',
                    args=['tenant', self.container.name]), formData)
        #self.assertRedirectsNoFollow(res, reverse('dash_containers_public',
        #                                          args=[self.request.user.tenant_id, self.container.name]))
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
Esempio n. 12
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
Esempio n. 13
0
 def handle(self, request, data):
     object_prefix = data['object_prefix'] or None
     container_name = data['container_name'] or None
     if object_prefix:
         object_prefix = object_prefix.encode('utf-8')
     if container_name:
         container_name = container_name.encode('utf-8')
     try:
        objects = api.swift_get_objects(request, container_name,
                      None,request.session.get('storage_url', None))
     except NoSuchContainer, e:
         messages.error(request, 'No Such Container %s' % container_name)
         return None
Esempio n. 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
Esempio n. 15
0
 def handle(self, request, data):
     object_prefix = data['object_prefix'] or None
     container_name = data['container_name'] or None
     if object_prefix:
         object_prefix = object_prefix.encode('utf-8')
     if container_name:
         container_name = container_name.encode('utf-8')
     try:
         objects = api.swift_get_objects(
             request, container_name, None,
             request.session.get('storage_url', None))
     except NoSuchContainer, e:
         messages.error(request, 'No Such Container %s' % container_name)
         return None
Esempio n. 16
0
    def handle(self, request, data):
        object_prefix = data['object_prefix'] or None
        container_name = data['container_name'] or None
        if object_prefix:
            object_prefix = object_prefix.encode('utf-8')
        if container_name:
            container_name = container_name.encode('utf-8')

        objects = api.swift_get_objects(request,
                                        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
Esempio n. 17
0
    def handle(self, request, data):
        object_prefix = data['object_prefix'] or None
        container_name = data['container_name'] or None
        if object_prefix:
            object_prefix = object_prefix.encode('utf-8')
        if container_name:
            container_name = container_name.encode('utf-8')

        objects = api.swift_get_objects(request,
                                        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
Esempio n. 18
0
def index(request, tenant_id, container_name):
    delete_form, handled = DeleteObject.maybe_handle(request)
    if handled:
        return handled

    filter_form, objects = FilterObjects.maybe_handle(request)

    if objects is None:
        filter_form.fields["container_name"].initial = container_name
        objects = api.swift_get_objects(request, container_name)

    delete_form.fields["container_name"].initial = container_name
    return render_to_response(
        "django_openstack/dash/objects/index.html",
        {"container_name": container_name, "objects": objects, "delete_form": delete_form, "filter_form": filter_form},
        context_instance=template.RequestContext(request),
    )
Esempio n. 19
0
def public(request, tenant_id, container_name):
    container = api.swift_get_container(request, container_name)
    objects = [(o.name, o.name) for o in api.swift_get_objects(request, container_name)]
    form, handled = MakePublicContainer.maybe_handle(request, objects=objects, headers=container.headers)
    if handled:
        return handled

    #if len(objects) > 0:
    #   form.fields['index_object_name'].initial = objects[0]
    #   form.fields['css_object_name'].initial = objects[0]

    return shortcuts.render_to_response(
    'django_openstack/dash/containers/public.html', {
        'container_name' : container_name,
        'container': container,
        'objects' : objects,
        'public_form' : form
    }, context_instance=template.RequestContext(request))
Esempio n. 20
0
def index(request, tenant_id, container_name):
    delete_form, handled = DeleteObject.maybe_handle(request)
    if handled:
        return handled

    filter_form, objects = FilterObjects.maybe_handle(request)

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

    delete_form.fields['container_name'].initial = container_name
    return render_to_response(
    'django_openstack/dash/objects/index.html', {
        'container_name': container_name,
        'objects': objects,
        'delete_form': delete_form,
        'filter_form': filter_form,
    }, context_instance=template.RequestContext(request))
Esempio n. 21
0
def index(request, tenant_id, container_name):
    delete_form, handled = DeleteObject.maybe_handle(request)
    if handled:
        return handled

    filter_form, objects = FilterObjects.maybe_handle(request)

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

    delete_form.fields['container_name'].initial = container_name
    return render_to_response(
    'django_openstack/dash/objects/index.html', {
        'container_name': container_name,
        'objects': objects,
        'delete_form': delete_form,
        'filter_form': filter_form,
    }, context_instance=template.RequestContext(request))
Esempio n. 22
0
def index(request, tenant_id, container_name):
    delete_form, handled = DeleteObject.maybe_handle(request)
    if handled:
        return handled

    download_form, handled = DownloadObject.maybe_handle(request)
    if handled:
        return handled

    filter_form, objects = FilterObjects.maybe_handle(request)
    container_name_unquoted = unquote(container_name)

    if objects is None:
        filter_form.fields['container_name'].initial = container_name
        try:
           objects = api.swift_get_objects(request, container_name, 
                               None, request.session.get('storage_url', None))
        except NoSuchContainer, e:
           messages.error(request, 'No Such Container %s' % container_name)
        except ResponseError, e:
           messages.error(request, 'Unable to get list of objects : %s' % str(e))
Esempio n. 23
0
    def test_swift_get_objects(self):
        NAME = "containerName"

        swift_objects = (TEST_RETURN, TEST_RETURN + "2")
        container = self.mox.CreateMock(cloudfiles.container.Container)
        container.get_objects(prefix=None).AndReturn(swift_objects)

        swift_api = self.stub_swift_api()

        swift_api.get_container(NAME).AndReturn(container)

        self.mox.ReplayAll()

        ret_val = api.swift_get_objects(self.request, NAME)

        self.assertEqual(len(ret_val), len(swift_objects))
        for swift_object in ret_val:
            self.assertIsInstance(swift_object, api.SwiftObject)
            self.assertIn(swift_object._apiresource, swift_objects)

        self.mox.VerifyAll()
Esempio n. 24
0
def public(request, tenant_id, container_name):
    container = api.swift_get_container(request, container_name)
    objects = [(o.name, o.name)
               for o in api.swift_get_objects(request, container_name)]
    form, handled = MakePublicContainer.maybe_handle(request,
                                                     objects=objects,
                                                     headers=container.headers)
    if handled:
        return handled

    #if len(objects) > 0:
    #   form.fields['index_object_name'].initial = objects[0]
    #   form.fields['css_object_name'].initial = objects[0]

    return shortcuts.render_to_response(
        'django_openstack/dash/containers/public.html', {
            'container_name': container_name,
            'container': container,
            'objects': objects,
            'public_form': form
        },
        context_instance=template.RequestContext(request))
Esempio n. 25
0
def index(request, tenant_id, container_name):
    delete_form, handled = DeleteObject.maybe_handle(request)
    if handled:
        return handled

    download_form, handled = DownloadObject.maybe_handle(request)
    if handled:
        return handled

    filter_form, objects = FilterObjects.maybe_handle(request)
    container_name_unquoted = unquote(container_name)

    if objects is None:
        filter_form.fields['container_name'].initial = container_name
        try:
            objects = api.swift_get_objects(
                request, container_name, None,
                request.session.get('storage_url', None))
        except NoSuchContainer, e:
            messages.error(request, 'No Such Container %s' % container_name)
        except ResponseError, e:
            messages.error(request,
                           'Unable to get list of objects : %s' % str(e))