Skip to content

Commit

Permalink
Fix: correct rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Rotheem committed Dec 22, 2024
1 parent b8c0f4d commit 8e31881
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
10 changes: 5 additions & 5 deletions app/core/schools/endpoints_schools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from app.core.users import cruds_users
from app.dependencies import (
get_db,
is_user_a_member_of,
is_user_an_ecl_member,
is_user_in,
)

router = APIRouter(tags=["Schools"])
Expand Down Expand Up @@ -52,7 +52,7 @@ async def read_schools(
async def read_school(
school_id: str,
db: AsyncSession = Depends(get_db),
user=Depends(is_user_a_member_of(GroupType.admin)),
user=Depends(is_user_in(GroupType.admin)),
):
"""
Return school with id from database as a dictionary. This includes a list of users being members of the school.
Expand All @@ -74,7 +74,7 @@ async def read_school(
async def create_school(
school: schemas_core.CoreSchoolBase,
db: AsyncSession = Depends(get_db),
user: schemas_core.CoreUser = Depends(is_user_a_member_of(GroupType.admin)),
user: schemas_core.CoreUser = Depends(is_user_in(GroupType.admin)),
):
"""
Create a new school.
Expand Down Expand Up @@ -125,7 +125,7 @@ async def update_school(
school_id: str,
school_update: schemas_core.CoreSchoolUpdate,
db: AsyncSession = Depends(get_db),
user=Depends(is_user_a_member_of(GroupType.admin)),
user=Depends(is_user_in(GroupType.admin)),
):
"""
Update the name or the description of a school.
Expand Down Expand Up @@ -165,7 +165,7 @@ async def update_school(
async def delete_school(
school_id: str,
db: AsyncSession = Depends(get_db),
user=Depends(is_user_a_member_of(GroupType.admin)),
user=Depends(is_user_in(GroupType.admin)),
):
"""
Delete school from database.
Expand Down
2 changes: 2 additions & 0 deletions app/core/users/endpoints_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from app.core.config import Settings
from app.core.groups import cruds_groups
from app.core.groups.groups_type import AccountType, GroupType
from app.core.schools import cruds_schools
from app.core.schools.schools_type import SchoolType
from app.core.users import cruds_users
from app.dependencies import (
get_db,
Expand Down
10 changes: 9 additions & 1 deletion tests/test_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ async def init_objects() -> None:
user = await create_user_with_groups(
groups=[],
)
user_schema = schemas_core.CoreUser(**user.__dict__)
school = schemas_core.CoreSchoolSimple(
id=user.school.id,
name=user.school.name,
email_regex=user.school.email_regex,
)
user_dict = user.__dict__
user_dict.pop("school")

user_schema = schemas_core.CoreUser(**user_dict, school=school)


# Test endpoints #
Expand Down
42 changes: 24 additions & 18 deletions tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,35 @@ def test_create_user_by_user_with_email(


@pytest.mark.parametrize(
("email", "expected_code", "expected_account_type"),
("email", "expected_code", "expected_account_type", "expected_school_id"),
[
("[email protected]", 201, AccountType.student),
("[email protected]", 201, AccountType.staff),
("[email protected]", 201, AccountType.former_student),
("[email protected]", 201, AccountType.external),
("[email protected]", 201, AccountType.student),
(
"[email protected]",
201,
AccountType.student,
SchoolType.centrale_lyon,
),
("[email protected]", 201, AccountType.staff, SchoolType.centrale_lyon),
(
"[email protected]",
201,
AccountType.former_student,
SchoolType.centrale_lyon,
),
("[email protected]", 201, AccountType.external, SchoolType.no_school),
(
"[email protected]",
201,
AccountType.student,
SchoolType.centrale_lyon,
),
],
)
def test_create_and_activate_user(
email: str,
expected_code: int,
expected_account_type: AccountType,
expected_school_id: SchoolType,
mocker: MockerFixture,
client: TestClient,
) -> None:
Expand All @@ -197,7 +213,7 @@ def test_create_and_activate_user(
response = client.post(
"/users/create",
json={
"email": "[email protected]",
"email": email,
},
)
assert response.status_code == expected_code
Expand All @@ -224,22 +240,12 @@ def test_create_and_activate_user(
assert user is not None
assert user["account_type"] == expected_account_type.value

users = client.get(
"/users/",
headers={"Authorization": f"Bearer {token_admin_user}"},
)
user = next(
user
for user in users.json()
if user["firstname"] == "new_user_firstname" and user["name"] == "new_user_name"
)

user_detail = client.get(
f"/users/{user['id']}",
headers={"Authorization": f"Bearer {token_admin_user}"},
)

assert user_detail.json()["school_id"] == SchoolType.centrale_lyon.value
assert user_detail.json()["school_id"] == expected_school_id.value


@pytest.mark.parametrize(
Expand Down

0 comments on commit 8e31881

Please sign in to comment.