Skip to content

Commit

Permalink
notifications: split notifications es and creations tests.
Browse files Browse the repository at this point in the history
* Improves units testing to have a separate test for functionality.

Co-Authored-by: Aly Badr <aly.badr@rero.ch>
  • Loading branch information
Aly Badr committed Jun 19, 2019
1 parent 72623c7 commit 44fdfb4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 30 deletions.
16 changes: 5 additions & 11 deletions rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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()),
Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
51 changes: 33 additions & 18 deletions tests/ui/notifications/test_notifications_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 44fdfb4

Please sign in to comment.