From 44fdfb4cc83217b2e70fc6f88f0b186c946fcad8 Mon Sep 17 00:00:00 2001 From: Aly Badr Date: Tue, 18 Jun 2019 08:26:42 +0200 Subject: [PATCH] notifications: split notifications es and creations tests. * Improves units testing to have a separate test for functionality. Co-Authored-by: Aly Badr --- rero_ils/config.py | 16 ++---- tests/api/test_serializers.py | 2 +- .../notifications/test_notifications_api.py | 51 ++++++++++++------- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/rero_ils/config.py b/rero_ils/config.py index e0669e75ed..fe2495eb38 100644 --- a/rero_ils/config.py +++ b/rero_ils/config.py @@ -214,8 +214,8 @@ def _(x): }, 'notification-creation': { 'task': - 'rero-ils.modules.tasks.create_over_and_due_soon_notifications', - 'schedule': crontab(hour=4, minute=00) + 'rero_ils.modules.notifications.tasks:create_over_and_due_soon_notifications', + 'schedule': crontab(minute="*/5") }, # 'mef-harvester': { # 'task': 'rero_ils.modules.apiharvester.tasks.harvest_records', @@ -662,19 +662,13 @@ def _(x): search_type=None, record_serializers={ 'application/json': ( - 'rero_ils.modules.serializers' ':json_v1_response' - ), - 'application/can-delete+json': ( - 'rero_ils.modules.serializers' ':can_delete_json_v1_response' + 'rero_ils.modules.serializers:json_v1_response' ) }, search_serializers={ 'application/json': ( - 'invenio_records_rest.serializers' ':json_v1_search' - ), - 'application/can-delete+json': ( - 'rero_ils.modules.serializers' ':can_delete_json_v1_search' - ), + 'rero_ils.modules.serializers:json_v1_search' + ) }, record_loaders={ 'application/json': lambda: Notification(request.get_json()), diff --git a/tests/api/test_serializers.py b/tests/api/test_serializers.py index d4ba11b10a..2716d2c364 100644 --- a/tests/api/test_serializers.py +++ b/tests/api/test_serializers.py @@ -130,7 +130,7 @@ def test_items_serializers( patron_martigny_no_email, librarian_martigny_no_email, librarian_sion_no_email, - loan_pending + loan_pending_martigny ): """Test record retrieval.""" login_user(client, librarian_martigny_no_email) diff --git a/tests/ui/notifications/test_notifications_api.py b/tests/ui/notifications/test_notifications_api.py index 517bdd8689..1370a5c7ef 100644 --- a/tests/ui/notifications/test_notifications_api.py +++ b/tests/ui/notifications/test_notifications_api.py @@ -36,9 +36,23 @@ notification_id_fetcher as fetcher -def test_notification_create_and_es_mapping( - dummy_notification, loan_validated_martigny, mailbox): - """Test notification creation.""" +def test_notification_organisation_pid( + org_martigny, notification_availability_martigny): + """Test organisation pid has been added during the indexing.""" + search = NotificationsSearch() + pid = notification_availability_martigny.get('pid') + notification = next(search.filter('term', pid=pid).scan()) + assert notification.organisation.pid == org_martigny.pid + + # test notification can_delete + assert notification_availability_martigny.get_links_to_me() == {} + assert notification_availability_martigny.can_delete + + +def test_notification_es_mapping( + dummy_notification, loan_validated_martigny): + """Test notification elasticsearch mapping.""" + search = NotificationsSearch() mapping = get_mapping(search.Meta.index) assert mapping @@ -51,6 +65,22 @@ def test_notification_create_and_es_mapping( loan_ref = '{loan_url}{pid}'.format(**notif_data) notif['loan'] = {"$ref": loan_ref} + Notification.create(notif, dbcommit=True, delete_pid=True, reindex=True) + + assert mapping == get_mapping(search.Meta.index) + + +def test_notification_create( + es_clear, dummy_notification, loan_validated_martigny, mailbox): + """Test notification creation.""" + notif = deepcopy(dummy_notification) + notif_data = { + 'loan_url': 'https://ils.rero.ch/api/loans/', + 'pid': loan_validated_martigny.get('loan_pid') + } + loan_ref = '{loan_url}{pid}'.format(**notif_data) + notif['loan'] = {"$ref": loan_ref} + notification = Notification.create( notif, dbcommit=True, delete_pid=True, reindex=True) assert notification == notif @@ -60,24 +90,9 @@ def test_notification_create_and_es_mapping( notification = Notification.get_record_by_pid(pid) assert notification == notif - assert mapping == get_mapping(search.Meta.index) - fetched_pid = fetcher(notification.id, notification) assert fetched_pid.pid_value == pid assert fetched_pid.pid_type == 'notif' notification.dispatch() assert len(mailbox) == 1 - - -def test_notification_organisation_pid( - org_martigny, notification_availability_martigny): - """Test organisation pid has been added during the indexing.""" - search = NotificationsSearch() - pid = notification_availability_martigny.get('pid') - notification = next(search.filter('term', pid=pid).scan()) - assert notification.organisation.pid == org_martigny.pid - - # test notification can_delete - assert notification_availability_martigny.get_links_to_me() == {} - assert notification_availability_martigny.can_delete