Skip to content

Commit

Permalink
Testing with pytest, router/app package tests, work in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmdocua committed Sep 28, 2023
1 parent 95a9a8b commit 79752aa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
29 changes: 28 additions & 1 deletion repromon_app/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
import threading

import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient

from repromon_app.config import app_config, app_config_init
from repromon_app.config import app_config, app_config_init, app_settings
from repromon_app.db import db_init
from repromon_app.service import SecSysService
from repromon_app.srv import create_fastapi_app

logger = logging.getLogger(__name__)

_apikey_tester1: str = None
_apikey_tester2: str = None
_apikey_tester3: str = None

_fastapi_app: FastAPI = None
_test_client: TestClient = None


@pytest.fixture(scope="session", autouse=True)
def init_config():
Expand Down Expand Up @@ -51,3 +57,24 @@ def apikey_tester2() -> str:
def apikey_tester3() -> str:
global _apikey_tester3
return _apikey_tester3


@pytest.fixture
def base_url() -> str:
return f"https://{app_settings().WEB_HOST}:{str(app_settings().WEB_PORT)}"


@pytest.fixture
def fastapi_app() -> FastAPI:
global _fastapi_app
if not _fastapi_app:
_fastapi_app = create_fastapi_app()
return _fastapi_app


@pytest.fixture
def test_client(fastapi_app) -> str:
global _test_client
if not _test_client:
_test_client = TestClient(fastapi_app)
return _test_client
13 changes: 13 additions & 0 deletions repromon_app/tests/router/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import logging

from fastapi.testclient import TestClient

logger = logging.getLogger(__name__)
logger.debug(f"name={__name__}")


def test_app_root(test_client: TestClient):
logger.debug("test_app_root()")
response = test_client.get("/")
assert response.status_code == 200
assert "ReproMon Home" in response.text

0 comments on commit 79752aa

Please sign in to comment.