From 811313d1ef7bdcf51d3885116d6e641e25e75afd Mon Sep 17 00:00:00 2001 From: WorldTeacher Date: Tue, 25 Nov 2025 09:59:24 +0100 Subject: [PATCH] fix: add uvicorn dependency feat: add test_api file --- .gitea/workflows/test_pr.yml | 34 ++++++++++++++++++---------------- pyproject.toml | 6 +++++- test_api.py | 8 ++++++++ 3 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 test_api.py diff --git a/.gitea/workflows/test_pr.yml b/.gitea/workflows/test_pr.yml index a762f0b..ee459ef 100644 --- a/.gitea/workflows/test_pr.yml +++ b/.gitea/workflows/test_pr.yml @@ -46,26 +46,28 @@ jobs: # show container status to aid debugging docker ps -a --filter name=semapform-test || true - # perform an in-container GET request (endpoint is a GET) and print attempts/logs - docker exec semapform-test python - << 'PY' + # perform a readiness loop and then run the repo test script to exercise the API + docker exec semapform-test python - << 'PY' import time, urllib.request, sys - url = 'http://127.0.0.1:8001/api/validate-signature?signature=ST%20250%20U42%20%2815%29' + url = 'http://127.0.0.1:8001/health' for i in range(20): - try: - with urllib.request.urlopen(url, timeout=3) as r: - print('attempt', i, 'status', r.status) - print(r.read().decode()) - if 200 <= r.status < 300: - sys.exit(0) - except Exception as e: - print('attempt', i, 'failed:', e) - time.sleep(1) - print('failed') + try: + with urllib.request.urlopen(url, timeout=2) as r: + print('ready', i, 'status', r.status) + if 200 <= r.status < 300: + sys.exit(0) + except Exception as e: + print('ready attempt', i, 'failed:', e) + time.sleep(1) + print('service did not become ready') sys.exit(1) - PY + PY - # dump the last 200 lines of logs so this step has visible output - docker logs semapform-test --tail 200 || true + # Run the repository smoke-test script inside the container and surface its output + docker exec semapform-test python test_api.py || true + + # dump the last 200 lines of logs so this step always displays useful output + docker logs semapform-test --tail 200 || true - name: Cleanup container if: always() diff --git a/pyproject.toml b/pyproject.toml index 04d13ea..5bbe282 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,11 @@ version = "0.1.0" description = "Add your description here" readme = "README.md" requires-python = ">=3.13" -dependencies = ["bibapi>=0.0.5", "fastapi>=0.122.0"] +dependencies = [ + "bibapi>=0.0.5", + "fastapi>=0.122.0", + "uvicorn>=0.38.0", +] [[tool.uv.index]] name = "gitea" url = "https://git.theprivateserver.de/api/packages/PHB/pypi/simple/" diff --git a/test_api.py b/test_api.py new file mode 100644 index 0000000..bec1e82 --- /dev/null +++ b/test_api.py @@ -0,0 +1,8 @@ +# test api endpoint with a signature, print the response +import urllib.request + +response = urllib.request.urlopen( + "http://localhost:8001/api/validate-signature?signature=ST%20250%20U42%20%2815%29", +) + +print(response.read().decode("utf-8"))