def test_current_hour_with_pending_backup(self, get_worker_name_mock, task_register, save_backup_group, make_instance_snapshot_backup): infra_mock = InfraHelper.create(name='pending_backup_test', backup_hour=self.backup_hour - 1, plan__has_persistence=True, environment=self.dev_env, plan=self.plan) DatabaseHelper.create(databaseinfra=infra_mock, environment=self.dev_env) instance_mock = mommy.make('Instance', databaseinfra=infra_mock) get_worker_name_mock.return_value = 'test' group = BackupGroup() save_backup_group.return_value = group make_instance_snapshot_backup.return_value.status.return_value = ( Snapshot.SUCCESS) make_databases_backup() calls = [ call(current_hour=self.backup_hour, instance=self.instance, error={}, group=group), call(current_hour=self.backup_hour, instance=instance_mock, error={}, group=group) ] make_instance_snapshot_backup.assert_has_calls(calls, any_order=True)
def test_current_hour_without_pending_backup( self, get_worker_name_mock, task_register, save_backup_group, make_instance_snapshot_backup): infra_mock = InfraHelper.create( name='backup_test', backup_hour=self.backup_hour - 1, plan__has_persistence=True, environment=self.dev_env, plan=self.plan, ) DatabaseHelper.create(databaseinfra=infra_mock, environment=self.dev_env) instance_mock = mommy.make('Instance', databaseinfra=infra_mock) get_worker_name_mock.return_value = 'test' group = BackupGroup() save_backup_group.return_value = group snapshot = mommy.make('Snapshot', instance=instance_mock, group=group, status=Snapshot.SUCCESS, end_at=FAKE_NOW - timedelta(hours=1)) make_instance_snapshot_backup.return_value = snapshot make_databases_backup() make_instance_snapshot_backup.assert_called_once_with( current_hour=self.backup_hour, instance=self.instance, error={}, group=group)
def setUp(self): self.backup_hour = 5 self.year = 2020 self.month = 1 self.day = 1 mommy.make('Configuration', name='backup_hour', value=str(self.backup_hour)) self.dev_env = mommy.make('Environment', name='dev', stage=Environment.DEV) mommy.make('Environment', name='prod', stage=Environment.PROD) _, _, _, self.plan = PlanHelper.create() self.infra = InfraHelper.create(backup_hour=self.backup_hour, plan__has_persistence=True, environment=self.dev_env, plan=self.plan) self.instance = mommy.make('Instance', databaseinfra=self.infra) self.database = DatabaseHelper.create(databaseinfra=self.infra, environment=self.dev_env)
def _create_database(self, env_name='fake_env', infra_name='__test__ mysqlinfra2'): environment = mommy.make('Environment', name=env_name) databaseinfra = InfraHelper.create(name=infra_name, user="******", password='******', engine=self.engine, plan=self.plan, ssl_configured=True, environment=environment) hostname = mommy.make('Host', ssl_expire_at=FAKE_TODAY + timedelta(days=16)) self.instance_helper.create_instances_by_quant( instance_type=Instance.MYSQL, qt=1, infra=databaseinfra, hostname=hostname) database = DatabaseHelper.create( name='test_db_1', databaseinfra=databaseinfra, ) return environment, databaseinfra, hostname, database