def test_health_status_run_query_throws_exception(self): data_source = self.factory.create_data_source() def exception_raiser(*args, **kwargs): raise Exception self.patched_run_query.side_effect = exception_raiser update_health_status() # Status is updated for the one data source self.assertEqual(self.patched_store_health_status.call_count, 1) # The data source name is correctly passed in the last call of update_health_status() args, kwargs = self.patched_store_health_status.call_args self.assertEqual(str(data_source.id), args[0]) self.assertEqual(data_source.name, args[1]) self.assertEqual(data_source.query_runner.noop_query, args[2]) # All expected status keys are available. EXPECTED_KEYS = ['status', 'last_run', 'last_run_human', 'runtime'] NEW_STATUS = args[3] new_status_keys = set(NEW_STATUS.keys()) self.assertEqual(set(EXPECTED_KEYS), new_status_keys) self.assertEqual('FAIL', NEW_STATUS['status']) self.assertIsNotNone(NEW_STATUS['last_run']) self.assertIsNotNone(NEW_STATUS['last_run_human']) self.assertIsNone(NEW_STATUS['runtime'])
def test_health_status_custom_query(self): CUSTOM_QUERY = "select * from table" data_source = self.factory.create_data_source() os.environ["REDASH_CUSTOM_HEALTH_QUERIES_1"] = CUSTOM_QUERY update_health_status() args, kwargs = self.patched_store_health_status.call_args self.assertNotEqual(data_source.query_runner.noop_query, args[2]) self.assertEqual(CUSTOM_QUERY, args[2])
def test_health_status_run_query_throws_noop_not_implemented_exception( self): self.factory.create_data_source() def exception_raiser(*args, **kwargs): raise NotImplementedError self.patched_run_query.side_effect = exception_raiser update_health_status() # Status is updated for the one data source self.assertEqual(self.patched_store_health_status.call_count, 0)
def test_health_status_success(self): data_sources = [] for i in range(5): data_sources.append(self.factory.create_data_source()) update_health_status() # Status is updated for each of the 5 data sources self.assertEqual(self.patched_store_health_status.call_count, 5) # The data source name and id is correctly passed in the last call of update_health_status() args, kwargs = self.patched_store_health_status.call_args self.assertEqual(str(data_sources[-1].id), args[0]) self.assertEqual(data_sources[-1].name, args[1]) # All expected status keys are available. EXPECTED_KEYS = ["status", "last_run", "last_run_human", "runtime"] NEW_STATUS = args[3] new_status_keys = set(NEW_STATUS.keys()) self.assertEqual(set(EXPECTED_KEYS), new_status_keys) self.assertEqual("SUCCESS", NEW_STATUS["status"]) for key in EXPECTED_KEYS[1:]: self.assertIsNotNone(NEW_STATUS[key])