def test_send_client_notification(self, mock_parser): params = self.static_params.copy() params['data_retention_db'] = os.path.join(this_dir, 'test_db_file.db') params['backup_db_list'] = [ os.path.join(this_dir, 'test_db_file.db'), ] # same mock_parser.return_value = params cloud_retention_scanner.main()
def test_inconsistent_databases_raises_exception(self, mock_parser): params = self.static_params.copy() params['data_retention_db'] = os.path.join(this_dir, 'test_db_file.db') params['backup_db_list'] = [ os.path.join(this_dir, 'test_db_file3.db'), ] # this db is different, which should raise an exception mock_parser.return_value = params with self.assertRaises( cloud_retention_scanner.DatabaseInconsistencyException): cloud_retention_scanner.main()
def test_bad_target_date_raises_exception(self, mock_parser): params = self.static_params.copy() params['data_retention_db'] = os.path.join(this_dir, 'test_db_file2.db') params['backup_db_list'] = [ os.path.join(this_dir, 'test_db_file2.db'), ] # make the same as the primary for testing mock_parser.return_value = params with self.assertRaises( cloud_retention_scanner.utils.MalformattedDateException): cloud_retention_scanner.main()
def test_noninteger_reminder_intervals(self, mock_parser): self.static_params['reminder_intervals'] = ['14', '7a', '3'] params = self.static_params.copy() params['data_retention_db'] = os.path.join(this_dir, 'test_db_file.db') params['backup_db_list'] = [ os.path.join(this_dir, 'test_db_file.db'), ] # make the same as the primary for testing mock_parser.return_value = params with self.assertRaises( cloud_retention_scanner.InvalidReminderCheckpointsException): cloud_retention_scanner.main()
def test_calls_removal_function(self, mock_deletion_func, mock_reminder_func, mock_parser): params = self.static_params.copy() params['data_retention_db'] = os.path.join(this_dir, 'test_db_file8.db') params['backup_db_list'] = [ os.path.join(this_dir, 'test_db_file8.db'), ] # the same mock_parser.return_value = params cloud_retention_scanner.main() # read the file contents db = utils.load_database(params['data_retention_db'], params) mock_deletion_func.assert_called_once_with('abc', db['abc'], params)
def test_fills_out_reminder_email_template(self, mock_parser, mock_email_sender): params = self.static_params.copy() params['data_retention_db'] = os.path.join(this_dir, 'test_db_file4.db') params['backup_db_list'] = [ os.path.join(this_dir, 'test_db_file4.db'), ] # same mock_parser.return_value = params cloud_retention_scanner.calculate_size = mock.MagicMock( return_value=30.1) cloud_retention_scanner.main() cloud_retention_scanner.calculate_size.assert_called_once_with( 'bucket-abc', scale=1e9) self.assertTrue(mock_email_sender.called)
def test_fills_out_cccb_notification_template(self, mock_parser, mock_email_sender): params = self.static_params.copy() params['data_retention_db'] = os.path.join(this_dir, 'test_db_file8.db') params['backup_db_list'] = [ os.path.join(this_dir, 'test_db_file8.db'), ] # same params['data_cleanup_command_log'] = os.path.join( this_dir, 'test_delete.sh') mock_parser.return_value = params cloud_retention_scanner.main() file_contents = open(params['data_cleanup_command_log']).read() lines = file_contents.split('\n') self.assertEqual(lines[1], 'gsutil rm -r gs://bucket-abc/*') self.assertEqual(lines[2], 'gsutil rb gs://bucket-abc') self.assertTrue(mock_email_sender.called)
def test_calls_reminder_email_function_for_multiple_on_different_days( self, mock_reminder_func, mock_parser): params = self.static_params.copy() params['data_retention_db'] = os.path.join(this_dir, 'test_db_file6.db') params['backup_db_list'] = [ os.path.join(this_dir, 'test_db_file6.db'), ] # the same mock_parser.return_value = params cloud_retention_scanner.main() # read the file contents db = utils.load_database(params['data_retention_db'], params) calls = [ mock.call('abc', db['abc'], params, 7), mock.call('def', db['def'], params, 14) ] mock_reminder_func.assert_has_calls(calls)