44 lines
934 B
Python
Executable File
44 lines
934 B
Python
Executable File
from fastapi import FastAPI, Response
|
|
import os
|
|
|
|
# For PyTest
|
|
from fastapi.testclient import TestClient
|
|
|
|
# Gebruik een omgevingsvariable. Tijdens het deployen van de applicatie kan
|
|
# deze worden meegegeven, bijvoorbeeld als configMap maar ook als 'fixed'value vanuit de
|
|
# deployment manifest.
|
|
name = os.getenv("HELLO_NAME", "unknown")
|
|
hostname = os.getenv("HOSTNAME")
|
|
version = os.getenv("PYTHON_VERSION")
|
|
|
|
api = FastAPI()
|
|
|
|
|
|
@api.get("/")
|
|
async def root():
|
|
return f"This is python version {version} in container {hostname}"
|
|
|
|
|
|
@api.get("/hello")
|
|
async def hello():
|
|
return f"Hello {name}!!!"
|
|
|
|
|
|
@api.get("/healthz")
|
|
async def healthz():
|
|
return "OK"
|
|
|
|
# PyTest section
|
|
client = TestClient(api)
|
|
|
|
|
|
def test_healthz():
|
|
response = client.get("/")
|
|
assert response.status_code == 200
|
|
# assert response.json() == {"msg": "OK"}
|
|
|
|
|
|
def test_hello():
|
|
response = client.get("/hello")
|
|
assert response.status_code == 200
|