def test_ensure_glacier(self, mock_vault, mock_download): glacier_id = 'iamarchived' version = FileVersionFactory() file_path = os.path.join(storage_settings.AUDIT_TEMP_PATH, version.location['object']) mock_download.return_value = file_path mock_vault.upload_archive.return_value = glacier_id ensure_glacier(version, dry_run=False) mock_vault.upload_archive.assert_called_with(file_path, description=version.location['object']) version.reload() assert_equal(version.metadata['archive'], glacier_id)
def test_ensure_glacier(self, mock_vault, mock_download): glacier_id = 'iamarchived' version = FileVersionFactory() file_path = os.path.join(storage_settings.AUDIT_TEMP_PATH, version.location['object']) mock_download.return_value = file_path mock_vault.upload_archive.return_value = glacier_id ensure_glacier(version, dry_run=False) mock_vault.upload_archive.assert_called_with( file_path, description=version.location['object']) version.reload() assert_equal(version.metadata['archive'], glacier_id)
def test_migrate_version(self, mock_test_container, mock_prod_container): mock_test_object = mock.Mock() mock_test_container.get_object.return_value = mock_test_object version = FileVersionFactory() version.location['container'] = TEST_CONTAINER_NAME version.save() migrate_version(version) mock_test_container.get_object.assert_called_with(version.location['object']) mock_test_object.copy.assert_called_with(mock_prod_container) version.reload() assert_equal(version.location['container'], PROD_CONTAINER_NAME) assert_equal(len(get_targets()), 0)
def test_migrate_version(self, mock_test_container, mock_prod_container): mock_test_object = mock.Mock() mock_test_container.get_object.return_value = mock_test_object version = FileVersionFactory() version.location['container'] = TEST_CONTAINER_NAME version.save() migrate_version(version) mock_test_container.get_object.assert_called_with( version.location['object']) mock_test_object.copy.assert_called_with(mock_prod_container) version.reload() assert_equal(version.location['container'], PROD_CONTAINER_NAME) assert_equal(len(get_targets()), 0)
def test_ensure_glacier_not_multipart(self, mock_getsize, mock_download): glacier_id = 'iamarchived' version = FileVersionFactory() file_path = os.path.join(storage_settings.AUDIT_TEMP_PATH, version.location['object']) mock_download.return_value = file_path self.ctx.vault = mock.Mock() self.ctx.vault.upload_archive.return_value.id = glacier_id with mock.patch('scripts.osfstorage.files_audit.open', mock.mock_open(read_data='hello world'), create=True) as mfp: ensure_glacier(self.ctx, version, dry_run=False) mfp.assert_called_once_with(file_path, 'rb') self.ctx.vault.upload_archive.assert_called_with( vaultName=storage_settings.GLACIER_VAULT_NAME, archiveDescription=version.location['object'], body=mfp(), ) version.reload() assert_equal(version.metadata['archive'], glacier_id)
def test_ensure_glacier_not_multipart(self, mock_getsize, mock_download): glacier_id = 'iamarchived' version = FileVersionFactory() file_path = os.path.join(storage_settings.AUDIT_TEMP_PATH, version.location['object']) mock_download.return_value = file_path self.ctx.vault = mock.Mock() self.ctx.vault.upload_archive.return_value.id = glacier_id with mock.patch('scripts.osfstorage.files_audit.open', mock.mock_open(read_data='hello world'), create=True) as mfp: ensure_glacier(self.ctx, version, dry_run=False) mfp.assert_called_once_with(file_path, 'rb') self.ctx.vault.upload_archive.assert_called_with( vaultName=storage_settings.GLACIER_VAULT_NAME, archiveDescription=version.location['object'], body=mfp(), ) version.reload() assert_equal(version.metadata['archive'], glacier_id)