forked from rero/rero-ils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patrons: fix patron creation and modification
* Fixes patron creation with an existing user account, closes rero#1454. * Ensures that when the patron updates his/her email in the RERO ID, the modification is synched to the patron record, closes rero#1458. * Makes the email required if the communication channel is email, closes rero#1455. Co-Authored-by: Johnny Mariéthoz <[email protected]>
- Loading branch information
Showing
5 changed files
with
115 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
|
||
import pytest | ||
from invenio_accounts.models import User | ||
from invenio_accounts.testutils import create_test_user | ||
from invenio_userprofiles import UserProfile | ||
from jsonschema.exceptions import ValidationError | ||
|
||
|
@@ -167,45 +168,51 @@ def test_patron_create(app, roles, lib_martigny, librarian_martigny_data_tmp, | |
def test_patron_create_without_email(app, roles, patron_type_children_martigny, | ||
patron_martigny_data_tmp, mailbox): | ||
"""Test Patron creation without an email.""" | ||
del patron_martigny_data_tmp['email'] | ||
patron_martigny_data_tmp = deepcopy(patron_martigny_data_tmp) | ||
|
||
# no data has been created | ||
mailbox.clear() | ||
# assert User.query.count() == 0 | ||
# assert UserProfile.query.count() == 0 | ||
|
||
# create a patron without email | ||
del patron_martigny_data_tmp['email'] | ||
ptrn = Patron.create( | ||
patron_martigny_data_tmp, | ||
dbcommit=True, | ||
delete_pid=True | ||
) | ||
# user has been created | ||
user = User.query.filter_by(id=ptrn.get('user_id')).first() | ||
assert user | ||
assert not user.email | ||
assert user == ptrn.user | ||
assert user.active | ||
assert len(mailbox) == 0 | ||
|
||
# add an email of a non existing user | ||
patron_martigny_data_tmp['email'] = '[email protected]' | ||
ptrn.replace( | ||
data=patron_martigny_data_tmp, | ||
dbcommit=True | ||
) | ||
# the user remains the same | ||
assert user == ptrn.user | ||
assert user.email == patron_martigny_data_tmp['email'] | ||
assert user.active | ||
assert len(mailbox) == 0 | ||
|
||
# update with a new email in the system | ||
patron_martigny_data_tmp['email'] = '[email protected]' | ||
ptrn.replace( | ||
data=patron_martigny_data_tmp, | ||
dbcommit=True | ||
) | ||
# the user remains the same | ||
assert user == ptrn.user | ||
assert user.email == patron_martigny_data_tmp['email'] | ||
assert user.active | ||
assert len(mailbox) == 0 | ||
|
||
# remove the email | ||
del patron_martigny_data_tmp['email'] | ||
ptrn.replace( | ||
data=patron_martigny_data_tmp, | ||
|
@@ -216,6 +223,26 @@ def test_patron_create_without_email(app, roles, patron_type_children_martigny, | |
assert user.active | ||
assert len(mailbox) == 0 | ||
|
||
# create a new invenio user in the system | ||
rero_id_user = create_test_user(email='[email protected]', active=True) | ||
|
||
# update the patron with the email of the freshed create invenio user | ||
patron_martigny_data_tmp['email'] = '[email protected]' | ||
patron_martigny_data_tmp['username'] = 'reroid' | ||
ptrn.replace( | ||
data=patron_martigny_data_tmp, | ||
dbcommit=True | ||
) | ||
# the user linked with the patron has been changed | ||
assert rero_id_user == ptrn.user | ||
# the username is updated on both user profile and patron | ||
assert rero_id_user.profile.username == ptrn.get('username') == 'reroid' | ||
|
||
# clean up created users | ||
ds = app.extensions['invenio-accounts'].datastore | ||
ds.delete_user(user) | ||
ds.delete_user(rero_id_user) | ||
|
||
|
||
def test_patron_organisation_pid(org_martigny, patron_martigny_no_email, | ||
librarian_martigny_no_email): | ||
|