コード例 #1
0
 def test_that_get_all_backups_sorted_will_return_only_these_with_null_deleted_column(
         self):  # nopep8 pylint: disable=C0301, W0613
     # given
     table = Table(project_id='example-proj-name',
                   dataset_id='example-dataset-name',
                   table_id='example-table-name',
                   last_checked=datetime(2017, 02, 1, 16, 30))
     table.put()
     backup1 = Backup(
         parent=table.key,
         last_modified=datetime(2017, 02, 1, 16, 30),
         created=datetime(2017, 02, 1, 16, 30),
         dataset_id='backup_dataset',
         table_id='backup1',
         numBytes=1234,
     )
     backup1.put()
     backup2 = Backup(parent=table.key,
                      last_modified=datetime(2017, 02, 1, 16, 30),
                      created=datetime(2017, 02, 1, 16, 30),
                      dataset_id='backup_dataset',
                      table_id='backup2',
                      numBytes=1234,
                      deleted=datetime(2017, 02, 10, 16, 30))
     backup2.put()
     # when
     existing_backups = Backup.get_all_backups_sorted(table.key)
     # then
     self.assertTrue(backup1 in existing_backups)
     self.assertTrue(backup2 not in existing_backups)
コード例 #2
0
    def test_should_return_true_if_table_was_changed_after_last_backup(self, _):
        # given
        backup = Backup(
            parent=self.table.key,
            last_modified=datetime(2016, 11, 13, 15, 00)
        )
        backup.put()
        predicate = OnDemandBackupPredicate()

        # when
        result = predicate.test(self.big_query_table_metadata, self.table)
        # then
        self.assertTrue(result, "OnDemandShouldBackupPredicate should return TRUE "
                                "if table was changed after last backup")
コード例 #3
0
    def test_should_return_true_if_table_was_changed_before_last_backup(self, _):  # nopep8 pylint: disable=C0301
        # given
        backup = Backup(
            parent=self.table.key,
            last_modified=datetime(2016, 11, 13, 15, 00)
        )
        backup.put()
        predicate = OnDemandBackupPredicate()

        # when
        result = predicate.test(self.big_query_table_metadata, self.table)
        # then
        self.assertTrue(result, "OnDemandShouldBackupPredicate should return FALSE "
                                "if table was changed before "
                                "last backup was made")
コード例 #4
0
    def test_should_return_false_if_table_was_changed_at_the_same_time_when_last_backup(
            self, _1, _2):  # nopep8 pylint: disable=C0301
        # given
        backup = Backup(parent=self.table.key,
                        last_modified=datetime(2016, 11, 13, 15, 00),
                        numBytes=123)
        backup.put()
        predicate = DefaultBackupPredicate()

        # when
        result = predicate.test(self.big_query_table_metadata, self.table)
        # then
        self.assertFalse(
            result, "ShouldBackupPredicate should return False "
            "if table was change at the same time when "
            "last backup was made")
コード例 #5
0
    def test_should_return_true_if_changed_table_is_empty_and_last_backup_is_also_empty(
            self, _1, _2):  # nopep8 pylint: disable=C0301
        # given
        backup = Backup(parent=self.table.key,
                        last_modified=datetime(2016, 11, 13, 15, 00),
                        numBytes=0)
        backup.put()
        predicate = DefaultBackupPredicate()

        # when
        result = predicate.test(self.big_query_table_metadata, self.table)

        # then
        self.assertTrue(
            result, "ShouldBackupPredicate should return True "
            "if table was changed after last backup was made,"
            "but source table is empty and bbq has also empty last backup")
コード例 #6
0
    def test_should_return_true_if_table_was_changed_before_last_backup_but_table_size_is_different(
            self, _1, _2):  # nopep8 pylint: disable=C0301
        # given
        backup = Backup(parent=self.table.key,
                        last_modified=datetime(2016, 11, 13, 15, 00),
                        numBytes=123)
        backup.put()
        predicate = DefaultBackupPredicate()

        # when
        result = predicate.test(self.big_query_table_metadata, self.table)
        # then
        self.assertTrue(
            result, "ShouldBackupPredicate should return TRUE "
            "if table was changed before "
            "last backup was made but "
            "backup has different size than source table")
コード例 #7
0
 def test_should_retrieve_table_using_backup(self):
     # given
     table = Table(project_id='example-proj-name',
                   dataset_id='example-dataset-name',
                   table_id='example-table-name',
                   last_checked=datetime(2017, 02, 1, 16, 30))
     table.put()
     backup = Backup(parent=table.key,
                     last_modified=datetime(2017, 02, 1, 16, 30),
                     created=datetime(2017, 02, 1, 16, 30),
                     dataset_id='targetDatasetId',
                     table_id='targetTableId',
                     numBytes=1234)
     backup.put()
     # then
     backup_entity = Backup.get_by_key(backup.key)
     table_entity = Table.get_table_from_backup(backup_entity)
     self.assertEqual(table_entity, table)
コード例 #8
0
 def test_that_not_deleted_backup_doesnt_have_created_field(self):
     # given
     table = Table(project_id='example-proj-name',
                   dataset_id='example-dataset-name',
                   table_id='example-table-name',
                   last_checked=datetime(2017, 02, 1, 16, 30))
     backup = Backup(parent=table.key,
                     last_modified=datetime(2017, 02, 1, 16, 30),
                     created=datetime(2017, 02, 1, 16, 30),
                     dataset_id='targetDatasetId',
                     table_id='targetTableId',
                     numBytes=1234)
     backup.put()
     # then
     backup_to_check = Backup.get_by_key(backup.key)
     self.assertEqual(backup_to_check.deleted, None)
     self.assertEqual(backup_to_check.created,
                      datetime(2017, 02, 1, 16, 30))
コード例 #9
0
 def test_deleting_backup_is_adding_current_timestamp_in_deleted_field(
         self):
     # given
     table = Table(project_id='example-proj-name',
                   dataset_id='example-dataset-name',
                   table_id='example-table-name',
                   last_checked=datetime(2017, 02, 1, 16, 30))
     backup = Backup(parent=table.key,
                     last_modified=datetime(2017, 02, 1, 16, 30),
                     created=datetime(2017, 02, 1, 16, 30),
                     dataset_id='targetDatasetId',
                     table_id='targetTableId',
                     numBytes=1234)
     backup.put()
     # when
     Backup.mark_backup_deleted(backup.key)
     # then
     deleted_backup = Backup.get_by_key(backup.key)
     self.assertEqual(deleted_backup.deleted, datetime(2017, 02, 3, 16, 30))