def test_copy_job_creation(self, _): # given copy_job_request = CopyJobRequest( task_name_suffix='task-name-suffix', copy_job_type_id="backups", source_big_query_table=BigQueryTable('source_project', 'source_dataset', 'source_table'), target_big_query_table=BigQueryTable('target_project', 'target_dataset', 'target_table'), create_disposition="CREATE_IF_NEEDED", write_disposition="WRITE_EMPTY", post_copy_action_request=PostCopyActionRequest(url="/my/url", data={ "key1": "value1"}) ) # when TaskCreator.create_copy_job( copy_job_request=copy_job_request ) # then expected_queue_name = 'backups-copy-job' executed_tasks = self.taskqueue_stub.get_filtered_tasks( queue_names=expected_queue_name ) self.assertEqual(len(executed_tasks), 1, "Should create one task in queue") executed_task = executed_tasks[0] self.assertEqual(json.dumps(copy_job_request, cls=RequestEncoder), executed_task.extract_params()['copyJobRequest']) self.assertEqual('POST', executed_task.method) self.assertEqual('task_name', executed_task.name) self.assertEqual(executed_task.url, '/tasks/copy_job_async/copy_job')
def test_return_none_if_calculated_name_is_too_long(self): # given task_name_suffix = "x" * 501 copy_job_request = CopyJobRequest( task_name_suffix=task_name_suffix, copy_job_type_id="unknown-copying", source_big_query_table=BigQueryTable('source_project', 'source_dataset', 'source_table'), target_big_query_table=BigQueryTable('target_project', 'target_dataset', 'target_table'), create_disposition="CREATE_IF_NEEDED", write_disposition="WRITE_EMPTY", retry_count=0) # when copy_job_task_name = CopyJobTaskName(copy_job_request).create() # then self.assertIsNone(copy_job_task_name)
def test_copy_job_creation_throws_error_on_unknown_queue(self, _): # when with self.assertRaises(UnknownQueueError) as error: TaskCreator.create_copy_job( copy_job_request=CopyJobRequest( task_name_suffix=None, copy_job_type_id="unknown-copying", source_big_query_table=BigQueryTable('source_project', 'source_dataset', 'source_table'), target_big_query_table=BigQueryTable('target_project', 'target_dataset', 'target_table'), create_disposition="CREATE_IF_NEEDED", write_disposition="WRITE_EMPTY" ) ) self.assertEqual( error.exception.message, "There is no queue " "'unknown-copying-copy-job'. Please add " "it to your queue.yaml definition.")
def test_creating_task_name(self): # given copy_job_request = CopyJobRequest( task_name_suffix='task_name_suffix', copy_job_type_id="unknown-copying", source_big_query_table=BigQueryTable('source_project', 'source_dataset', 'source_table'), target_big_query_table=BigQueryTable('target_project', 'target_dataset', 'target_table'), create_disposition="CREATE_IF_NEEDED", write_disposition="WRITE_EMPTY", retry_count=0) # when copy_job_task_name = CopyJobTaskName(copy_job_request).create() # then self.assertEqual( copy_job_task_name, '2017-12-06_source_project_source_dataset_source_table_0_task_name_suffix' )