From 18ed90158e8905d07f74d535c0e57a86766aef58 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Tue, 26 Sep 2017 12:16:33 +0100 Subject: [PATCH] add tests for new noti dao function --- .../test_letter_api_notification_dao.py | 51 +++++++++++++++++++ .../notification_dao/test_notification_dao.py | 5 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/app/dao/notification_dao/test_letter_api_notification_dao.py diff --git a/tests/app/dao/notification_dao/test_letter_api_notification_dao.py b/tests/app/dao/notification_dao/test_letter_api_notification_dao.py new file mode 100644 index 000000000..41869b15e --- /dev/null +++ b/tests/app/dao/notification_dao/test_letter_api_notification_dao.py @@ -0,0 +1,51 @@ +from app.models import ( + NOTIFICATION_CREATED, + NOTIFICATION_PENDING, + NOTIFICATION_SENDING, + KEY_TYPE_TEST, + KEY_TYPE_NORMAL +) +from app.dao.notifications_dao import dao_set_created_live_letter_api_notifications_to_pending + +from tests.app.db import create_notification + + +def test_should_only_get_letter_notifications( + sample_letter_notification, + sample_email_notification, + sample_notification +): + ret = dao_set_created_live_letter_api_notifications_to_pending() + + assert sample_letter_notification.status == NOTIFICATION_PENDING + assert sample_email_notification.status == NOTIFICATION_CREATED + assert sample_notification.status == NOTIFICATION_CREATED + assert ret == [sample_letter_notification] + + +def test_should_only_get_created_letters(sample_letter_template): + created_noti = create_notification(sample_letter_template, status=NOTIFICATION_CREATED) + create_notification(sample_letter_template, status=NOTIFICATION_PENDING) + create_notification(sample_letter_template, status=NOTIFICATION_SENDING) + + ret = dao_set_created_live_letter_api_notifications_to_pending() + + assert ret == [created_noti] + + +def test_should_only_get_api_letters(sample_letter_template, sample_letter_job): + api_noti = create_notification(sample_letter_template) + job_noti = create_notification(sample_letter_template, job=sample_letter_job) + + ret = dao_set_created_live_letter_api_notifications_to_pending() + + assert ret == [api_noti] + + +def test_should_only_get_normal_api_letters(sample_letter_template): + live_noti = create_notification(sample_letter_template, key_type=KEY_TYPE_NORMAL) + test_noti = create_notification(sample_letter_template, key_type=KEY_TYPE_TEST) + + ret = dao_set_created_live_letter_api_notifications_to_pending() + + assert ret == [live_noti] diff --git a/tests/app/dao/notification_dao/test_notification_dao.py b/tests/app/dao/notification_dao/test_notification_dao.py index 2b4e9479c..ba8378827 100644 --- a/tests/app/dao/notification_dao/test_notification_dao.py +++ b/tests/app/dao/notification_dao/test_notification_dao.py @@ -42,7 +42,10 @@ from app.dao.notifications_dao import ( is_delivery_slow_for_provider, dao_update_notifications_for_job_to_sent_to_dvla, dao_get_notifications_by_to_field, - dao_created_scheduled_notification, dao_get_scheduled_notifications, set_scheduled_notification_to_processed) + dao_created_scheduled_notification, + dao_get_scheduled_notifications, + set_scheduled_notification_to_processed +) from app.dao.services_dao import dao_update_service from tests.app.db import create_notification, create_api_key