-
Notifications
You must be signed in to change notification settings - Fork 27
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
3 changed files
with
44 additions
and
2 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
from typing import Literal, Optional | ||
from uuid import UUID | ||
|
||
from models_library.basic_types import IdInt | ||
from pydantic import BaseModel, EmailStr, Field, validator | ||
from servicelib.json_serialization import json_dumps | ||
from simcore_postgres_database.models.users import UserRole | ||
|
@@ -60,6 +61,7 @@ class ProfileUpdate(_ProfileCommon): | |
|
||
|
||
class ProfileGet(_ProfileCommon): | ||
id: IdInt | ||
login: EmailStr | ||
role: Literal["Anonymous", "Guest", "User", "Tester", "Admin"] | ||
groups: Optional[AllUsersGroups] = None | ||
|
@@ -79,11 +81,13 @@ class Config: | |
schema_extra = { | ||
"examples": [ | ||
{ | ||
"id": 1, | ||
"login": "[email protected]", | ||
"role": "Admin", | ||
"gravatar_id": "205e460b479e2e5b48aec07710c08d50", | ||
}, | ||
{ | ||
"id": 42, | ||
"login": "[email protected]", | ||
"role": UserRole.ADMIN, | ||
"expirationDate": "2022-09-14", | ||
|
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 |
---|---|---|
|
@@ -53,7 +53,7 @@ def test_profile_get_expiration_date(faker: Faker): | |
fake_expiration = datetime.utcnow() | ||
|
||
profile = ProfileGet( | ||
login=faker.email(), role=UserRole.ADMIN, expiration_date=fake_expiration | ||
id=1, login=faker.email(), role=UserRole.ADMIN, expiration_date=fake_expiration | ||
) | ||
|
||
assert fake_expiration.date() == profile.expiration_date | ||
|
@@ -73,3 +73,38 @@ def test_profile_get_role(user_role: str): | |
data["role"] = UserRole(user_role) | ||
m2 = ProfileGet(**data) | ||
assert m1 == m2 | ||
|
||
|
||
def test_parsing_output_of_get_user_profile(): | ||
|
||
result_from_db_query_and_composition = { | ||
"id": 1, | ||
"login": "[email protected]", | ||
"first_name": "PtN5Ab0uv", | ||
"last_name": "", | ||
"role": "Guest", | ||
"gravatar_id": "9d5e02c75fcd4bce1c8861f219f7f8a5", | ||
"groups": { | ||
"me": { | ||
"gid": 2, | ||
"label": "PtN5Ab0uv", | ||
"description": "primary group", | ||
"thumbnail": None, | ||
"inclusionRules": {}, | ||
"accessRights": {"read": True, "write": False, "delete": False}, | ||
}, | ||
"organizations": [], | ||
"all": { | ||
"gid": 1, | ||
"label": "Everyone", | ||
"description": "all users", | ||
"thumbnail": None, | ||
"inclusionRules": {}, | ||
"accessRights": {"read": True, "write": False, "delete": False}, | ||
}, | ||
}, | ||
"password": "secret", # should be stripped out | ||
} | ||
|
||
profile = ProfileGet.parse_obj(result_from_db_query_and_composition) | ||
assert "password" not in profile.dict(exclude_unset=True) |