diff --git a/app/config.py b/app/config.py index bd6e655..002a3ea 100644 --- a/app/config.py +++ b/app/config.py @@ -5,6 +5,25 @@ BASEROW_PW = os.environ.get("BASEROW_PW") DATABASES = { + "test": + { + "db_name": "Test DB", + "db_id": "538", + "endpoints": { + "persons": { + "table_id": "3284", + "search_field_name": "name", + "search_field_id": "29742", + "id_field_name": "project_id" + }, + "places": { + "table_id": "3285", + "search_field_name": "name", + "search_field_id": "29745", + "id_field_name": "project_id" + } + } + }, "emt": { "db_name": "EMT", diff --git a/app/test_main.py b/app/test_main.py index f45e1ed..5bf0865 100644 --- a/app/test_main.py +++ b/app/test_main.py @@ -20,5 +20,32 @@ def test_read_main(): def test_correct_endpoint_number(): with TestClient(app) as client: response = client.get("/") - endpoints = response.json()['endpoints'] + endpoints = response.json()["endpoints"] assert len(endpoints) == len(DATABASES) + + +def test_ac_endpoint(): + db_id = "test" + endpoints = [key for key, _ in DATABASES[db_id]["endpoints"].items()] + for x in endpoints: + with TestClient(app) as client: + response = client.get(f"/ac/{db_id}/{x}") + assert response.status_code == 422 + response = client.get(f"/ac/{db_id}/{x}?q=A") + assert response.status_code == 200 + + +def test_nonexiting_ac_endpoint(): + with TestClient(app) as client: + response = client.get("/ac/quatsch/blödsinn?q=A") + assert response.status_code == 404 + + +def test_list_tables_endpoint(): + db_id = "test" + with TestClient(app) as client: + response = client.get(f"/db/{db_id}/tables") + assert response.status_code == 200 + with TestClient(app) as client: + response = client.get("/db/blödsinn/tables") + assert response.status_code == 404 diff --git a/run_tests.sh b/run_tests.sh index 15d2ca2..f3871c3 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,6 +1,7 @@ #/bin/bash -coverage run -m pytest -v +echo "Be aware that we are ignoring warnings, this might come back to you one day!" +coverage run -m pytest -v -p no:warnings coverage report coverage html xdg-open ./htmlcov/index.html \ No newline at end of file