-
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.
feat: refactor user model, and add institutions attribute
- Loading branch information
1 parent
98635a0
commit 9b840aa
Showing
7 changed files
with
66 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
__all__ = ["oauth2_admin", "BearerTokenAuthBackend", "AuthenticatedUser"] | ||
__all__ = ["oauth2_admin", "BearerTokenAuthBackend"] | ||
|
||
from .oauth2_admin import oauth2_admin | ||
from .oauth2_backend import BearerTokenAuthBackend, AuthenticatedUser | ||
from .oauth2_backend import BearerTokenAuthBackend |
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 @@ | |
from pytest_mock import MockerFixture | ||
from starlette.authentication import AuthCredentials | ||
|
||
from oauth2.oauth2_backend import AuthenticatedUser | ||
from entities.models import AuthenticatedUser | ||
|
||
|
||
class TestAdminApi: | ||
|
@@ -14,13 +14,33 @@ def test_get_me_unauthed(self, app_fixture: FastAPI, unauthed_user_mock: Mock): | |
res = client.get("/v1/admin/me") | ||
assert res.status_code == 403 | ||
|
||
def test_get_me_authed( | ||
self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock | ||
def test_get_me_authed_with_no_institutions( | ||
self, app_fixture: FastAPI, authed_user_mock: Mock | ||
): | ||
client = TestClient(app_fixture) | ||
res = client.get("/v1/admin/me") | ||
assert res.status_code == 200 | ||
assert res.json().get("name") == "test" | ||
assert res.json().get("institutions") == [] | ||
|
||
def test_get_me_authed_with_institutions( | ||
self, app_fixture: FastAPI, auth_mock: Mock | ||
): | ||
claims = { | ||
"name": "test", | ||
"preferred_username": "test_user", | ||
"email": "[email protected]", | ||
"sub": "testuser123", | ||
"institutions": ["/TEST1LEI", "/TEST2LEI"], | ||
} | ||
auth_mock.return_value = ( | ||
AuthCredentials(["authenticated"]), | ||
AuthenticatedUser.from_claim(claims), | ||
) | ||
client = TestClient(app_fixture) | ||
res = client.get("/v1/admin/me") | ||
assert res.status_code == 200 | ||
assert res.json().get("institutions") == ["TEST1LEI", "TEST2LEI"] | ||
|
||
def test_update_me_unauthed(self, app_fixture: FastAPI, unauthed_user_mock: Mock): | ||
client = TestClient(app_fixture) | ||
|