generated from pamelafox/simple-fastapi-azure-function
-
Notifications
You must be signed in to change notification settings - Fork 18
/
test_env.py
34 lines (24 loc) · 917 Bytes
/
test_env.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import random
import pytest
from fastapi.testclient import TestClient
from api.fastapi_app import create_app
@pytest.fixture
def mock_functions_env(monkeypatch):
monkeypatch.setenv("RUNNING_IN_PRODUCTION", "true")
def test_functions_env(mock_functions_env):
random.seed(1)
client = TestClient(create_app())
response = client.get("/generate_name")
assert response.status_code == 200
assert response.json() == {"name": "Margaret"}
def test_functions_openapi(mock_functions_env):
client = TestClient(create_app())
response = client.get("/openapi.json")
assert response.status_code == 200
body = response.json()
assert body["servers"][0]["url"] == "/api"
def test_functions_docs(mock_functions_env):
client = TestClient(create_app())
response = client.get("/docs")
assert response.status_code == 200
assert b"/public/openapi.json" in response.content