def assert_invalid_request(url, metrics, error_message=None): resp = requests.post(url, data=metrics) assert 400 == resp.status_code assert 'application/json; charset=UTF-8' == resp.headers['Content-Type'] if error_message: assert error_message == json.loads(resp.content)['error_message'] assert 0 == len(list(models.find_all_events()))
def assert_event_created(bucket, target, metrics, timestamp): events = list(models.find_all_events()) assert 1 == len(events) assert bucket == events[0]['bucket'] assert target == events[0]['target'] assert metrics == events[0]['metrics'] assert timestamp - time.mktime(events[0]['timestamp'].timetuple()) <= 1
def test_handler_should_mark_event_as_anomalous_if_anomaly_detected(): handler = ignore_init(AddMetricsHandler) handler.initialize() handler.request = FakeRequest() handler.detector = FakeDetector(True) handler.post('bk1', 'mach1') events = list(models.find_all_events()) assert 1 == len(events) assert True == events[0]['is_anomalous']