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 test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
rsavoye committed Dec 26, 2023
1 parent b695cf1 commit 8a5fa1b
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 49 deletions.
Empty file modified tests/__init__.py
100644 → 100755
Empty file.
Empty file modified tests/conftest.py
100644 → 100755
Empty file.
18 changes: 14 additions & 4 deletions tests/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,28 @@
user = UsersDB('localhost/testdata')
project = ProjectsDB('localhost/testdata')


def get_project_by_id():
# project_id: int) -> Project:
log.debug(f"get_project_by_id() unimplemented!")
log.debug(f"--- get_project_by_id() ---")
id = 135
# all = user.getByID(id)
result = project.getByWhere(f" id='{id}'")
assert len(result) > 0

def exists():
# project_id: int) -> bool:
log.debug(f"exists() unimplemented!")
log.debug(f"--- exists() ---")
id = 1
# all = user.getByID(id)
result = project.getByID(id)
assert len(result) == 0

def get_project_by_name():
# project_id: int) -> Project:
log.debug(f"get_project_by_name() unimplemented!")
log.debug(f"--- get_project_by_name() ---")
name = '262628 Nigeria'
result = project.getByName(name)
# assert len(result) > 0

def auto_unlock_tasks():
# project_id: int):
Expand Down
22 changes: 13 additions & 9 deletions tests/test_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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__)
Expand All @@ -39,7 +40,18 @@
# FIXME: For now these tests assume you have a local postgres installed. One has the TM
# database, the other for tm_admin.

organization = OrganizationsDB('localhost/tm_admin')
team = TeamsDB('localhost/tm_admin')

def get_team_by_id():
log.debug(f"get_team_by_id() unimplemented!")
id = 1
# all = user.getByID(id)
result = team.getByWhere(f" id='{id}'")
# assert len(result) > 0

def get_team_by_name():
log.debug(f"get_team_by_name() unimplemented!")
# str) -> Tea

def request_to_join_team():
# team_id: int, user_id: int)
Expand Down Expand Up @@ -97,14 +109,6 @@ def change_team_role():
log.debug(f"change_team_role() unimplemented!")
# int, project_id: int, role: str

def get_team_by_id():
log.debug(f"get_team_by_id() unimplemented!")
# team_id: int) -> Tea

def get_team_by_name():
log.debug(f"get_team_by_name() unimplemented!")
# str) -> Tea

def create_team():
log.debug(f"create_team() unimplemented!")
# -> in
Expand Down
97 changes: 61 additions & 36 deletions tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def is_user_blocked():
assert result['role'] != Userrole.USER_READ_ONLY

def get_mapped_projects():
"""Gets all projects a user has mapped or validated on"""
log.debug("--- get_mapped_projects() ---")
# user_name: str, preferred_locale: str
id = 4606673
Expand All @@ -189,6 +190,7 @@ def update_user():

# FIXME: I'm not really sure of the difference of these two internal API functions.
def register_user():
"""Creates user in DB"""
log.debug("--- update_user() ---")
# osm_id, username, changeset_count, picture_url, email
# The id is generated by postgres, so we don't supply it.
Expand All @@ -198,6 +200,7 @@ def register_user():
assert entry['id'] > 0

def register_user_with_email():
"""Validate that user is not within the general users table."""
log.debug("--- register_user_with_email() ---")
# osm_id, username, changeset_count, picture_url, email
# The id is generated by postgres, so we don't supply it.
Expand All @@ -207,66 +210,98 @@ def register_user_with_email():
assert entry['id'] > 0

def has_user_accepted_license():
"""Checks if user has accepted specified license"""
# user_id: int, license_id: int
log.debug("--- has_user_accepted_license() ---")
id = 4606673
id = 4606673
result = user.getByID(id)
assert result['id'] == id

def get_interests():
log.debug(f"--- get_interests() ---")
id = 4606673
result = user.getColumn(id, 'interests')
assert len(result) > 0

def get_projects_favorited():
# user_id: int
log.debug(f"get_projects_favorited() unimplemented!")
log.debug(f"--- get_projects_favorited() ---")
id = 4606673
result = user.getColumn(id, 'favorite_projects')
# assert len(result) > 0

def accept_license_terms():
"""Saves the fact user has accepted license terms"""
# user_id: int, license_id: int
log.debug(f"accept_license_terms() unimplemented!")
log.debug(f"--- accept_license_terms() ---")
id = 4606673
result = user.updateColumn(id, {'licenses': {1}})
assert result

def get_interests():
log.debug(f"get_interests() unimplemented!")
def get_general_admins():
"""Get all users that are ADMIN"""
log.debug(f"--- get_general_admins() ---")
result = user.getByWhere(f" role='ADMIN'")
# FIXME: there are no ADMINs yet in the test data
# assert len(result) > 0

def filter_users():
"""Gets paginated list of users, filtered by username, for autocomplete"""
# FIXME: this should probably be in test_projects.py
log.debug(f"--- filter_users() ---")
# username: str, project_id: int, page: int
pid = 135
result = project.getByWhere(f" id={pid}")
assert len(result) > 0

def upsert_mapped_projects():
"""Add project to mapped projects if it doesn't exist, otherwise return"""
# user_id: int, project_id: int
log.debug(f"--- upsert_mapped_projects() ---")
uid = 4606673
pid = 135
# FIXME: for now appendColumn adds a single entry to an existing array
result = user.appendColumn(uid, {'projects_mapped': pid})
assert result

def update_user_details():
# user_id: int, db: UsersDB
log.debug(f"update_user_details() unimplemented!")

def get_interests_stats():
"""Get all projects that the user has contributed."""
# FIXME: this uses task history
# user_id
log.debug(f"get_interests_stats() unimplemented!")

def get_detailed_stats():
# FIXME: this uses task history
# username: str
log.debug(f"get_detailed_stats() unimplemented!")

def update_user_details():
# user_id: int, db: UsersDB
log.debug(f"update_user_details() unimplemented!")

def filter_users():
# username: str, project_id: int, page: int
log.debug(f"filter_users() unimplemented!")

def is_user_the_project_author():
# user_id: int, author_id: int
log.debug(f"is_user_the_project_author() unimplemented!")

def get_countries_contributed():
# FIXME: this uses task history
# user_id: int
log.debug(f"get_countries_contributed() unimplemented!")

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

def get_contributions_by_day():
# The TM source says "Validate that user exists",
# FIXME: this uses task history
# user_id: int
log.debug(f"get_contributions_by_day() unimplemented!")

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

def get_recommended_projects():
"""Gets all projects a user has mapped or validated on"""
# user_name: str, preferred_locale: str
# Get all projects that the user has contributed
# Get all campaigns for all contributed projects.
# Get projects with given campaign tags but without user contributions.
# Get only user mapping level projects.
log.debug(f"get_recommended_projects() unimplemented!")


# This one seems silly, and needs no database access
# def is_user_the_project_author(user_id: int, author_id: int)

# These both require accessing the OSM server, which we're not going to do yet.
# def get_osm_details_for_user(username: str)
# def notify_level_upgrade(user_id: int, username: str, level: str)
Expand Down Expand Up @@ -299,25 +334,15 @@ def get_recommended_projects():
# get_user_dto_by_username()
# get_user_dto_by_id()
test_by_id()

test_by_name()

test_role()

set_user_mapping_level()

test_expert()

test_registered()

get_project_managers()

get_mapping_level()

is_user_an_admin()

is_user_validator()

get_contributions_by_day()
get_project_managers()
get_general_admins()
Expand All @@ -329,7 +354,6 @@ def get_recommended_projects():
get_detailed_stats()
update_user_details()
filter_users()
is_user_the_project_author()
is_user_blocked()
get_countries_contributed()
upsert_mapped_projects()
Expand All @@ -341,6 +365,7 @@ def get_recommended_projects():
check_and_update_mapper_level()
register_user_with_email()
get_interests()
# is_user_the_project_author()
# get_osm_details_for_user() # Not part of this API
# notify_level_upgrade() # Not part of this API

Expand Down

0 comments on commit 8a5fa1b

Please sign in to comment.