Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
fix: Update to use Access.Roles
Browse files Browse the repository at this point in the history
  • Loading branch information
robsavoye committed Mar 26, 2024
1 parent f208abe commit 74f6a0f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 33 deletions.
7 changes: 4 additions & 3 deletions tests/test_orgs.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
11 changes: 6 additions & 5 deletions tests/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand Down
1 change: 1 addition & 0 deletions tests/test_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
51 changes: 27 additions & 24 deletions tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,6 +46,8 @@
import tm_admin
import test_tasks
import test_projects


# Instantiate logger
log = logging.getLogger(__name__)

Expand All @@ -60,7 +63,7 @@ async def create_users(uapi):
user = UsersTable(id = 1, username = "foobar", name = "foo",
city = "Someplace", email_address = "[email protected]",
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",
Expand Down Expand Up @@ -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 = "[email protected]",
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 = "[email protected]",
# 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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand All @@ -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() ---")
Expand All @@ -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() ---")
Expand Down Expand Up @@ -609,7 +612,7 @@ async def main():
await UsersStatisticsInterestsAPI()
await UsersStatisticsAllAPI()
await UsersTasksAPI()

# FMTM API tests
await get_user()
await get_user_by_username()
Expand Down

0 comments on commit 74f6a0f

Please sign in to comment.