fastapi-dls/test/main.py

24 lines
548 B
Python
Raw Normal View History

2022-12-23 06:35:37 +00:00
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'