-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automate users scraping #124
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7957ac8
temporarily disable mymila source
nurbal 999f8c6
cleaner "NotImplementedException" handling for `fetch_mymila` call
nurbal e342244
automate daily LDAP scraping
nurbal 93d857f
fix tests
nurbal 138c3ab
Add test for users versions count
nurbal a48625f
lint
nurbal 0333861
update test
nurbal c157acf
ignore "record_start" and "record_end" fields
nurbal f65fbb0
fix test typo
nurbal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
import sarc.account_matching.make_matches | ||
import sarc.ldap.acquire | ||
from sarc.ldap.api import get_user | ||
from sarc.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 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je l'ai fait comme ça, de manière à gérer les deux cas:
Pour l'heure le traitement de ce fichier est l'objet d'une autre PR ( #120 ) mais pas encore Ok. Donc on ne place simplement pas le CSV en prod et le code fonctionne en l'état.