|
| 1 | +import pytest |
| 2 | + |
| 3 | +from country_workspace.models import Office, User, Program, UserRole |
| 4 | +from country_workspace.workspaces.forms import get_available_programs |
| 5 | +from testutils.factories import OfficeFactory, UserFactory, ProgramFactory, UserRoleFactory, SuperUserFactory |
| 6 | + |
| 7 | + |
| 8 | +@pytest.fixture |
| 9 | +def office() -> Office: |
| 10 | + return OfficeFactory() |
| 11 | + |
| 12 | + |
| 13 | +@pytest.fixture |
| 14 | +def program0(office: Office) -> Program: |
| 15 | + return ProgramFactory(country_office=office) |
| 16 | + |
| 17 | + |
| 18 | +@pytest.fixture |
| 19 | +def program1(office: Office) -> Program: |
| 20 | + return ProgramFactory(country_office=office) |
| 21 | + |
| 22 | + |
| 23 | +@pytest.fixture |
| 24 | +def all_programs(program0: Program, program1: Program) -> tuple[Program, ...]: |
| 25 | + return program0, program1 |
| 26 | + |
| 27 | + |
| 28 | +@pytest.fixture |
| 29 | +def user() -> User: |
| 30 | + return UserFactory() |
| 31 | + |
| 32 | + |
| 33 | +@pytest.fixture |
| 34 | +def single_program_role(office: Office, user: User, program0: Program) -> UserRole: |
| 35 | + return UserRoleFactory(user=user, country_office=office, program=program0) |
| 36 | + |
| 37 | + |
| 38 | +@pytest.fixture |
| 39 | +def none_program_role(office: Office, user: User) -> Program: |
| 40 | + return UserRoleFactory(country_office=office, user=user) |
| 41 | + |
| 42 | + |
| 43 | +@pytest.fixture |
| 44 | +def super_user() -> User: |
| 45 | + return SuperUserFactory() |
| 46 | + |
| 47 | + |
| 48 | +def test_no_roles(office: Office, all_programs: tuple[Program, ...], user: User) -> None: |
| 49 | + assert get_available_programs(office, user).count() == 0 |
| 50 | + |
| 51 | + |
| 52 | +def test_single_program_role( |
| 53 | + office: Office, all_programs: tuple[Program, ...], single_program_role: UserRole, user: User |
| 54 | +) -> None: |
| 55 | + assert get_available_programs(office, user).count() == 1 |
| 56 | + |
| 57 | + |
| 58 | +def test_none_program_role( |
| 59 | + office: Office, all_programs: tuple[Program, ...], none_program_role: Program, user: User |
| 60 | +) -> None: |
| 61 | + assert get_available_programs(office, user).count() == len(all_programs) |
| 62 | + |
| 63 | + |
| 64 | +def test_single_program_role_and_none_program_role( |
| 65 | + office: Office, |
| 66 | + all_programs: tuple[Program, ...], |
| 67 | + single_program_role: UserRole, |
| 68 | + none_program_role: UserRole, |
| 69 | + user: User, |
| 70 | +) -> None: |
| 71 | + assert get_available_programs(office, user).count() == 1 |
| 72 | + |
| 73 | + |
| 74 | +def test_super_user(office: Office, all_programs: tuple[Program, ...], program1: Program, super_user: User) -> None: |
| 75 | + assert get_available_programs(office, super_user).count() == len(all_programs) |
0 commit comments