Skip to content

Commit

Permalink
Feat: refactoring tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rotheem committed Nov 27, 2024
1 parent 89416d2 commit 2519b20
Show file tree
Hide file tree
Showing 21 changed files with 174 additions and 91 deletions.
6 changes: 3 additions & 3 deletions tests/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from app.core.auth import schemas_auth
from app.core.config import Settings
from app.core.groups import cruds_groups
from app.core.groups.groups_type import GroupType
from app.core.groups.groups_type import AccountType, GroupType
from app.core.payment import cruds_payment, models_payment, schemas_payment
from app.core.payment.payment_tool import PaymentTool
from app.core.users import cruds_users
Expand Down Expand Up @@ -108,13 +108,13 @@ def change_redis_client_status(activated: bool) -> None:

async def create_user_with_groups(
groups: list[GroupType],
account_type: AccountType = AccountType.external,
user_id: str | None = None,
email: str | None = None,
password: str | None = None,
name: str | None = None,
firstname: str | None = None,
floor: FloorsType | None = None,
external: bool = False,
) -> models_core.CoreUser:
"""
Add a dummy user to the database
Expand All @@ -133,7 +133,7 @@ async def create_user_with_groups(
name=name or get_random_string(),
firstname=firstname or get_random_string(),
floor=floor,
external=external,
account_type=account_type,
nickname=None,
birthday=None,
promo=None,
Expand Down
7 changes: 5 additions & 2 deletions tests/test_PH.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fastapi.testclient import TestClient

from app.core import models_core
from app.core.groups.groups_type import GroupType
from app.core.groups.groups_type import AccountType, GroupType
from app.modules.ph import models_ph
from tests.commons import (
add_object_to_db,
Expand All @@ -33,7 +33,10 @@ async def init_objects() -> None:
token_ph = create_api_access_token(ph_user_ph)

global ph_user_simple
ph_user_simple = await create_user_with_groups([GroupType.student])
ph_user_simple = await create_user_with_groups(
[],
AccountType.student,
)

global token_simple
token_simple = create_api_access_token(ph_user_simple)
Expand Down
12 changes: 9 additions & 3 deletions tests/test_advert.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fastapi.testclient import TestClient

from app.core import models_core
from app.core.groups.groups_type import GroupType
from app.core.groups.groups_type import AccountType, GroupType
from app.modules.advert import models_advert
from tests.commons import (
add_object_to_db,
Expand Down Expand Up @@ -41,13 +41,19 @@ async def init_objects() -> None:
)
await add_object_to_db(advertiser)

user_advertiser = await create_user_with_groups([GroupType.student, GroupType.CAA])
user_advertiser = await create_user_with_groups(
[GroupType.CAA],
AccountType.student,
)

global token_advertiser
token_advertiser = create_api_access_token(user_advertiser)

global user_simple
user_simple = await create_user_with_groups([GroupType.student])
user_simple = await create_user_with_groups(
[],
AccountType.student,
)

global token_simple
token_simple = create_api_access_token(user_simple)
Expand Down
9 changes: 6 additions & 3 deletions tests/test_amap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fastapi.testclient import TestClient

from app.core import models_core
from app.core.groups.groups_type import GroupType
from app.core.groups.groups_type import AccountType, GroupType
from app.modules.amap import models_amap
from app.modules.amap.types_amap import AmapSlotType, DeliveryStatusType
from tests.commons import (
Expand Down Expand Up @@ -39,8 +39,11 @@ async def init_objects() -> None:
order, \
deletable_order_by_admin

amap_user = await create_user_with_groups([GroupType.amap])
student_user = await create_user_with_groups([GroupType.student])
amap_user = await create_user_with_groups([GroupType.amap], AccountType.student)
student_user = await create_user_with_groups(
[],
AccountType.student,
)

product = models_amap.Product(
id=str(uuid.uuid4()),
Expand Down
7 changes: 4 additions & 3 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from app.core import models_core
from app.core.auth import models_auth
from app.core.groups.groups_type import GroupType
from app.core.groups.groups_type import AccountType
from tests.commons import (
add_object_to_db,
create_api_access_token,
Expand All @@ -30,13 +30,15 @@ async def init_objects() -> None:
global user
user = await create_user_with_groups(
groups=[],
account_type=AccountType.student,
email="email@myecl.fr",
password="azerty",
)

global ecl_user
ecl_user = await create_user_with_groups(
groups=[GroupType.student],
groups=[],
account_type=AccountType.student,
email="email@etu.ec-lyon.fr",
password="azerty",
)
Expand All @@ -46,7 +48,6 @@ async def init_objects() -> None:
groups=[],
email="external@myecl.fr",
password="azerty",
external=True,
)

global access_token
Expand Down
9 changes: 6 additions & 3 deletions tests/test_booking.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fastapi.testclient import TestClient

from app.core import models_core
from app.core.groups.groups_type import GroupType
from app.core.groups.groups_type import AccountType, GroupType
from app.modules.booking import models_booking
from tests.commons import (
add_object_to_db,
Expand Down Expand Up @@ -39,13 +39,16 @@ async def init_objects() -> None:
token_admin = create_api_access_token(admin_user)

global manager_user
manager_user = await create_user_with_groups([GroupType.student, GroupType.BDE])
manager_user = await create_user_with_groups(
[GroupType.BDE],
AccountType.student,
)

global token_manager
token_manager = create_api_access_token(manager_user)

global simple_user
simple_user = await create_user_with_groups([GroupType.student])
simple_user = await create_user_with_groups([], AccountType.student)

global token_simple
token_simple = create_api_access_token(simple_user)
Expand Down
7 changes: 4 additions & 3 deletions tests/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fastapi.testclient import TestClient

from app.core import models_core
from app.core.groups.groups_type import GroupType
from app.core.groups.groups_type import AccountType, GroupType
from app.modules.booking.types_booking import Decision
from app.modules.calendar import models_calendar
from app.modules.calendar.types_calendar import CalendarEventType
Expand All @@ -27,14 +27,15 @@
async def init_objects() -> None:
global calendar_user_bde
calendar_user_bde = await create_user_with_groups(
[GroupType.student, GroupType.BDE],
[GroupType.BDE],
AccountType.student,
)

global token_bde
token_bde = create_api_access_token(calendar_user_bde)

global calendar_user_simple
calendar_user_simple = await create_user_with_groups([GroupType.student])
calendar_user_simple = await create_user_with_groups([], AccountType.student)

global token_simple
token_simple = create_api_access_token(calendar_user_simple)
Expand Down
9 changes: 6 additions & 3 deletions tests/test_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fastapi.testclient import TestClient

from app.core import models_core
from app.core.groups.groups_type import GroupType
from app.core.groups.groups_type import AccountType, GroupType
from app.modules.campaign import models_campaign
from app.modules.campaign.types_campaign import ListType
from tests.commons import (
Expand All @@ -28,8 +28,11 @@
async def init_objects() -> None:
global CAA_user, AE_user

CAA_user = await create_user_with_groups([GroupType.CAA, GroupType.AE])
AE_user = await create_user_with_groups([GroupType.AE])
CAA_user = await create_user_with_groups(
[GroupType.CAA, GroupType.AE],
AccountType.student,
)
AE_user = await create_user_with_groups([GroupType.AE], AccountType.student)

global section
global campaign_list
Expand Down
21 changes: 15 additions & 6 deletions tests/test_cdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pytest_mock import MockerFixture

from app.core import models_core
from app.core.groups.groups_type import GroupType
from app.core.groups.groups_type import AccountType, GroupType
from app.modules.cdr import models_cdr
from app.modules.cdr.types_cdr import (
CdrStatus,
Expand Down Expand Up @@ -71,21 +71,28 @@
async def init_objects():
global cdr_admin
cdr_admin = await create_user_with_groups(
[GroupType.student, GroupType.admin_cdr],
[GroupType.admin_cdr],
AccountType.student,
email="cdr_admin@etu.ec-lyon.fr",
)

global token_admin
token_admin = create_api_access_token(cdr_admin)

global cdr_bde
cdr_bde = await create_user_with_groups([GroupType.student, GroupType.BDE])
cdr_bde = await create_user_with_groups(
[GroupType.BDE],
AccountType.student,
)

global token_bde
token_bde = create_api_access_token(cdr_bde)

global cdr_user
cdr_user = await create_user_with_groups([GroupType.student])
cdr_user = await create_user_with_groups(
[],
AccountType.student,
)

global token_user
token_user = create_api_access_token(cdr_user)
Expand Down Expand Up @@ -238,7 +245,8 @@ async def init_objects():
await add_object_to_db(unused_curriculum)

cdr_user_with_curriculum_without_purchase = await create_user_with_groups(
[GroupType.student],
[],
AccountType.student,
)
curriculum_membership = models_cdr.CurriculumMembership(
user_id=cdr_user_with_curriculum_without_purchase.id,
Expand All @@ -249,7 +257,8 @@ async def init_objects():
global cdr_user_with_curriculum_with_non_validated_purchase
cdr_user_with_curriculum_with_non_validated_purchase = (
await create_user_with_groups(
[GroupType.student],
[],
AccountType.student,
)
)
curriculum_membership_for_user_with_curriculum_with_non_validated_purchase = (
Expand Down
18 changes: 13 additions & 5 deletions tests/test_cdr_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest_asyncio

from app.core import models_core
from app.core.groups.groups_type import GroupType
from app.core.groups.groups_type import AccountType, GroupType
from app.modules.cdr import models_cdr
from app.modules.cdr.utils_cdr import construct_dataframe_from_users_purchases
from tests.commons import (
Expand Down Expand Up @@ -53,7 +53,8 @@
async def init_objects():
global cdr_admin
cdr_admin = await create_user_with_groups(
[GroupType.student, GroupType.admin_cdr],
[GroupType.admin_cdr],
AccountType.student,
email="cdr_admin@etu.ec-lyon.fr",
)

Expand All @@ -62,7 +63,8 @@ async def init_objects():

global cdr_user1
cdr_user1 = await create_user_with_groups(
[GroupType.student],
[],
AccountType.student,
email="demo@demo.fr",
name="Demo",
firstname="Oui",
Expand All @@ -72,10 +74,16 @@ async def init_objects():
token_user = create_api_access_token(cdr_user1)

global cdr_user2
cdr_user2 = await create_user_with_groups([GroupType.student])
cdr_user2 = await create_user_with_groups(
[],
AccountType.student,
)

global cdr_user3
cdr_user3 = await create_user_with_groups([GroupType.student])
cdr_user3 = await create_user_with_groups(
[],
AccountType.student,
)

global seller1
seller1 = models_cdr.Seller(
Expand Down
7 changes: 5 additions & 2 deletions tests/test_cinema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fastapi.testclient import TestClient

from app.core import models_core
from app.core.groups.groups_type import GroupType
from app.core.groups.groups_type import AccountType, GroupType
from app.modules.cinema import models_cinema
from tests.commons import (
add_object_to_db,
Expand All @@ -29,7 +29,10 @@ async def init_objects() -> None:
token_cinema = create_api_access_token(cinema_user_cinema)

global cinema_user_simple
cinema_user_simple = await create_user_with_groups([GroupType.student])
cinema_user_simple = await create_user_with_groups(
[],
AccountType.student,
)

global token_simple
token_simple = create_api_access_token(cinema_user_simple)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def init_objects() -> None:
user_simple = await create_user_with_groups([GroupType.AE])
global token_simple
token_simple = create_api_access_token(user_simple)
module_visibility = models_core.ModuleVisibility(
module_visibility = models_core.ModuleGroupVisibility(
root=root,
allowed_group_id=group_id,
)
Expand Down Expand Up @@ -61,9 +61,9 @@ def test_add_module_visibility(client: TestClient) -> None:
assert response.status_code == 201


def test_delete_loaners(client: TestClient) -> None:
def test_delete_visibility(client: TestClient) -> None:
response = client.delete(
f"/module-visibility/{root}/{group_id}",
f"/module-visibility/{root}/groups/{group_id}",
headers={"Authorization": f"Bearer {token_admin}"},
)
assert response.status_code == 204
Expand Down
7 changes: 5 additions & 2 deletions tests/test_flappybird.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fastapi.testclient import TestClient

from app.core import models_core
from app.core.groups.groups_type import GroupType
from app.core.groups.groups_type import AccountType, GroupType
from app.modules.flappybird import models_flappybird
from tests.commons import (
add_object_to_db,
Expand All @@ -23,7 +23,10 @@
@pytest_asyncio.fixture(scope="module", autouse=True)
async def init_objects() -> None:
global user
user = await create_user_with_groups([GroupType.student])
user = await create_user_with_groups(
[],
AccountType.student,
)

global admin_user
admin_user = await create_user_with_groups([GroupType.admin])
Expand Down
Loading

0 comments on commit 2519b20

Please sign in to comment.