Пример #1
0
    def test_download(self, mock_container, mock_exists):
        files_audit.audit_temp_path = os.path.join(
            storage_settings.AUDIT_TEMP_PATH)
        file_contents = ['fake', 'file', 'content']
        mock_obj = mock.Mock()
        mock_obj.fetch.return_value = iter(file_contents)
        mock_container.get_object.return_value = mock_obj
        mock_exists.return_value = False
        version = FileVersionFactory()
        version.metadata = {
            'sha256':
            'dff32002043d7a4da7173d2034cb2f6856d10549bd8cc6d7e16d62f1304681f8'
        }  # fakefilecontent

        mock_open = mock.mock_open()
        with mock.patch('scripts.osfstorage.files_audit.open',
                        mock_open,
                        create=True):
            download_from_cloudfiles(version)

        mock_container.get_object.assert_called_with(
            version.location['object'])
        mock_open.assert_called_once_with(
            os.path.join(os.path.join(storage_settings.AUDIT_TEMP_PATH),
                         version.location['object']), 'wb')

        handle = mock_open()
        assert_equal(handle.write.call_count, 3)
        for content in file_contents:
            handle.write.assert_any_call(content)
Пример #2
0
 def test_download(self, mock_container, mock_exists):
     mock_object = mock.Mock()
     mock_container.get_object.return_value = mock_object
     mock_exists.return_value = False
     version = FileVersionFactory()
     download_from_cloudfiles(version)
     mock_container.get_object.assert_called_with(version.location['object'])
     mock_object.download.assert_called_with(storage_settings.AUDIT_TEMP_PATH)
Пример #3
0
    def test_download(self, mock_exists):
        files_audit.audit_temp_path = os.path.join(storage_settings.AUDIT_TEMP_PATH)
        file_contents = ['fake', 'file', 'content']
        self.ctx.container_primary = mock.Mock()
        self.ctx.container_primary.get_object.return_value.fetch.return_value = iter(file_contents)
        version = FileVersionFactory()
        version.metadata = {'sha256': 'dff32002043d7a4da7173d2034cb2f6856d10549bd8cc6d7e16d62f1304681f8'}  # fakefilecontent

        mock_open = mock.mock_open()
        with mock.patch('scripts.osfstorage.files_audit.open', mock_open, create=True):
            download_from_cloudfiles(self.ctx, version)

        self.ctx.container_primary.get_object.assert_called_with(version.location['object'])
        mock_open.assert_called_once_with(os.path.join(os.path.join(storage_settings.AUDIT_TEMP_PATH), version.location['object']), 'wb')

        handle = mock_open()
        assert_equal(handle.write.call_count, 3)
        for content in file_contents:
            handle.write.assert_any_call(content)