fix up tests to be internally consistent

notifications should always have at least one of job and api key, and
the key type should match the api key's key type (or be 'normal')
This commit is contained in:
Leo Hemsted
2017-08-02 15:35:56 +01:00
parent 5d61b3644c
commit 372b10f19c
7 changed files with 151 additions and 247 deletions

View File

@@ -552,11 +552,11 @@ def test_fetch_stats_counts_should_ignore_team_key(
sample_team_api_key
):
# two created email, one failed email, and one created sms
create_notification(notify_db, notify_db_session, api_key_id=sample_api_key.id, key_type=sample_api_key.key_type)
create_notification(notify_db, notify_db_session, api_key=sample_api_key, key_type=sample_api_key.key_type)
create_notification(
notify_db, notify_db_session, api_key_id=sample_test_api_key.id, key_type=sample_test_api_key.key_type)
notify_db, notify_db_session, api_key=sample_test_api_key, key_type=sample_test_api_key.key_type)
create_notification(
notify_db, notify_db_session, api_key_id=sample_team_api_key.id, key_type=sample_team_api_key.key_type)
notify_db, notify_db_session, api_key=sample_team_api_key, key_type=sample_team_api_key.key_type)
create_notification(
notify_db, notify_db_session)
@@ -757,24 +757,17 @@ def test_dao_suspend_service_marks_service_as_inactive_and_expires_api_keys(samp
("8", "4", "2")]) # a date range that starts more than 7 days ago
def test_fetch_stats_by_date_range_for_all_services_returns_test_notifications(notify_db,
notify_db_session,
sample_api_key,
start_delta,
end_delta,
expected):
result_one = create_notification(notify_db, notify_db_session, created_at=datetime.now(),
api_key_id=sample_api_key.id, key_type='test')
create_notification(notify_db, notify_db_session, created_at=datetime.now() - timedelta(days=2),
api_key_id=sample_api_key.id, key_type='test')
create_notification(notify_db, notify_db_session, created_at=datetime.now() - timedelta(days=3),
api_key_id=sample_api_key.id, key_type='test')
create_notification(notify_db, notify_db_session, created_at=datetime.now() - timedelta(days=4),
api_key_id=sample_api_key.id, key_type='normal')
create_notification(notify_db, notify_db_session, created_at=datetime.now() - timedelta(days=4),
api_key_id=sample_api_key.id, key_type='test')
create_notification(notify_db, notify_db_session, created_at=datetime.now() - timedelta(days=8),
api_key_id=sample_api_key.id, key_type='test')
create_notification(notify_db, notify_db_session, created_at=datetime.now() - timedelta(days=8),
api_key_id=sample_api_key.id, key_type='normal')
create_noti = functools.partial(create_notification, notify_db, notify_db_session)
result_one = create_noti(created_at=datetime.now(), key_type='test')
create_noti(created_at=datetime.now() - timedelta(days=2), key_type='test')
create_noti(created_at=datetime.now() - timedelta(days=3), key_type='test')
create_noti(created_at=datetime.now() - timedelta(days=4), key_type='normal')
create_noti(created_at=datetime.now() - timedelta(days=4), key_type='test')
create_noti(created_at=datetime.now() - timedelta(days=8), key_type='test')
create_noti(created_at=datetime.now() - timedelta(days=8), key_type='normal')
start_date = (datetime.utcnow() - timedelta(days=int(start_delta))).date()
end_date = (datetime.utcnow() - timedelta(days=int(end_delta))).date()