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

Commit

Permalink
fix: Add Makefile target check, minor updates to get a clean test run
Browse files Browse the repository at this point in the history
  • Loading branch information
rsavoye committed Feb 26, 2024
1 parent 5588149 commit 167e0b4
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 17 deletions.
5 changes: 5 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ NAME := tm-admin
VERSION := 0.1.0

SQL := $(wildcard *.sql)
TESTS := $(wildcard test_*.py)

# Developer only! This requires a Tasking Manager database running on your local machine.
# This is used to update the test data if any changes to the TM database schema are made.
Expand Down Expand Up @@ -56,4 +57,8 @@ import:
psql -d testdata -f $${i}; \
done

check:
for test in $(TESTS); do \
./$${test}; \
done
force:
4 changes: 2 additions & 2 deletions tests/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ async def main():
stream=sys.stdout,
)

user.connect(args.uri)
msg.connect(args.uri)
await user.connect(args.uri)
await msg.connect(args.uri)

await send_welcome_message()
await send_message_after_validation()
Expand Down
31 changes: 22 additions & 9 deletions tests/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from tm_admin.types_tm import Userrole, Mappinglevel
from datetime import datetime
from tm_admin.users.users_class import UsersTable
import asyncio
from codetiming import Timer

# Instantiate logger
log = logging.getLogger(__name__)
Expand All @@ -41,20 +43,19 @@
# FIXME: For now these tests assume you have a local postgres installed. One has the TM
# database, the other for tm_admin.

dbname = os.getenv("TMDB", default="localhost/testdata")
user = UsersDB(dbname)
project = ProjectsDB(dbname)
task = TasksDB(dbname)
# user = UsersDB()
# project = ProjectsDB()
# task = TasksDB()

def update():
async def update():
# user_id: int):
log.debug(f"--- update() unimplemented!")

def get_unread_message_count():
async def get_unread_message_count():
# user_id: int):
log.debug(f"--- get_unread_message_count() unimplemented!")

if __name__ == "__main__":
async def main():
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", nargs="?", const="0", help="verbose output")
parser.add_argument("-u", "--uri", default='localhost/tm_admin', help="Database URI")
Expand All @@ -72,5 +73,17 @@ def get_unread_message_count():
stream=sys.stdout,
)

update()
get_unread_message_count()
# user = UsersDB()
# project = ProjectsDB()
# task = TasksDB()

await update()
await get_unread_message_count()


if __name__ == "__main__":
"""This is just a hook so this file can be run standalone during development."""
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(main())

76 changes: 76 additions & 0 deletions tests/test_stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/python3

# Copyright (c) 2022, 2023 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
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

# Humanitarian OpenStreetmap Team
# 1100 13th Street NW Suite 800 Washington, D.C. 20005
# <[email protected]>

import argparse
import logging
import sys
import os
from sys import argv
# from tm_admin.organizations.organizations_proto import OrganizationsMessage
#from tm_admin.yamlfile import YamlFile
from tm_admin.organizations.organizations import OrganizationsDB
from tm_admin.types_tm import Organizationtype, Mappinglevel
from datetime import datetime
from tm_admin.teams.teams import TeamsDB

# Instantiate logger
log = logging.getLogger(__name__)

import tm_admin as tma
rootdir = tma.__path__[0]

# average mapping time per task
# average validation ti8me per task
# Estimated time to finish mapping
# Estimated time to finish validation
# mappers per project
# validators per project
# total contributors
# users by level

## task Status
# tasks locked for validation
# finished tasks
# ready for validation
# available for mapping
# locked for mapping
# more mapping needed


# FIXME: For now these tests assume you have a local postgres installed

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", nargs="?", const="0", help="verbose output")
parser.add_argument("-u", "--uri", default='localhost/tm_admin', help="Database URI")
args = parser.parse_args()
# if verbose, dump to the terminal.
log_level = os.getenv("LOG_LEVEL", default="INFO")
if args.verbose is not None:
log_level = logging.DEBUG

logging.basicConfig(
level=log_level,
format=("%(asctime)s.%(msecs)03d [%(levelname)s] " "%(name)s | %(funcName)s:%(lineno)d | %(message)s"),
datefmt="%y-%m-%d %H:%M:%S",
stream=sys.stdout,
)

11 changes: 7 additions & 4 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@
from tm_admin.types_tm import Userrole, Mappinglevel
from datetime import datetime
from tm_admin.users.users_class import UsersTable
from tm_admin.tasks.api import TasksAPI

# Instantiate logger
log = logging.getLogger(__name__)

import tm_admin as tma
rootdir = tma.__path__[0]

dbname = os.getenv("TMDB", default="localhost/testdata")
user = UsersDB(dbname)
project = ProjectsDB(dbname)
task = TasksDB(dbname)
task = TasksAPI()

# FIXME: For now these tests assume you have a local postgres installed. One has the TM
# database, the other for tm_admin.
Expand Down Expand Up @@ -185,6 +183,11 @@ def edit_task_boundary():
stream=sys.stdout,
)

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

get_task()
get_task_as_dto()
_is_task_undoable()
Expand Down
1 change: 0 additions & 1 deletion tests/test_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

dbname = os.getenv("TMDB", default="localhost/testdata")
teams = TeamsAPI()
teams.connect("localhost/tm_admin")

async def get_team_by_id():
log.debug(f"get_team_by_id() unimplemented!")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ async def register_user():
# osm_id, username, changeset_count, picture_url, email
# The id is generated by postgres, so we don't supply it.
ut = UsersTable(username='foobar', name='barfoo', picture_url='URI', email_address="[email protected]", mapping_level='INTERMEDIATE', role='VALIDATOR')
new = user.createTable(ut)
# new = user.createTable(ut)
entry = await user.getByName(ut.data['name'])
# assert entry['id'] > 0

Expand Down

0 comments on commit 167e0b4

Please sign in to comment.