-
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.
- Loading branch information
Showing
16 changed files
with
203 additions
and
45 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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from sarc.config import LDAPConfig | ||
from sarc.users.read_mila_ldap import load_ldap_exceptions | ||
|
||
|
||
def apply_users_delegation_exceptions(DD_persons, ldap_config: LDAPConfig, span): | ||
""" | ||
Apply manual exceptions to users; | ||
these exceptions are defined in the exceptions.json file refered in the LDAPConfig. | ||
""" | ||
span.add_event("Applying users delegation exceptions ...") | ||
# Load exceptions | ||
exceptions = load_ldap_exceptions(ldap_config) | ||
|
||
for _, user in DD_persons.items(): | ||
if ( | ||
exceptions | ||
and user["mila_ldap"]["mila_email_username"] in exceptions["delegations"] | ||
): | ||
span.add_event( | ||
f"Applying delegation exception for {user['mila_ldap']['mila_email_username']} ..." | ||
) | ||
user["teacher_delegations"] = exceptions["delegations"][ | ||
user["mila_ldap"]["mila_email_username"] | ||
] | ||
|
||
|
||
def apply_users_supervisor_exceptions(DD_persons, ldap_config: LDAPConfig, span): | ||
""" | ||
Apply manual exceptions to users; | ||
these exceptions are defined in the exceptions.json file refered in the LDAPConfig. | ||
""" | ||
span.add_event("Applying users supervisor exceptions ...") | ||
# Load exceptions | ||
exceptions = load_ldap_exceptions(ldap_config) | ||
|
||
for _, user in DD_persons.items(): | ||
# if there is a supervisors override, use it whatever the student status may be | ||
if exceptions and user["mila_ldap"]["mila_email_username"] in exceptions.get( | ||
"supervisors_overrides", [] | ||
): | ||
span.add_event( | ||
f"Applying supervisor exception for {user['mila_ldap']['mila_email_username']} ..." | ||
) | ||
supervisors = exceptions["supervisors_overrides"][ | ||
user["mila_ldap"]["mila_email_username"] | ||
] | ||
user["mila_ldap"]["supervisor"] = None | ||
user["mila_ldap"]["co_supervisor"] = None | ||
if len(supervisors) >= 1: | ||
user["mila_ldap"]["supervisor"] = supervisors[0] | ||
else: | ||
user["mila_ldap"]["supervisor"] = None | ||
if len(supervisors) >= 2: | ||
user["mila_ldap"]["co_supervisor"] = supervisors[1] | ||
else: | ||
user["mila_ldap"]["co_supervisor"] = None |
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 |
---|---|---|
|
@@ -216,8 +216,24 @@ def file_contents(): | |
""" | ||
exceptions_json_path = """ | ||
{ | ||
"not_prof": [], | ||
"not_student": [] | ||
"not_teacher": [], | ||
"not_student": [], | ||
"delegations": { | ||
"[email protected]": [ | ||
"[email protected]", | ||
"[email protected]" | ||
] | ||
}, | ||
"supervisors_overrides": { | ||
"[email protected]": [ | ||
"[email protected]" | ||
], | ||
"[email protected]": [ | ||
"[email protected]", | ||
"[email protected]" | ||
] | ||
} | ||
} | ||
""" | ||
|
||
|
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 |
---|---|---|
|
@@ -118,6 +118,37 @@ def test_acquire_users(cli_main, patch_return_values, mock_file, captrace): | |
js_user = get_user(drac_account_username="stranger.person") | ||
assert js_user is None | ||
|
||
# test supervisor overrides | ||
js_user = get_user(mila_email_username="[email protected]") | ||
assert js_user is not None | ||
assert js_user.mila_ldap["supervisor"] == "[email protected]" | ||
assert js_user.mila_ldap["co_supervisor"] == None | ||
|
||
js_user = get_user(mila_email_username="[email protected]") | ||
assert js_user is not None | ||
assert js_user.mila_ldap["supervisor"] == "[email protected]" | ||
assert js_user.mila_ldap["co_supervisor"] == "[email protected]" | ||
|
||
# test delegations | ||
# john.smith003 should have delegations for john.smith004 and john.smith005 | ||
# john.smith004 should have no delegations | ||
# john.smith005 should have no delegations | ||
|
||
js_user = get_user(mila_email_username="[email protected]") | ||
assert js_user is not None | ||
assert js_user.teacher_delegations is not None | ||
assert "[email protected]" in js_user.teacher_delegations | ||
assert "[email protected]" in js_user.teacher_delegations | ||
assert "[email protected]" not in js_user.teacher_delegations | ||
|
||
js_user = get_user(mila_email_username="[email protected]") | ||
assert js_user is not None | ||
assert js_user.teacher_delegations == None | ||
|
||
js_user = get_user(mila_email_username="[email protected]") | ||
assert js_user is not None | ||
assert js_user.teacher_delegations == None | ||
|
||
# Check traces | ||
# NB: We don't check logging here, because | ||
# this execution won't display "acquire users" logs, | ||
|
@@ -132,14 +163,28 @@ def test_acquire_users(cli_main, patch_return_values, mock_file, captrace): | |
|
||
assert spans[1].name == "match_drac_to_mila_accounts" | ||
assert spans[1].status.status_code == StatusCode.OK | ||
assert len(spans[1].events) == 4 | ||
assert len(spans[1].events) == 9 | ||
assert ( | ||
spans[1].events[0].name | ||
== "Loading mila_ldap, drac_roles and drac_members from files ..." | ||
) | ||
assert spans[1].events[1].name == "Loading matching config from file ..." | ||
assert spans[1].events[2].name == "Matching DRAC/CC to mila accounts ..." | ||
assert spans[1].events[3].name == "Committing matches to database ..." | ||
assert spans[1].events[3].name == "Applying users delegation exceptions ..." | ||
assert ( | ||
spans[1].events[4].name | ||
== "Applying delegation exception for [email protected] ..." | ||
) | ||
assert spans[1].events[5].name == "Applying users supervisor exceptions ..." | ||
assert ( | ||
spans[1].events[6].name | ||
== "Applying supervisor exception for [email protected] ..." | ||
) | ||
assert ( | ||
spans[1].events[7].name | ||
== "Applying supervisor exception for [email protected] ..." | ||
) | ||
assert spans[1].events[8].name == "Committing matches to database ..." | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
@@ -184,12 +229,16 @@ def test_acquire_users_supervisors( | |
nbr_users = 4 | ||
nbr_profs = 2 | ||
|
||
# for the test we will use the user with index 3, | ||
# which is the first user who has no supervisor override in the mock data | ||
# so that this test won't be affected by the previous test | ||
|
||
patch_return_values( | ||
{ | ||
"sarc.users.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 | ||
3: { # The first user who is not a prof is the one with index 3 | ||
"supervisor": ldap_supervisor | ||
} | ||
}, | ||
|
@@ -198,7 +247,7 @@ def test_acquire_users_supervisors( | |
nbr_users=nbr_users, | ||
nbr_profs=nbr_profs, | ||
hardcoded_values_by_user={ | ||
2: { # The first user who is not a prof is the one with index 2 | ||
3: { # The first user who is not a prof is the one with index 3 | ||
"Supervisor Principal": mymila_supervisor | ||
} | ||
}, | ||
|
@@ -221,8 +270,8 @@ def test_acquire_users_supervisors( | |
|
||
# Validate the results of all of this by inspecting the database. | ||
js_user = get_user( | ||
mila_email_username=f"john.smith002@mila.quebec" | ||
) # We modified the user with index 2; thus this is the one we retrieve | ||
mila_email_username=f"john.smith003@mila.quebec" | ||
) # We modified the user with index 3; thus this is the one we retrieve | ||
assert js_user.mila_ldap["supervisor"] == expected_supervisor | ||
|
||
|
||
|
@@ -268,12 +317,16 @@ def test_acquire_users_co_supervisors( | |
nbr_users = 4 | ||
nbr_profs = 2 | ||
|
||
# for the test we will use the user with index 3, | ||
# which is the first user who has no supervisor override in the mock data | ||
# so that this test won't be affected by the previous test | ||
|
||
patch_return_values( | ||
{ | ||
"sarc.users.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 | ||
3: { # The first user who is not a prof is the one with index 3 | ||
"co_supervisor": ldap_co_supervisor | ||
} | ||
}, | ||
|
@@ -282,7 +335,7 @@ def test_acquire_users_co_supervisors( | |
nbr_users=nbr_users, | ||
nbr_profs=nbr_profs, | ||
hardcoded_values_by_user={ | ||
2: { # The first user who is not a prof is the one with index 2 | ||
3: { # The first user who is not a prof is the one with index 3 | ||
"Co-Supervisor": mymila_co_supervisor | ||
} | ||
}, | ||
|
@@ -305,8 +358,8 @@ def test_acquire_users_co_supervisors( | |
|
||
# Validate the results of all of this by inspecting the database. | ||
js_user = get_user( | ||
mila_email_username=f"john.smith002@mila.quebec" | ||
) # We modified the user with index 2; thus this is the one we retrieve | ||
mila_email_username=f"john.smith003@mila.quebec" | ||
) # We modified the user with index 3; thus this is the one we retrieve | ||
assert js_user.mila_ldap["co_supervisor"] == expected_co_supervisor | ||
|
||
|
||
|
@@ -411,12 +464,26 @@ def test_acquire_users_prompt( | |
|
||
assert spans[1].name == "match_drac_to_mila_accounts" | ||
assert spans[1].status.status_code == StatusCode.OK | ||
assert len(spans[1].events) == 5 | ||
assert len(spans[1].events) == 10 | ||
assert ( | ||
spans[1].events[0].name | ||
== "Loading mila_ldap, drac_roles and drac_members from files ..." | ||
) | ||
assert spans[1].events[1].name == "Loading matching config from file ..." | ||
assert spans[1].events[2].name == "Matching DRAC/CC to mila accounts ..." | ||
assert spans[1].events[3].name == "Committing matches to database ..." | ||
assert spans[1].events[4].name == "Saving 1 manual matches ..." | ||
assert spans[1].events[3].name == "Applying users delegation exceptions ..." | ||
assert ( | ||
spans[1].events[4].name | ||
== "Applying delegation exception for [email protected] ..." | ||
) | ||
assert spans[1].events[5].name == "Applying users supervisor exceptions ..." | ||
assert ( | ||
spans[1].events[6].name | ||
== "Applying supervisor exception for [email protected] ..." | ||
) | ||
assert ( | ||
spans[1].events[7].name | ||
== "Applying supervisor exception for [email protected] ..." | ||
) | ||
assert spans[1].events[8].name == "Committing matches to database ..." | ||
assert spans[1].events[9].name == "Saving 1 manual matches ..." |
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ Found 3 users(s): | |
"active": true | ||
}, | ||
"drac": null, | ||
"teacher_delegations": null, | ||
"mila_ldap": { | ||
"co_supervisor": null, | ||
"display_name": "M/Ms Bonhomme", | ||
|
@@ -34,6 +35,7 @@ Found 3 users(s): | |
"email": "[email protected]", | ||
"active": true | ||
}, | ||
"teacher_delegations": null, | ||
"mila_ldap": { | ||
"co_supervisor": null, | ||
"display_name": "M/Ms Petitbonhomme", | ||
|
@@ -74,6 +76,7 @@ Found 3 users(s): | |
"email": "[email protected]", | ||
"active": true | ||
}, | ||
"teacher_delegations": null, | ||
"mila_ldap": { | ||
"co_supervisor": null, | ||
"display_name": "M/Ms Beaubonhomme", | ||
|
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
Oops, something went wrong.