Ejemplo n.º 1
0
    def test_download(self):
        container = self.containers.first()
        obj = self.objects.first()
        OBJECT_DATA = "objectData"

        self.mox.StubOutWithMock(api, "swift_get_object_data")
        self.mox.StubOutWithMock(api.swift, "swift_get_object")
        api.swift.swift_get_object(IsA(http.HttpRequest), container.name, obj.name).AndReturn(obj)
        api.swift_get_object_data(IsA(http.HttpRequest), container.name, obj.name).AndReturn(OBJECT_DATA)
        self.mox.ReplayAll()

        download_url = reverse("horizon:nova:containers:object_download", args=[container.name, obj.name])
        res = self.client.get(download_url)
        self.assertEqual(res.content, OBJECT_DATA)
        self.assertTrue(res.has_header("Content-Disposition"))
Ejemplo n.º 2
0
    def test_download(self):
        OBJECT_DATA = 'objectData'
        OBJECT_NAME = 'objectName'

        self.mox.StubOutWithMock(api, 'swift_get_object_data')
        api.swift_get_object_data(IsA(http.HttpRequest),
                                  unicode(self.CONTAINER_NAME),
                                  unicode(OBJECT_NAME)).AndReturn(OBJECT_DATA)

        self.mox.ReplayAll()

        res = self.client.get(reverse(
                            'horizon:nova:containers:object_download',
                            args=[self.CONTAINER_NAME, OBJECT_NAME]))

        self.assertEqual(res.content, OBJECT_DATA)
        self.assertTrue(res.has_header('Content-Disposition'))
Ejemplo n.º 3
0
    def test_download(self):
        OBJECT_DATA = 'objectData'
        OBJECT_NAME = 'objectName'

        self.mox.StubOutWithMock(api, 'swift_get_object_data')
        api.swift_get_object_data(IsA(http.HttpRequest),
                                  unicode(self.CONTAINER_NAME),
                                  unicode(OBJECT_NAME)).AndReturn(OBJECT_DATA)

        self.mox.ReplayAll()

        res = self.client.get(reverse(
                            'horizon:nova:containers:object_download',
                            args=[self.CONTAINER_NAME, OBJECT_NAME]))

        self.assertEqual(res.content, OBJECT_DATA)
        self.assertTrue(res.has_header('Content-Disposition'))
Ejemplo n.º 4
0
    def test_download(self):
        container = self.containers.first()
        obj = self.objects.first()
        OBJECT_DATA = 'objectData'

        self.mox.StubOutWithMock(api, 'swift_get_object_data')
        self.mox.StubOutWithMock(api.swift, 'swift_get_object')
        api.swift.swift_get_object(IsA(http.HttpRequest), container.name,
                                   obj.name).AndReturn(obj)
        api.swift_get_object_data(IsA(http.HttpRequest), container.name,
                                  obj.name).AndReturn(OBJECT_DATA)
        self.mox.ReplayAll()

        download_url = reverse('horizon:nova:containers:object_download',
                               args=[container.name, obj.name])
        res = self.client.get(download_url)
        self.assertEqual(res.content, OBJECT_DATA)
        self.assertTrue(res.has_header('Content-Disposition'))
Ejemplo n.º 5
0
def object_download(request, container_name, object_name):
    object_data = api.swift_get_object_data(
            request, container_name, object_name)

    response = http.HttpResponse()
    response['Content-Disposition'] = 'attachment; filename=%s' % \
            object_name
    for data in object_data:
        response.write(data)
    return response
Ejemplo n.º 6
0
def object_download(request, container_name, object_name):
    object_data = api.swift_get_object_data(request, container_name,
                                            object_name)

    response = http.HttpResponse()
    response['Content-Disposition'] = 'attachment; filename=%s' % \
            object_name
    for data in object_data:
        response.write(data)
    return response
Ejemplo n.º 7
0
    def test_swift_get_object_data(self):
        container = self.containers.first()
        obj = self.objects.first()
        OBJECT_DATA = 'objectData'

        swift_api = self.stub_swiftclient()
        swift_api.get_container(container.name).AndReturn(container)
        self.mox.StubOutWithMock(container, 'get_object')
        container.get_object(obj.name).AndReturn(obj)
        self.mox.StubOutWithMock(obj, 'stream')
        obj.stream().AndReturn(OBJECT_DATA)
        self.mox.ReplayAll()

        ret_val = api.swift_get_object_data(self.request, container.name,
                                            obj.name)
        self.assertEqual(ret_val, OBJECT_DATA)
Ejemplo n.º 8
0
    def test_swift_get_object_data(self):
        container = self.containers.first()
        obj = self.objects.first()
        OBJECT_DATA = 'objectData'

        swift_api = self.stub_swiftclient()
        swift_api.get_container(container.name).AndReturn(container)
        self.mox.StubOutWithMock(container, 'get_object')
        container.get_object(obj.name).AndReturn(obj)
        self.mox.StubOutWithMock(obj, 'stream')
        obj.stream().AndReturn(OBJECT_DATA)
        self.mox.ReplayAll()

        ret_val = api.swift_get_object_data(self.request,
                                            container.name,
                                            obj.name)
        self.assertEqual(ret_val, OBJECT_DATA)
Ejemplo n.º 9
0
def object_download(request, container_name, object_name):
    obj = api.swift.swift_get_object(request, container_name, object_name)
    # Add the original file extension back on if it wasn't preserved in the
    # name given to the object.
    filename = object_name
    if not os.path.splitext(obj.name)[1]:
        name, ext = os.path.splitext(obj.metadata.get("orig-filename", ""))
        filename = "%s%s" % (object_name, ext)
    try:
        object_data = api.swift_get_object_data(request, container_name, object_name)
    except:
        redirect = reverse("horizon:nova:containers:index")
        exceptions.handle(request, _("Unable to retrieve object."), redirect=redirect)
    response = http.HttpResponse()
    safe_name = filename.encode("utf-8")
    response["Content-Disposition"] = "attachment; filename=%s" % safe_name
    response["Content-Type"] = "application/octet-stream"
    for data in object_data:
        response.write(data)
    return response
Ejemplo n.º 10
0
def object_download(request, container_name, object_name):
    obj = api.swift.swift_get_object(request, container_name, object_name)
    # Add the original file extension back on if it wasn't preserved in the
    # name given to the object.
    filename = object_name
    if not os.path.splitext(obj.name)[1]:
        name, ext = os.path.splitext(obj.metadata.get('orig-filename', ''))
        filename = "%s%s" % (object_name, ext)
    try:
        object_data = api.swift_get_object_data(request, container_name,
                                                object_name)
    except:
        redirect = reverse("horizon:nova:containers:index")
        exceptions.handle(request,
                          _("Unable to retrieve object."),
                          redirect=redirect)
    response = http.HttpResponse()
    response['Content-Disposition'] = 'attachment; filename=%s' % filename
    response['Content-Type'] = 'application/octet-stream'
    for data in object_data:
        response.write(data)
    return response