From 3f5e3b16c590364923114d822a0bd3003bfd7fcd Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Fri, 23 Dec 2022 07:35:37 +0100 Subject: [PATCH] added api tests --- .gitlab-ci.yml | 6 +++++- test/main.py | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/main.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c24c913..70b8e02 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,9 +16,13 @@ build: - docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}/${CI_BUILD_REF_NAME}:${CI_BUILD_REF} test: + image: python:3.10-alpine stage: test + before_script: + - pip install pytest httpx + - cd test script: - - echo "Nothing to do ..." + - pytest main.py deploy: stage: deploy diff --git a/test/main.py b/test/main.py new file mode 100644 index 0000000..d28d1a4 --- /dev/null +++ b/test/main.py @@ -0,0 +1,23 @@ +from starlette.testclient import TestClient +import importlib.util +import sys + +MODULE, PATH = 'main.app', '../app/main.py' + +spec = importlib.util.spec_from_file_location(MODULE, PATH) +main = importlib.util.module_from_spec(spec) +sys.modules[MODULE] = main +spec.loader.exec_module(main) + +client = TestClient(main.app) + + +def test_index(): + response = client.get('/') + assert response.status_code == 200 + + +def test_status(): + response = client.get('/status') + assert response.status_code == 200 + assert response.json()['status'] == 'up'