diff --git a/tests/test_orgs.py b/tests/test_orgs.py index 5740805..93959ee 100755 --- a/tests/test_orgs.py +++ b/tests/test_orgs.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 -# Copyright (c) 2022, 2023 Humanitarian OpenStreetMap Team +# Copyright (c) 2023, 2024 Humanitarian OpenStreetMap Team # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -28,7 +28,8 @@ #from tm_admin.yamlfile import YamlFile from tm_admin.organizations.organizations_class import OrganizationsTable from tm_admin.organizations.api import OrganizationsAPI -from tm_admin.types_tm import Organizationtype, Userrole +from tm_admin.types_tm import Organizationtype +from tm_admin.access import Roles from datetime import datetime import asyncio from codetiming import Timer @@ -109,7 +110,7 @@ async def can_user_manage_organisation(): user_id = 3 role = await users.getRole(user_id) # print(role) - assert role == Userrole.ORGANIZATION_ADMIN + assert role == Roles.ORGANIZATION_ADMIN async def is_user_an_org_manager(): # organisation_id: int, user_id: int): diff --git a/tests/test_projects.py b/tests/test_projects.py index ccc0ad8..0202207 100755 --- a/tests/test_projects.py +++ b/tests/test_projects.py @@ -26,10 +26,11 @@ from sys import argv # from tm_admin.users.users_proto import UsersMessage #from tm_admin.yamlfile import YamlFile -from tm_admin.types_tm import Userrole, Mappinglevel, Teamrole, Permissions +from tm_admin.types_tm import Roles, Mappinglevel, Permissions from datetime import datetime from tm_admin.users.users_class import UsersTable from tm_admin.projects.projects_class import ProjectsTable +from tm_admin.access import Roles import asyncio from codetiming import Timer from tm_admin.projects.api import ProjectsAPI @@ -77,10 +78,10 @@ async def create_projects(papi): organisation_id = 1) result = await papi.insertRecords([pt]) - role = Teamrole(Teamrole.TEAM_MAPPER) + role = Roles(Roles.MAPPER) teams = {"team_id": 1, "role": role} project_id = 1 - result = await papi.updateColumns({"teams": teams}, {"id": project_id}) + result = await papi.updateColumns({"members": teams}, {"id": project_id}) # Add some allowed users user_id = 1 @@ -117,7 +118,7 @@ async def get_team_role(): team_id = 1 result = await projects.getTeamRole(project_id, team_id) # print(result) - assert result == Teamrole.TEAM_MAPPER + assert result == Roles.MAPPER # These endpoint tests come from the TM backend async def get_project_by_id(): @@ -194,7 +195,7 @@ async def get_project_teams(): # project_id: int): log.debug(f"--- get_project_teams() ---") project_id = 1 - teams = await projects.getColumns(['teams'], {"id": project_id}) + teams = await projects.getColumns(['members'], {"id": project_id}) #teams = data[0]['teams'] assert len(teams) > 0 diff --git a/tests/test_tasks.py b/tests/test_tasks.py index 2dd6014..a1b5380 100755 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -34,6 +34,8 @@ from tm_admin.tasks.task_history_class import Task_historyTable from tm_admin.tasks.task_issues_class import Task_issuesTable from tm_admin.tasks.task_invalidation_history_class import Task_invalidation_historyTable +from tm_admin.access import Roles + import asyncio from codetiming import Timer import tm_admin @@ -219,7 +221,7 @@ async def undo_mapping(): async def map_all_tasks(): log.debug(f"--- map_all_tasks() unimplemented!") - result = await tasks.markAllMapped() + # result = await tasks.markAllMapped() # project_id: int, user_id: int): """Marks all tasks on a project as mapped""" diff --git a/tests/test_teams.py b/tests/test_teams.py index 3ff1832..15153cb 100755 --- a/tests/test_teams.py +++ b/tests/test_teams.py @@ -36,6 +36,7 @@ from codetiming import Timer from tm_admin.teams.team_members_class import Team_membersTable import tm_admin +from tm_admin.access import Roles # Instantiate logger log = logging.getLogger(__name__) diff --git a/tests/test_users.py b/tests/test_users.py index a0492bf..b5659b2 100755 --- a/tests/test_users.py +++ b/tests/test_users.py @@ -35,7 +35,8 @@ from sys import argv # from tm_admin.users.users_proto import UsersMessage #from tm_admin.yamlfile import YamlFile -from tm_admin.types_tm import Userrole, Mappinglevel +from tm_admin.types_tm import Mappinglevel +from tm_admin.access import Roles from datetime import datetime from tm_admin.users.users_class import UsersTable import asyncio @@ -45,6 +46,8 @@ import tm_admin import test_tasks import test_projects + + # Instantiate logger log = logging.getLogger(__name__) @@ -60,7 +63,7 @@ async def create_users(uapi): user = UsersTable(id = 1, username = "foobar", name = "foo", city = "Someplace", email_address = "fubr@gmail.com", is_email_verified = False, is_expert = False, - tasks_notifications = True, role = "USER_READ_ONLY", + tasks_notifications = True, role = "READ_ONLY", mapping_level = "BEGINNER", tasks_mapped = 0, tasks_validated = 0, tasks_invalidated = 0, date_registered = "2024-01-29T22:19:35.587016", @@ -125,22 +128,22 @@ async def create_users(uapi): ) result = await uapi.insertRecords([user]) - user = UsersTable(id = 5, username = "superbeing", name = "god", - city = "Someplace", email_address = "nogood@gmail.com", - is_email_verified = False, is_expert = False, - tasks_notifications = True, role = "SUPER_ADMIN", - mapping_level = "ADVANCED", tasks_mapped = 0, - tasks_validated = 0, tasks_invalidated = 0, - date_registered = "2024-01-29T22:19:35.587016", - last_validation_date = "2024-01-29T22:19:35.587018", - default_editor = "ID", gender = 1, - mentions_notifications = True, - projects_notifications = True, - projects_comments_notifications = False, - tasks_comments_notifications = False, - teams_announcement_notifications = True, - ) - result = await uapi.insertRecords([user]) + # user = UsersTable(id = 5, username = "superbeing", name = "god", + # city = "Someplace", email_address = "nogood@gmail.com", + # is_email_verified = False, is_expert = False, + # tasks_notifications = True, role = "SUPER_ADMIN", + # mapping_level = "ADVANCED", tasks_mapped = 0, + # tasks_validated = 0, tasks_invalidated = 0, + # date_registered = "2024-01-29T22:19:35.587016", + # last_validation_date = "2024-01-29T22:19:35.587018", + # default_editor = "ID", gender = 1, + # mentions_notifications = True, + # projects_notifications = True, + # projects_comments_notifications = False, + # tasks_comments_notifications = False, + # teams_announcement_notifications = True, + # ) + # result = await uapi.insertRecords([user]) user_id = 1 # We need mapped projects @@ -171,7 +174,7 @@ async def UsersAllAPI(): paged = False count = 20 username = "foo" - role = Userrole(Userrole.MAPPER) + role = Roles(Roles.MAPPER) level = Mappinglevel(Mappinglevel.BEGINNER) result = await users.getPagedUsers(paged, count, username, role, level) @@ -310,7 +313,7 @@ async def test_expert(): async def get_project_managers(): log.debug("--- get_project_managers() ---") - role = Userrole(Userrole.PROJECT_MANAGER) + role = Roles(Roles.PROJECT_MANAGER) result = await users.getColumns(['id'], {"role": role}) assert len(result) > 0 @@ -319,9 +322,9 @@ async def is_user_an_admin(): # first user is not an admin user_id = 1 noresult = await users.getRole(user_id) - user_id = 5 + user_id = 2 result = await users.getRole(user_id) - assert noresult == Userrole.USER_READ_ONLY and result == Userrole.SUPER_ADMIN + assert noresult == Roles.READ_ONLY and result == Roles.PROJECT_MANAGER async def is_user_validator(): log.debug("--- is_user_validator() ---") @@ -331,7 +334,7 @@ async def is_user_validator(): user_id = 4 # but this user is a validator result = await users.getRole(user_id) - assert noresult == Userrole.PROJECT_MANAGER and result == Userrole.VALIDATOR + assert noresult == Roles.PROJECT_MANAGER and result == Roles.VALIDATOR async def is_user_blocked(): log.debug("--- is_user_blocked() ---") @@ -609,7 +612,7 @@ async def main(): await UsersStatisticsInterestsAPI() await UsersStatisticsAllAPI() await UsersTasksAPI() - + # FMTM API tests await get_user() await get_user_by_username()