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

Commit

Permalink
fix: Add test case for organizations table
Browse files Browse the repository at this point in the history
  • Loading branch information
rsavoye committed Dec 18, 2023
1 parent 863fa33 commit 677269d
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions tests/test_orgs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/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

# Instantiate logger
log = logging.getLogger(__name__)

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

# 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')

def test_all():
all = organization.getAll()
assert len(all) > 0

def test_by_id():
id = 100
all = organization.getByID(id)
assert len(all) > 0

def test_by_name():
name = 'Peace Corps'
all = organization.getByName(name)
assert len(all) > 0

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,
)

print("--- test_by_id() ---")
test_by_id()

print("--- test_by_name() ---")
test_by_name()

print("--- test_all() ---")
test_all()


0 comments on commit 677269d

Please sign in to comment.