def test_issue_with_event_counts_date_ranges(): issue = IssueFactory.create() issue.count_event('day1-1', date(2018, 1, 1)) issue.count_event('day1-2', date(2018, 1, 1)) issue.count_event('day2-1', date(2018, 1, 2)) issue.count_event('day3-1', date(2018, 1, 3)) issue.count_event('day3-2', date(2018, 1, 3)) assert Issue.objects.filter_dates( start_date=date(2018, 1, 1), ).event_count() == 5 assert Issue.objects.filter_dates( start_date=date(2018, 1, 1), end_date=date(2018, 1, 2), ).event_count() == 3 assert Issue.objects.filter_dates( start_date=date(2018, 1, 2), end_date=date(2018, 1, 2), ).event_count() == 1 assert Issue.objects.filter_dates( end_date=date(2018, 1, 2), ).event_count() == 3 assert Issue.objects.filter_dates( start_date=date(2018, 1, 1), end_date=date(2018, 1, 3), ).event_count() == 5 assert Issue.objects.filter_dates( start_date=date(2018, 1, 6), ).event_count() == 0
def test_issuebucket_event_count_multiple_issues(): issue1, issue2 = IssueFactory.create_batch(2) issue1.count_event('asdf', date(2018, 1, 1)) issue1.count_event('qwer', date(2018, 1, 1)) issue2.count_event('asdf', date(2018, 1, 2)) assert IssueBucket.objects.event_count(issue=issue1) == 2 assert IssueBucket.objects.event_count(issue=issue2) == 1
def test_issuebucket_event_count_uniques(): issue = IssueFactory.create() issue.count_event('asdf', date(2018, 1, 1)) issue.count_event('asdf', date(2018, 1, 1)) issue.count_event('asdf', date(2018, 1, 2)) issue.count_event('asdf', date(2018, 1, 3)) issue.count_event('qwer', date(2018, 1, 1)) assert IssueBucket.objects.event_count(issue=issue) == 2
def test_issuebucket_event_count_multiple_issues(): issue1, issue2 = IssueFactory.create_batch(2) issue1.count_event('asdf', date(2018, 1, 1)) issue1.count_event('qwer', date(2018, 1, 1)) issue2.count_event('asdf', date(2018, 1, 2)) assert Issue.objects.filter(pk=issue1.pk).event_count() == 2 assert Issue.objects.filter(pk=issue2.pk).event_count() == 1
def test_issue_with_event_counts_uniques(): issue = IssueFactory.create() issue.count_event('asdf', date(2018, 1, 1)) issue.count_event('asdf', date(2018, 1, 1)) issue.count_event('asdf', date(2018, 1, 2)) issue.count_event('asdf', date(2018, 1, 3)) issue.count_event('qwer', date(2018, 1, 1)) issue = Issue.objects.with_event_counts().get(pk=issue.pk) assert issue.event_count == 2
def test_evaluator_dry_run(reraise_errors, set_trigger_classes): alert_backend = CollectingAlertBackend() evaluator = TriggerEvaluator(alert_backend, dry_run=True) set_trigger_classes([AlwaysNotifyTrigger]) issue = IssueFactory.create(message='AlwaysTest') evaluator.run_job() assert len(alert_backend.alerts) == 1 # Dry runs do not store that a user was notified user = User.objects.get(email='*****@*****.**') assert not user.has_been_notified_about(issue) # If we run again, the issue will be re-evaluated since it was a dry # run evaluator.run_job() assert len(alert_backend.alerts) == 2
def test_issuebucket_event_count_date_ranges(): issue = IssueFactory.create() issue.count_event('day1-1', date(2018, 1, 1)) issue.count_event('day1-2', date(2018, 1, 1)) issue.count_event('day2-1', date(2018, 1, 2)) issue.count_event('day3-1', date(2018, 1, 3)) issue.count_event('day3-2', date(2018, 1, 3)) assert IssueBucket.objects.event_count(start_date=date(2018, 1, 1)) == 5 assert IssueBucket.objects.event_count(start_date=date(2018, 1, 1), end_date=date(2018, 1, 2)) == 3 assert IssueBucket.objects.event_count(start_date=date(2018, 1, 2), end_date=date(2018, 1, 2)) == 1 assert IssueBucket.objects.event_count(end_date=date(2018, 1, 2)) == 3 assert IssueBucket.objects.event_count(start_date=date(2018, 1, 1), end_date=date(2018, 1, 3)) == 5 assert IssueBucket.objects.event_count(start_date=date(2018, 1, 6)) == 0
def test_issuebucket_top_issue_counts(): issue1, issue2, issue3 = IssueFactory.create_batch(3) for k in range(10): issue1.count_event(str(k), date(2018, 1, 1)) for k in range(20): issue2.count_event(str(k), date(2018, 1, 1)) for k in range(5): issue3.count_event(str(k), date(2018, 1, 1)) assert IssueBucket.objects.top_issue_counts(limit=3) == [ (20, issue2), (10, issue1), (5, issue3), ] assert IssueBucket.objects.top_issue_counts(limit=2) == [ (20, issue2), (10, issue1), ]
def test_evaluator_always(reraise_errors, set_trigger_classes): alert_backend = CollectingAlertBackend() evaluator = TriggerEvaluator(alert_backend, dry_run=False) set_trigger_classes([AlwaysNotifyTrigger]) issue = IssueFactory.create(message='AlwaysTest') evaluator.run_job() assert len(alert_backend.alerts) == 1 alert = alert_backend.alerts[0] assert alert.to == '*****@*****.**' assert alert.subject == '[Firefox Browser Errors] Error: AlwaysTest' assert 'AlwaysTest' in alert.body assert issue.group_id in alert.body user = User.objects.get(email='*****@*****.**') assert user.has_been_notified_about(issue) # If we run again, the issue will not be re-evaluated evaluator.run_job() assert len(alert_backend.alerts) == 1