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

Commit

Permalink
fix: Add more project tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rsavoye committed Dec 26, 2023
1 parent 0215e45 commit 66a7881
Showing 1 changed file with 73 additions and 34 deletions.
107 changes: 73 additions & 34 deletions tests/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
# from tm_admin.users.users_proto import UsersMessage
#from tm_admin.yamlfile import YamlFile
from tm_admin.users.users import UsersDB
from tm_admin.tasks.tasks import TasksDB
from tm_admin.projects.projects import ProjectsDB
from tm_admin.types_tm import Mappinglevel
from tm_admin.types_tm import Userrole, Mappinglevel
from datetime import datetime
from tm_admin.users.users_class import UsersTable
from tm_admin.projects.projects_class import ProjectsTable
Expand All @@ -42,8 +43,10 @@
# FIXME: For now these tests assume you have a local postgres installed. One has the TM
# database, the other for tm_admin.

user = UsersDB('localhost/testdata')
project = ProjectsDB('localhost/testdata')
dbname = 'localhost/testdata'
user = UsersDB(dbname)
project = ProjectsDB(dbname)
task = TasksDB(dbname)

def get_project_by_id():
# project_id: int) -> Project:
Expand All @@ -64,37 +67,79 @@ def exists():
def get_project_by_name():
# project_id: int) -> Project:
log.debug(f"--- get_project_by_name() ---")
name = '262628 Nigeria'
name = 'Kigoma_13'
result = project.getByName(name)
assert len(result) > 0

def get_project_priority_areas():
# project_id):
log.debug(f"--- get_project_priority_areas() ---")
pid = 150
result = project.getColumn(pid, 'priority_areas')
assert len(result) > 0

def get_project_tasks():
# project_id):
log.debug(f"--- get_project_tasks() ---")
pid = 150
result = task.getByWhere(f" project_id={pid}")
# assert len(result) > 0

def get_project_aoi():
# project_id):
log.debug(f"--- get_project_aoi() ---")
pid = 150
result = project.getColumn(pid, 'geometry')
# FIXME: this should test the geometry to make
# sure it's valid
assert len(result) > 0

def is_user_permitted_to_validate():
# project_id, user_id):
log.debug(f"-- is_user_permitted_to_validate() ---")
id = 4606673
result = user.getColumn(id, 'role')
# FIXME: This only works if the user has the right role
# assert len(result) > 0 and result[0][0] == Userrole.VALIDATOR
assert len(result) > 0

def is_user_permitted_to_map():
# project_id, user_id):
log.debug(f"--- is_user_permitted_to_map() ---")
id = 4606673
result = user.getColumn(id, 'role')
# FIXME: This only works if the user has the right role
# assert len(result) > 0 and result[0][0] != Userrole.USER_READ_ONLY
assert len(result) > 0

def get_project_title():
# project_id: int, preferred_locale: str = "en") -> str:
log.debug(f"--- get_project_title() ---")
pid = 150
result = user.getColumn(pid, 'name')
assert len(result) > 0 and result[0][0][10] == 'Mozambique'

def favorite():
# project_id: int, user_id: int):
log.debug(f"favorite() unimplemented!")

def unfavorite():
# project_id: int, user_id: int):
log.debug(f"unfavorite() unimplemented!")

def auto_unlock_tasks():
# project_id: int):
log.debug(f"auto_unlock_tasks() unimplemented!")

def delete_tasks():
# project_id: int, tasks_ids):
# FIXME: this requires the Tasks and Task History tables
log.debug(f"delete_tasks() unimplemented!")

def get_contribs_by_day():
# project_id: int) -> ProjectContribsDTO:
log.debug(f"get_contribs_by_day() unimplemented!")

def get_project_dto_for_mapper():
log.debug(f"get_project_dto_for_mapper() unimplemented!")

def get_project_tasks():
#
log.debug(f"get_project_tasks() unimplemented!")

def get_project_aoi():
# project_id):
log.debug(f"get_project_aoi() unimplemented!")

def get_project_priority_areas():
# project_id):
log.debug(f"get_project_priority_areas() unimplemented!")

def get_task_for_logged_in_user():
# user_id: int):
log.debug(f"get_task_for_logged_in_user() unimplemented!")
Expand All @@ -103,24 +148,12 @@ def get_task_details_for_logged_in_user():
# user_id: int, preferred_locale: str):
log.debug(f"get_task_details_for_logged_in_user() unimplemented!")

def is_user_in_the_allowed_list():
# allowed_users: list, current_user_id: int):
log.debug(f"is_user_in_the_allowed_list() unimplemented!")

def evaluate_mapping_permission():
log.debug(f"evaluate_mapping_permission() unimplemented!")

def evaluate_validation_permission():
log.debug(f"evaluate_validation_permission() unimplemented!")

def is_user_permitted_to_validate():
# project_id, user_id):
log.debug(f") unimplemented!")

def is_user_permitted_to_map():
# project_id, user_id):
log.debug(f"is_user_permitted_to_map() unimplemented!")

def get_cached_project_summary():
log.debug(f"get_cached_project_summary() unimplemented!")

Expand Down Expand Up @@ -174,7 +207,13 @@ def get_project_organisation():
def send_email_on_project_progress():
# project_id):
log.debug(f"send_email_on_project_progress() unimplemented!")


# This one seems silly, and needs no database access
# def is_user_in_the_allowed_list():

# we use the UsersTable() to represent the table schema
# def get_project_dto_for_mapper():

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", nargs="?", const="0", help="verbose output")
Expand All @@ -199,13 +238,11 @@ def send_email_on_project_progress():
auto_unlock_tasks()
delete_tasks()
get_contribs_by_day()
get_project_dto_for_mapper()
get_project_tasks()
get_project_aoi()
get_project_priority_areas()
get_task_for_logged_in_user()
get_task_details_for_logged_in_user()
is_user_in_the_allowed_list()
evaluate_mapping_permission()
is_user_permitted_to_map()
#_is_user_intermediate_or_advanced()
Expand All @@ -225,3 +262,5 @@ def send_email_on_project_progress():
get_project_teams()
get_project_organisation()
send_email_on_project_progress()
# is_user_in_the_allowed_list()
# get_project_dto_for_mapper()

0 comments on commit 66a7881

Please sign in to comment.