示例#1
0
 def test_should_return_true_if_there_is_no_backups(self, _):
     # given
     predicate = OnDemandBackupPredicate()
     # when
     result = predicate.test(self.big_query_table_metadata, self.table)
     # then
     self.assertTrue(result, "OnDemandShouldBackupPredicate should return TRUE "
                             "if there is no backups")
    def start(table_reference):
        big_query_table_metadata = BigQueryTableMetadata.get_table_by_reference(
            table_reference)

        BackupProcess(
            table_reference=table_reference,
            big_query=BigQuery(),
            big_query_table_metadata=big_query_table_metadata,
            should_backup_predicate=OnDemandBackupPredicate()).start()
 def test_should_return_false_if_table_is_external_or_view_type(self, _):
     # given
     predicate = OnDemandBackupPredicate()
     # when
     result = predicate.test(self.big_query_table_metadata, self.table)
     # then
     self.assertFalse(
         result, "OnDemandShouldBackupPredicate should return FALSE "
         "if object is table or external type")
 def test_should_return_false_if_table_not_exist_anymore(self, _):
     # given
     predicate = OnDemandBackupPredicate()
     # when
     result = predicate.test(self.big_query_table_metadata, self.table)
     # then
     self.assertFalse(
         result, "OnDemandShouldBackupPredicate should return FALSE "
         "if table not exists")
 def test_should_return_false_if_schema_is_not_defined(self, _):
     # given
     predicate = OnDemandBackupPredicate()
     # when
     result = predicate.test(self.big_query_table_metadata, self.table)
     # then
     self.assertFalse(
         result, "OnDemandShouldBackupPredicate should return FALSE "
         "if table has no schema")
示例#6
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")
示例#7
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")
示例#8
0
    def start(table_reference):
        big_query_table_metadata = BigQueryTableMetadata.get_table_by_reference(
            table_reference)

        if big_query_table_metadata.is_daily_partitioned(
        ) and not big_query_table_metadata.is_partition():
            raise ParameterValidationException(
                "Partition id is required for partitioned table in on-demand mode"
            )

        BackupProcess(
            table_reference=table_reference,
            big_query=BigQuery(),
            big_query_table_metadata=big_query_table_metadata,
            should_backup_predicate=OnDemandBackupPredicate()).start()
示例#9
0
 def test_should_raise_ParameterValidationException_if_table_is_external_or_view_type(self, _):
     # given
     predicate = OnDemandBackupPredicate()
     # when-then
     with self.assertRaises(ParameterValidationException):
         predicate.test(self.big_query_table_metadata, self.table)
示例#10
0
 def test_should_raise_NotFoundException_if_table_not_exist_anymore(self, _):
     # given
     predicate = OnDemandBackupPredicate()
     # when-then
     with self.assertRaises(NotFoundException):
         predicate.test(self.big_query_table_metadata, self.table)
示例#11
0
 def test_should_raise_ParameterValidationException_if_schema_is_not_defined(self, _):
     # given
     predicate = OnDemandBackupPredicate()
     # when-then
     with self.assertRaises(ParameterValidationException):
         predicate.test(self.big_query_table_metadata, self.table)