def test_nostate(self): """ Metrics shouldn't get reported outside a web state """ with add_tag('test-context', 'data_test'): try: self.run_queries() except Exception as e: logger.exception("test_nostate") self.assertFalse(self.reporter.counts) self.assertFalse(self.reporter.records)
def test_web_state(self): """ Metrics should get reported in web state """ with add_tag('test-context', 'data_test'): try: push_state('web') self.run_queries() except Exception as e: logger.exception("test_web_state") finally: pop_state('web') self.assertEqual(self.reporter.counts, self.expected_web_state_counts) self.assertItemsEqual(self.reporter.records.keys(), self.expected_web_state_gauges)
def test_model_state(self): """ Metrics shouldn't get reported in web state if also in model state """ with add_tag('test-context', 'data_test'): try: push_state('web') push_state('model') self.run_queries() except Exception as e: logger.exception("test_model_state") finally: pop_state('web') pop_state('model') self.assertFalse(self.reporter.counts) self.assertFalse(self.reporter.records)