Example #1
0
    def test_should_delete_same_day_duplicates_backups(self):
        #given
        reference = TableReference('example-project-id', 'example-dataset-id',
                                   'example-table-id')

        first_5_backups = create_backup_daily_sequence(5,
                                                       start_date=datetime(
                                                           2017, 6, 1, 12))
        second_5_backups = create_backup_daily_sequence(5,
                                                        start_date=datetime(
                                                            2017, 6, 6, 12))
        first_5_backups_duplicated = create_backup_daily_sequence(
            5, start_date=datetime(2017, 6, 1, 14))

        backups = list(first_5_backups + second_5_backups +
                       first_5_backups_duplicated)
        backups_expected_for_deletion = list(first_5_backups)

        #when
        eligible_for_deletion = \
            self.under_test.get_backups_eligible_for_deletion(
                backups=list(backups),
                table_reference=reference)
        #then
        self.sortAndAssertListEqual(backups_expected_for_deletion,
                                    eligible_for_deletion)
Example #2
0
    def test_should_delete_many_today_duplicates_and_11th_young_version_after_deduplication_and_retain_old_backup(
            self, _1, _2, _3):
        #given
        reference = TableReference('example-project-id', 'example-dataset-id',
                                   'example-table-id')

        young_backups = create_backup_daily_sequence(10,
                                                     start_date=datetime(
                                                         2017, 8, 1))
        newest_duplicated_backup = create_backup(datetime(2017, 8, 19, 10))

        today_duplicated_backups = [
            newest_duplicated_backup,
            create_backup(datetime(2017, 8, 19, 9)),
            create_backup(datetime(2017, 8, 19, 8)),
            create_backup(datetime(2017, 8, 19, 7))
        ]

        old_backup = create_backup(datetime(2016, 8, 19, 10))

        backups = list(young_backups + today_duplicated_backups + [old_backup])
        backups_expected_for_deletion = list([young_backups[9]] +
                                             today_duplicated_backups[1:])

        #when
        eligible_for_deletion = \
            self.under_test.get_backups_eligible_for_deletion(
                backups=list(backups),
                table_reference=reference)

        #then
        self.sortAndAssertListEqual(backups_expected_for_deletion,
                                    eligible_for_deletion)
    def test_should_filter_out_young_backups_above_10_version_but_retain_old_backups(
            self):
        # given
        reference = TableReference('example-project-id', 'example-dataset-id',
                                   'example-table-id')
        young_backups = backup_utils.create_backup_daily_sequence(
            14, start_date=datetime(2019, 8, 15))
        old_backups = backup_utils.create_backup_daily_sequence(
            3, start_date=datetime(2019, 1, 1))
        all_backups = list(young_backups + old_backups)

        expected_retained_backups = list(young_backups[:10] + old_backups)
        shuffle(all_backups)

        # when
        backups_to_retain = self.under_test.filter(all_backups, reference)
        # then
        self.assertListEqual(backups_to_retain, expected_retained_backups)
    def test_should_filter_out_young_backups_above_10_version(self, reference):
        # given
        backups = backup_utils.create_backup_daily_sequence(
            14, start_date=datetime(2019, 7, 1))
        expected_retained_backups = backups[:10]
        shuffle(backups)

        # when
        backups_to_retain = self.under_test.filter(backups, reference)
        # then
        self.assertListEqual(backups_to_retain, expected_retained_backups)
    def test_should_not_filter_out_if_there_is_10_or_less_young_table_backups(
            self, count):
        # given
        reference = TableReference('example-project-id', 'example-dataset-id',
                                   'example-table-id')
        backups = backup_utils.create_backup_daily_sequence(
            count, start_date=datetime(2019, 7, 1))

        # when
        backups_to_retain = self.under_test.filter(list(backups), reference)
        # then
        self.assertListEqual(backups_to_retain, backups)
Example #6
0
 def test_should_delete_oldest_if_11_young_backups(self):
     # given
     reference = TableReference('example-project-id', 'example-dataset-id',
                                'example-table-id')
     young_backups = create_backup_daily_sequence(11,
                                                  start_date=datetime(
                                                      2017, 8, 1))
     # when
     eligible_for_deletion = self.under_test \
         .get_backups_eligible_for_deletion(backups=list(young_backups),
                                            table_reference=reference)
     # then
     self.sortAndAssertListEqual([young_backups[10]], eligible_for_deletion)
Example #7
0
    def test_should_not_delete_if_10_young_backup_and_single_old_backup(
            self, _1, _2, _3):
        # given
        reference = TableReference('example-project-id', 'example-dataset-id',
                                   'example-table-id')
        young_backups = create_backup_daily_sequence(10,
                                                     start_date=datetime(
                                                         2017, 8, 1))
        old_backup = create_backup(datetime(2016, 8, 1))
        all_backups = list(young_backups + [old_backup])

        # when
        eligible_for_deletion = self.under_test \
            .get_backups_eligible_for_deletion(backups=list(all_backups),
                                               table_reference=reference)
        # then
        self.sortAndAssertListEqual([], eligible_for_deletion)
Example #8
0
    def test_should_delete_older_old_and_oldest_young_backup_if_two_old_and_11_young_backups(
            self, _1, _2, _3):
        # given
        reference = TableReference('example-project-id', 'example-dataset-id',
                                   'example-table-id')
        older_old_backup = create_backup(datetime(2016, 7, 31))
        old_backup = create_backup(datetime(2016, 8, 1))
        young_backups = create_backup_daily_sequence(11,
                                                     start_date=datetime(
                                                         2017, 8, 1))
        all_backups = list(young_backups + [older_old_backup, old_backup])

        # when
        eligible_for_deletion = self.under_test \
            .get_backups_eligible_for_deletion(backups=all_backups,
                                               table_reference=reference)
        # then
        self.sortAndAssertListEqual([older_old_backup, young_backups[10]],
                                    eligible_for_deletion)
Example #9
0
    def test_should_remove_above_last_10_young_backups(self):
        #given
        reference = TableReference('example-project-id', 'example-dataset-id',
                                   'example-table-id')
        oldest_backup = create_backup(datetime(2017, 6, 1))
        _10_last_backups = create_backup_daily_sequence(10,
                                                        start_date=datetime(
                                                            2017, 6, 2))

        backups = list(_10_last_backups)
        backups.append(oldest_backup)

        backups_expected_for_deletion = [oldest_backup]

        #when
        eligible_for_deletion = \
            self.under_test.get_backups_eligible_for_deletion(
                backups=list(backups),
                table_reference=reference)
        #then
        self.sortAndAssertListEqual(backups_expected_for_deletion,
                                    eligible_for_deletion)