Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

Commit

Permalink
added AsyncBatchRestoreService test and moved workspace creation back…
Browse files Browse the repository at this point in the history
… into try clause
  • Loading branch information
marcin-kolda committed Jul 11, 2018
1 parent a105f55 commit b7ce2b7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
11 changes: 5 additions & 6 deletions src/restore/async_batch_restore_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ def __run_copy_job_for_each(self, restore_items, restoration_job_id):
source_table_reference = restore_item.source_table_reference
target_table_reference = restore_item.target_table_reference

self.restore_workspace_creator.create_workspace(
source_table_reference,
target_table_reference)

try:

self.restore_workspace_creator.create_workspace(
source_table_reference,
target_table_reference)
CopyJobServiceAsync(
copy_job_type_id='restore',
task_name_suffix=restoration_job_id
Expand All @@ -49,8 +48,8 @@ def __run_copy_job_for_each(self, restore_items, restoration_job_id):
target_table_reference.create_big_query_table()
)
except Exception as ex:
logging.error(
"Error during creating copy job. Marking restore item as FAILED")
logging.error("Error during creating copy job. Marking restore "
"item as FAILED, Error message: %s", ex.message)
restore_item.update_with_failed(restore_item.key, ex.message)

@staticmethod
Expand Down
24 changes: 22 additions & 2 deletions tests/restore/test_async_restore_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
from unittest import TestCase

from google.appengine.ext import testbed, ndb
from mock import patch, call
from mock import patch, call, mock

from src.backup.copy_job_async.post_copy_action_request import \
PostCopyActionRequest
from src.restore.async_batch_restore_service import AsyncBatchRestoreService
from src.restore.datastore.restoration_job import RestorationJob
from src.restore.datastore.restore_item import RestoreItem
from src.restore.restore_workspace_creator import RestoreWorkspaceCreator
from apiclient.errors import HttpError

from src.table_reference import TableReference

Expand Down Expand Up @@ -61,6 +62,25 @@ def test_for_single_item_should_create_post_copy_action(self):
call().with_post_action().copy_table(source_bq, target_bq)
])

@patch.object(RestoreWorkspaceCreator, 'create_workspace', side_effect=
HttpError(mock.Mock(status=403), 'Forbidden'))
def test_failing_creating_dataset_should_update_restore_item_status(self,
_):
# given
restoration_job_key = RestorationJob.create(HARDCODED_UUID)
restore_items_tuple = self.__create_restore_items(count=1)
restore_item = restore_items_tuple[0][0]

# when
AsyncBatchRestoreService().restore(HARDCODED_UUID, [[restore_item]])

# then
restore_items = list(RestoreItem.query().filter(
RestoreItem.restoration_job_key == restoration_job_key))

self.assertEqual(restore_items[0].status,
RestoreItem.STATUS_FAILED)

def test_multiple_items_restore(self):
# given
RestorationJob.create(HARDCODED_UUID)
Expand Down Expand Up @@ -116,7 +136,7 @@ def test_that_enforcer_is_called_for_each_restore_item(self):

self.enforcer.assert_has_calls(expected_calls)

def test_that_proper_entities_was_stored_in_datastore(self):
def test_that_proper_entities_were_stored_in_datastore(self):
# given
RestorationJob.create(HARDCODED_UUID)
restore_item_tuples = self.__create_restore_items(count=3)
Expand Down

0 comments on commit b7ce2b7

Please sign in to comment.