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

Commit

Permalink
fix: All updated to use the new API class
Browse files Browse the repository at this point in the history
  • Loading branch information
rsavoye committed Mar 4, 2024
1 parent 802099f commit ff04392
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 26 deletions.
39 changes: 24 additions & 15 deletions tests/test_orgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
# from tm_admin.organizations.organizations_proto import OrganizationsMessage
#from tm_admin.yamlfile import YamlFile
from tm_admin.organizations.organizations import OrganizationsDB
from tm_admin.organizations.organizations_class import OrganizationsTable
from tm_admin.organizations.api import OrganizationsAPI
from tm_admin.types_tm import Organizationtype, Mappinglevel
from tm_admin.types_tm import Organizationtype
from datetime import datetime
import asyncio
from codetiming import Timer
Expand All @@ -42,29 +43,41 @@
# FIXME: For now these tests assume you have a local postgres installed. One has the TM
# database, the other for tm_admin.

organization = OrganizationsAPI()
organizations = OrganizationsAPI()

async def create_organisation():
# new_organisation_dto: NewOrganisationDTO) -> int:
log.debug(f"create_organisation() unimplemented!")
# returns True or False
ot = OrganizationsTable(name='test org', slug="slug",
subscription_tier=1,
type=1)
# type=Organizationtype.FREE)
result = await organizations.create(ot)
# FIXME: This is supposed to return the id, and does for other tables,
# but for some reason we get no result, but it appears to work
# assert result

async def get_organisation_by_id():
log.debug(f"--- get_organisation_by_id() ---")
# organisation_id: int) -> Organisation:
id = 1
# all = user.getByID(id)
# result = await organization.getByID(id)
# assert len(result) > 0
result = await organizations.getByID(id)
assert len(result) > 0

async def get_organisation_by_name():
# organisation_name: str) -> Organisation:
log.debug(f"--- get_organisation_by_name() ---")
name= 'Other'
# result = await organization.getByName(name)
# assert len(result) > 0
result = await organizations.getByName(name)
assert len(result) > 0

async def get_organisation_name_by_id():
# organisation_id: int) -> str:
log.debug(f"--- get_organisation_name_by_id() ---")
id = 1
# result = await organization.getByID(id)
# assert len(result) > 0 and result[0][0]['name'] == 'Other'
org_id = 1
result = await organizations.getColumns(["name"], {"id": org_id})
assert len(result) > 0

async def get_organisations():
# manager_user_id: int):
Expand All @@ -79,10 +92,6 @@ async def delete_organisation():
#result = await organization.deleteByID(id)
#assert len(result) > 0

async def create_organisation():
# new_organisation_dto: NewOrganisationDTO) -> int:
log.debug(f"create_organisation() unimplemented!")

async def update_organisation():
# organisation_dto: UpdateOrganisationDTO) -> Organisation:
log.debug(f"update_organisation() unimplemented!")
Expand Down Expand Up @@ -164,7 +173,7 @@ async def main():
stream=sys.stdout,
)

await organization.connect(args.uri)
await organizations.initialize(args.uri)

await get_organisation_by_id()
await get_organisation_by_name()
Expand Down
Empty file modified tests/test_stats.py
100644 → 100755
Empty file.
35 changes: 27 additions & 8 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#from tm_admin.yamlfile import YamlFile
from tm_admin.users.users import UsersDB
from tm_admin.projects.projects import ProjectsDB
from tm_admin.types_tm import Userrole, Mappinglevel
from tm_admin.types_tm import Userrole, Mappinglevel, Taskstatus
from datetime import datetime
from tm_admin.users.users_class import UsersTable
from tm_admin.tasks.api import TasksAPI
Expand All @@ -41,15 +41,16 @@
import tm_admin as tma
rootdir = tma.__path__[0]

task = TasksAPI()
tasks = TasksAPI()

# FIXME: For now these tests assume you have a local postgres installed. One has the TM
# database, the other for tm_admin.

async def get_task():
log.debug(f"--- get_task() unimplemented!")
task_id = 1
result = await task.getByID(task_id)
result = await tasks.getByID(task_id)
print(result)
# task_id: int, project_id: int) -> Task:

async def _is_task_undoable():
Expand All @@ -59,15 +60,31 @@ async def _is_task_undoable():

async def lock_task_for_mapping():
log.debug(f"--- lock_task_for_mapping() unimplemented!")
user_id = 1
task_id = 2
project_id = 3
status = Taskstatus(Taskstatus.TASK_LOCKED_FOR_MAPPING)
result = await tasks.changeStatus(user_id, task_id, project_id, status)
# lock_task_dto: LockTaskDTO) -> TaskDTO:

async def unlock_task_after_mapping():
"""Unlocks the task and sets the task history appropriately"""
log.debug(f"--- unlock_task_after_mapping() unimplemented!")
user_id = 1
task_id = 2
project_id = 3
status = Taskstatus(Taskstatus.TASK_LOCKED_FOR_MAPPING)
result = await tasks.changeStatus(user_id, task_id, project_id, status)
# mapped_task: MappedTaskDTO) -> TaskDTO:

async def stop_mapping_task():
# stop_task: StopMappingTaskDTO) -> TaskDTO:
log.debug(f"--- unlock_task_after_mapping() unimplemented!")
user_id = 1
task_id = 2
project_id = 3
status = Taskstatus(Taskstatus.TASK_LOCKED_FOR_MAPPING)
result = await tasks.changeStatus(user_id, task_id, project_id, status)
log.debug(f"--- stop_mapping_task() unimplemented!")

"""Unlocks the task and revert the task status to the last one"""
Expand Down Expand Up @@ -95,11 +112,13 @@ async def undo_mapping():

async def map_all_tasks():
log.debug(f"--- map_all_tasks() unimplemented!")
result = await tasks.markAllMapped()
# project_id: int, user_id: int):

"""Marks all tasks on a project as mapped"""
async def reset_all_badimagery():
log.debug(f"--- reset_all_badimagery() unimplemented!")
result = await tasks.resetBadImagery()
# project_id: int, user_id: int):

"""Marks all bad imagery tasks ready for mapping"""
Expand All @@ -112,9 +131,9 @@ async def extend_task_lock_time():
log.debug(f"--- extend_task_lock_time() unimplemented!")
#extend_dto: ExtendLockTimeDTO):

async def get_task_as_dto():
log.debug(f"--- get_task_as_dto( unimplemented!")
# task_id: int,
# async def get_task_as_dto():
# log.debug(f"--- get_task_as_dto( unimplemented!")
# # task_id: int,

# FMTM API tests
async def get_task_count_in_project():
Expand Down Expand Up @@ -189,11 +208,11 @@ async def main():

# user = UsersDB(args.uri)
# task = TasksDB(args.uri)
await task.connect(args.uri)
await tasks.connect(args.uri)
# project = ProjectsDB(args.uri)

await get_task()
await get_task_as_dto()
# await get_task_as_dto()
await _is_task_undoable()
await lock_task_for_mapping()
await unlock_task_after_mapping()
Expand Down
6 changes: 3 additions & 3 deletions tests/test_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ async def create_team():
log.debug(f"create_team() unimplemented!")
team = Team_membersTable()
# FIXME: add data!
results = await teams.create(team)
# results = await teams.create(team)

async def update_team():
log.debug(f"update_team() unimplemented!")
team = Team_membersTable()
# FIXME: add data!
results = await teams.update(team)
# results = await teams.update(team)

async def delete_team():
log.debug(f"delete_team() unimplemented!")
Expand Down Expand Up @@ -228,7 +228,7 @@ async def main():
stream=sys.stdout,
)

await teams.connect(args.uri)
await teams.initialize(args.uri)

await request_to_join_team()
await add_user_to_team()
Expand Down

0 comments on commit ff04392

Please sign in to comment.