diff --git a/rero_ils/config.py b/rero_ils/config.py index e0669e75ed..2fd8ebf0d2 100644 --- a/rero_ils/config.py +++ b/rero_ils/config.py @@ -214,8 +214,9 @@ 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") + # TODO: in production set this up once a day }, # 'mef-harvester': { # 'task': 'rero_ils.modules.apiharvester.tasks.harvest_records', @@ -662,19 +663,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/rero_ils/modules/circ_policies/jsonschemas/circ_policies/circ_policy-v0.0.1.json b/rero_ils/modules/circ_policies/jsonschemas/circ_policies/circ_policy-v0.0.1.json index 6cbed29bc1..c0d6bf261f 100644 --- a/rero_ils/modules/circ_policies/jsonschemas/circ_policies/circ_policy-v0.0.1.json +++ b/rero_ils/modules/circ_policies/jsonschemas/circ_policies/circ_policy-v0.0.1.json @@ -70,7 +70,7 @@ "description": "Number of days before due date for sending the availability notification.", "type": "integer", "default": 5, - "minimum": 1 + "minimum": 0 }, "number_of_days_after_due_date": { "title": "Number of days after due data.", diff --git a/rero_ils/modules/notifications/tasks.py b/rero_ils/modules/notifications/tasks.py index 85b7bd4ed6..abf7b3b5d4 100644 --- a/rero_ils/modules/notifications/tasks.py +++ b/rero_ils/modules/notifications/tasks.py @@ -35,9 +35,18 @@ def create_over_and_due_soon_notifications(): """Creates due_soon and overdue notifications.""" over_due_loans = get_overdue_loans() + no_over_due_loans = 0 for loan in over_due_loans: loan.create_notification(notification_type='overdue') + no_over_due_loans += 1 due_soon_loans = get_due_soon_loans() + no_due_soon_loans = 0 for loan in due_soon_loans: loan.create_notification(notification_type='due_soon') + no_due_soon_loans += 1 + + return 'created {no_over_due_loans} overdue loans, '\ + '{no_due_soon_loans} due soon loans'.format( + no_over_due_loans=no_over_due_loans, + no_due_soon_loans=no_due_soon_loans) diff --git a/setup.py b/setup.py index aa81f3af20..6d5ccfeb12 100644 --- a/setup.py +++ b/setup.py @@ -268,6 +268,7 @@ def run(self): 'invenio_celery.tasks': [ 'rero_ils_oaiharvest = rero_ils.modules.ebooks.tasks', 'rero_ils_mefharvest = rero_ils.modules.apiharvester.tasks', + 'rero_ils_notifications = rero_ils.modules.notifications.tasks', ], 'invenio_records.jsonresolver': [ 'organisations = rero_ils.modules.organisations.jsonresolver', 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 diff --git a/ui/src/app/records/custom-editor/circulation-settings/circulation-policy/circulation-policy.component.html b/ui/src/app/records/custom-editor/circulation-settings/circulation-policy/circulation-policy.component.html index 5c75809bc7..9c24a13357 100644 --- a/ui/src/app/records/custom-editor/circulation-settings/circulation-policy/circulation-policy.component.html +++ b/ui/src/app/records/custom-editor/circulation-settings/circulation-policy/circulation-policy.component.html @@ -111,7 +111,7 @@

Circulation Policy

Days before due date is required.
- Days before due date must be greater than 0. + Days before due date must be greater or equal to 0.