コード例 #1
0
ファイル: tests.py プロジェクト: nimbis/horizon
    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"))
コード例 #2
0
ファイル: tests.py プロジェクト: BillTheBest/horizon
    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'))
コード例 #3
0
ファイル: tests.py プロジェクト: ohnoimdead/horizon-1
    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'))
コード例 #4
0
ファイル: tests.py プロジェクト: mshabdiz/horizon
    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'))
コード例 #5
0
ファイル: views.py プロジェクト: BillTheBest/horizon
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
コード例 #6
0
ファイル: views.py プロジェクト: termie/horizon
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
コード例 #7
0
ファイル: swift_tests.py プロジェクト: mshabdiz/horizon
    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)
コード例 #8
0
ファイル: swift_tests.py プロジェクト: jakedahn/horizon
    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)
コード例 #9
0
ファイル: views.py プロジェクト: nimbis/horizon
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
コード例 #10
0
ファイル: views.py プロジェクト: OpenStack-Kha/horizon
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