-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/161_lei_check_from_commons
- Loading branch information
Showing
2 changed files
with
54 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,32 +63,76 @@ def test_update_me_no_permission(self, app_fixture: FastAPI, auth_mock: Mock): | |
res = client.put("/v1/admin/me", json={"first_name": "testFirst", "last_name": "testLast", "leis": ["testLei"]}) | ||
assert res.status_code == 403 | ||
|
||
def test_update_me(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock): | ||
def test_update_me(self, mocker: MockerFixture, app_fixture: FastAPI, auth_mock: Mock): | ||
update_user_mock = mocker.patch("regtech_api_commons.oauth2.oauth2_admin.OAuth2Admin.update_user") | ||
associate_lei_mock = mocker.patch("regtech_api_commons.oauth2.oauth2_admin.OAuth2Admin.associate_to_leis") | ||
get_user_mock = mocker.patch("regtech_api_commons.oauth2.oauth2_admin.OAuth2Admin.get_user") | ||
claims = { | ||
"name": "testFirst testLast", | ||
"preferred_username": "test_user", | ||
"email": "[email protected]", | ||
"sub": "testuser123", | ||
"institutions": ["testlei1", "testlei2"], | ||
} | ||
auth_mock.return_value = ( | ||
AuthCredentials(["manage-account"]), | ||
AuthenticatedUser.from_claim(claims), | ||
) | ||
update_user_mock.return_value = None | ||
associate_lei_mock.return_value = None | ||
get_user_mock.return_value = auth_mock.return_value[1] | ||
client = TestClient(app_fixture) | ||
data = {"first_name": "testFirst", "last_name": "testLast", "leis": ["testLei1", "testLei2"]} | ||
res = client.put("/v1/admin/me", json=data) | ||
update_user_mock.assert_called_once_with("testuser123", {"firstName": "testFirst", "lastName": "testLast"}) | ||
associate_lei_mock.assert_called_once_with("testuser123", {"testLei1", "testLei2"}) | ||
assert res.status_code == 202 | ||
assert res.status_code == 200 | ||
assert res.json().get("name") == "testFirst testLast" | ||
assert res.json().get("institutions") == ["testlei1", "testlei2"] | ||
|
||
def test_update_me_no_lei(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock): | ||
def test_update_me_no_lei(self, mocker: MockerFixture, app_fixture: FastAPI, auth_mock: Mock): | ||
update_user_mock = mocker.patch("regtech_api_commons.oauth2.oauth2_admin.OAuth2Admin.update_user") | ||
associate_lei_mock = mocker.patch("regtech_api_commons.oauth2.oauth2_admin.OAuth2Admin.associate_to_leis") | ||
get_user_mock = mocker.patch("regtech_api_commons.oauth2.oauth2_admin.OAuth2Admin.get_user") | ||
claims = { | ||
"name": "testFirst testLast", | ||
"preferred_username": "test_user", | ||
"email": "[email protected]", | ||
"sub": "testuser123", | ||
} | ||
auth_mock.return_value = ( | ||
AuthCredentials(["manage-account"]), | ||
AuthenticatedUser.from_claim(claims), | ||
) | ||
update_user_mock.return_value = None | ||
get_user_mock.return_value = auth_mock.return_value[1] | ||
client = TestClient(app_fixture) | ||
res = client.put("/v1/admin/me", json={"first_name": "testFirst", "last_name": "testLast"}) | ||
update_user_mock.assert_called_once_with("testuser123", {"firstName": "testFirst", "lastName": "testLast"}) | ||
associate_lei_mock.assert_not_called() | ||
assert res.status_code == 202 | ||
assert res.status_code == 200 | ||
assert res.json().get("name") == "testFirst testLast" | ||
assert res.json().get("institutions") == [] | ||
|
||
def test_associate_institutions(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock): | ||
def test_associate_institutions(self, mocker: MockerFixture, app_fixture: FastAPI, auth_mock: Mock): | ||
associate_lei_mock = mocker.patch("regtech_api_commons.oauth2.oauth2_admin.OAuth2Admin.associate_to_leis") | ||
get_user_mock = mocker.patch("regtech_api_commons.oauth2.oauth2_admin.OAuth2Admin.get_user") | ||
claims = { | ||
"name": "test", | ||
"preferred_username": "test_user", | ||
"email": "[email protected]", | ||
"sub": "testuser123", | ||
"institutions": ["testlei1", "testlei2"], | ||
} | ||
auth_mock.return_value = ( | ||
AuthCredentials(["manage-account"]), | ||
AuthenticatedUser.from_claim(claims), | ||
) | ||
associate_lei_mock.return_value = None | ||
get_user_mock.return_value = auth_mock.return_value[1] | ||
client = TestClient(app_fixture) | ||
res = client.put("/v1/admin/me/institutions", json=["testlei1", "testlei2"]) | ||
associate_lei_mock.assert_called_once_with("testuser123", {"testlei1", "testlei2"}) | ||
assert res.status_code == 202 | ||
assert res.status_code == 200 | ||
assert res.json().get("name") == "test" | ||
assert res.json().get("institutions") == ["testlei1", "testlei2"] |