From 4d5fcfc5681607fad5b14a22423a9729f8164265 Mon Sep 17 00:00:00 2001 From: Emma Date: Thu, 16 Jan 2025 16:11:18 +0000 Subject: [PATCH] add endpoint check to integration test --- tests/test_integration.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_integration.py b/tests/test_integration.py index 5e1a253..3e201a0 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -1,10 +1,34 @@ import os +import time +import requests from constellation import docker_util from src.grout_deploy.cli import main +base_url = "http://localhost:5000" + +def wait_for_web_app(poll_interval=0.2, max=5): + for i in range(0, round(max/poll_interval)): + status_code = None + try: + status_code = requests.get(base_url).status_code + except requests.exceptions.ConnectionError: + pass + if status_code == 200: + return + time.sleep(poll_interval) + raise Exception(f"Web app not available within max timeout of {max}s") + def test_start_and_stop_grout(): assert os.getenv("GITHUB_ACCESS_TOKEN") is not None, "GITHUB_ACCESS_TOKEN env var must be set to run integration test" main(["start", "grout", "--pull"]) assert docker_util.container_exists("grout") + + # check can access metadata endpoint + wait_for_web_app() + response = requests.get(f"{base_url}/metadata") + assert response.status_code == 200 + json = response.json() + assert json["data"]["datasets"]["tile"]["gadm41"]["levels"] == ["admin0", "admin1", "admin2"] + main(["stop"]) assert not docker_util.container_exists("grout") \ No newline at end of file