def test_that_last_checked_date_is_updated_even_if_table_should_not_be_backed_up( # nopep8 pylint: disable=C0301 self, copy_table, _1, _2): # given table = Table(project_id="test-project", dataset_id="test-dataset", table_id="test-table", last_checked=datetime.datetime(2017, 3, 3)) table_reference = TableReference(project_id="test-project", dataset_id="test-dataset", table_id="test-table") # when table.put() BackupProcess(table_reference, self.big_query, self.big_query_table_metadata).start() table_entity = Table.get_table("test-project", "test-dataset", "test-table") # then self.assertEqual(table_entity.last_checked, datetime.datetime(2017, 04, 4)) copy_table.assert_not_called()
def __get_table_entity(table_reference): table = Table.get_table(table_reference.project_id, table_reference.dataset_id, table_reference.table_id, table_reference.partition_id) if table is None: raise NotFoundException( 'Table not found in datastore: {}'.format(table_reference)) logging.info("Datastore table: %s", table) return table
def test_copy_job_and_entity_in_datastore_for_single_partition_of_a_table( self, _, _1, _2): # given table_reference = TableReference(project_id="test-project", dataset_id="test-dataset", table_id="test-table", partition_id="20170330") # when BackupProcess(table_reference, self.big_query, self.big_query_table_metadata).start() ancestor_of_partition = Table.get_table("test-project", "test-dataset", "test-table") partition = Table.get_table("test-project", "test-dataset", "test-table", "20170330") # then self.assertIsNotNone(partition) self.assertIsNone(ancestor_of_partition)
def start(self): self.now = datetime.datetime.utcnow() table_entity = Table.get_table(self.project_id, self.dataset_id, self.table_id, self.partition_id) if self.__backup_ever_done(table_entity): self.__update_last_check(table_entity) if self.__should_backup(table_entity): self.__create_backup(table_entity) else: if self.__should_backup(table_entity): table_entity = self.__create_table_entity() self.__create_backup(table_entity)
def test_copy_job_and_entity_in_datastore_for_not_partitioned_table( self, _, _1, _2): # given table_reference = TableReference(project_id="test-project", dataset_id="test-dataset", table_id="test-table") # when BackupProcess(table_reference, self.big_query, self.big_query_table_metadata).start() table_entity = Table.get_table("test-project", "test-dataset", "test-table") # then self.assertIsNotNone(table_entity)
def test_that_copy_job_and_entity_in_datastore_is_created_if_empty_partitioned_table( # nopep8 pylint: disable=C0301 self, create_backup, _, _1): # given table_reference = TableReference(project_id="test-project", dataset_id="test-dataset", table_id="test-table", partition_id=None) # when BackupProcess(table_reference, self.big_query, self.big_query_table_metadata).start() table_in_datastore = Table.get_table("test-project", "test-dataset", "test-table") # then create_backup.assert_called_once() self.assertIsNotNone(table_in_datastore)
def test_that_last_checked_date_is_updated_when_backup_is_processed( self, _, _1, _2): # given table = Table(project_id="test-project", dataset_id="test-dataset", table_id="test-table", last_checked=datetime.datetime(2017, 3, 3)) table_reference = TableReference(project_id="test-project", dataset_id="test-dataset", table_id="test-table") # when table.put() BackupProcess(table_reference, self.big_query, self.big_query_table_metadata).start() table_entity = Table.get_table("test-project", "test-dataset", "test-table") # then self.assertEqual(table_entity.last_checked, datetime.datetime(2017, 04, 4))