-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into sarc-371-api
- Loading branch information
Showing
7 changed files
with
119 additions
and
24 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
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
import sarc.account_matching.make_matches | ||
import sarc.ldap.acquire | ||
from sarc.client.ldap.api import get_user | ||
from sarc.client.ldap.api import get_user, get_users | ||
|
||
|
||
@pytest.mark.usefixtures("empty_read_write_db") | ||
|
@@ -68,6 +68,75 @@ def test_acquire_ldap(patch_return_values, mock_file): | |
assert js_user is None | ||
|
||
|
||
@pytest.mark.usefixtures("empty_read_write_db") | ||
def test_acquire_ldap_revision_change(patch_return_values, mock_file): | ||
""" | ||
Test two LDAP acquisition, with a change in the LDAP data. | ||
This should result in a new record in the database. | ||
Then, one third acquisition, with no change in the LDAP data. | ||
This should result in no change in the database. | ||
""" | ||
nbr_users = 3 | ||
|
||
patch_return_values( | ||
{ | ||
"sarc.ldap.read_mila_ldap.query_ldap": fake_raw_ldap_data(nbr_users), | ||
"sarc.ldap.mymila.query_mymila_csv": [], | ||
} | ||
) | ||
|
||
# Patch the built-in `open()` function for each file path | ||
with patch("builtins.open", side_effect=mock_file): | ||
sarc.ldap.acquire.run() | ||
|
||
# inspect database to check the number of records | ||
# should be nbr_users | ||
users = get_users(latest=False) | ||
nb_users_1 = len(users) | ||
assert nb_users_1 == nbr_users | ||
|
||
# re-acquire the same data | ||
with patch("builtins.open", side_effect=mock_file): | ||
sarc.ldap.acquire.run() | ||
|
||
# inspect database to check the number of records | ||
# should be the same | ||
users = get_users(latest=False) | ||
assert len(users) == nb_users_1 | ||
|
||
# change fake data | ||
patch_return_values( | ||
{ | ||
"sarc.ldap.read_mila_ldap.query_ldap": fake_raw_ldap_data( | ||
nbr_users, | ||
hardcoded_values_by_user={ | ||
2: { # The first user who is not a prof is the one with index 2 | ||
"supervisor": "[email protected]" | ||
} | ||
}, | ||
) | ||
} | ||
) | ||
|
||
# re-acquire the new data | ||
with patch("builtins.open", side_effect=mock_file): | ||
sarc.ldap.acquire.run() | ||
|
||
# inspect database to check the number of records | ||
# should be incremented by 1 | ||
users = get_users(latest=False) | ||
assert len(users) == nb_users_1 + 1 | ||
|
||
# re-acquire the same data | ||
with patch("builtins.open", side_effect=mock_file): | ||
sarc.ldap.acquire.run() | ||
|
||
# inspect database to check the number of records | ||
# should be the same | ||
users = get_users(latest=False) | ||
assert len(users) == nb_users_1 + 1 | ||
|
||
|
||
@pytest.mark.usefixtures("empty_read_write_db") | ||
def test_merge_ldap_and_mymila(patch_return_values, mock_file): | ||
nbr_users = 10 | ||
|