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 18, 2019
1 parent 72623c7 commit 17067f7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
12 changes: 3 additions & 9 deletions rero_ils/config.py
Original file line number Diff line number Diff line change
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
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 17067f7

Please sign in to comment.