コード例 #1
0
    def test_upload(self):
        OBJECT_DATA = 'objectData'
        OBJECT_FILE = tempfile.TemporaryFile()
        OBJECT_FILE.write(OBJECT_DATA)
        OBJECT_FILE.flush()
        OBJECT_FILE.seek(0)
        OBJECT_NAME = 'objectName'

        formData = {
            'method': 'UploadObject',
            'container_name': self.CONTAINER_NAME,
            'name': OBJECT_NAME,
            'object_file': OBJECT_FILE
        }

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

        self.mox.ReplayAll()

        res = self.client.post(
            reverse('dash_objects_upload',
                    args=[self.TEST_TENANT, self.CONTAINER_NAME]), formData)

        self.assertRedirectsNoFollow(
            res,
            reverse('dash_objects_upload',
                    args=[self.TEST_TENANT, self.CONTAINER_NAME]))

        self.mox.VerifyAll()
コード例 #2
0
    def test_upload(self):
        OBJECT_DATA = 'objectData'
        OBJECT_FILE = tempfile.TemporaryFile()
        OBJECT_FILE.write(OBJECT_DATA)
        OBJECT_FILE.flush()
        OBJECT_FILE.seek(0)
        OBJECT_NAME = 'objectName'

        formData = {'method': 'UploadObject',
                    'container_name': self.CONTAINER_NAME,
                    'name': OBJECT_NAME,
                    'object_file': OBJECT_FILE}

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

        self.mox.ReplayAll()

        res = self.client.post(reverse('dash_objects_upload',
                                       args=[self.TEST_TENANT,
                                             self.CONTAINER_NAME]),
                               formData)

        self.assertRedirectsNoFollow(res, reverse('dash_objects_upload',
                                                  args=[self.TEST_TENANT,
                                                        self.CONTAINER_NAME]))

        self.mox.VerifyAll()
コード例 #3
0
    def handle(self, request, data):
        api.swift_upload_object(
                request,
                data['container_name'],
                data['name'],
                self.files['object_file'].read())

        messages.success(request, "Object was successfully uploaded.")
        return shortcuts.redirect(request.build_absolute_uri())
コード例 #4
0
ファイル: objects.py プロジェクト: daniel-hou0/horizon
    def handle(self, request, data):
        api.swift_upload_object(
                request,
                data['container_name'],
                data['name'],
                self.files['object_file'].read())

        messages.success(request, _("Object was successfully uploaded."))
        return shortcuts.redirect(request.build_absolute_uri())
コード例 #5
0
    def test_swift_upload_object(self):
        CONTAINER_NAME = "containerName"
        OBJECT_NAME = "objectName"
        OBJECT_DATA = "someData"

        swift_api = self.stub_swift_api()
        container = self.mox.CreateMock(cloudfiles.container.Container)
        swift_object = self.mox.CreateMock(cloudfiles.storage_object.Object)

        swift_api.get_container(CONTAINER_NAME).AndReturn(container)
        container.create_object(OBJECT_NAME).AndReturn(swift_object)
        swift_object.write(OBJECT_DATA).AndReturn(TEST_RETURN)

        self.mox.ReplayAll()

        ret_val = api.swift_upload_object(self.request, CONTAINER_NAME, OBJECT_NAME, OBJECT_DATA)

        self.assertIsNone(ret_val)

        self.mox.VerifyAll()