-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtest_app.py
More file actions
36 lines (28 loc) · 1.05 KB
/
test_app.py
File metadata and controls
36 lines (28 loc) · 1.05 KB
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
35
36
import os
from fastapi.testclient import TestClient
import pytest
# Assuming your FastAPI code is in a file named `main.py`
from .main import app, get_env_message, get_secret_message
client = TestClient(app)
def test_home_view():
response = client.get("/")
assert response.status_code == 200
assert response.json() == {
"hello": "world",
"cron": "smooth-cronjob",
"watchtower": "working",
"env-message": get_env_message(),
"secret-message": get_secret_message(),
}
@pytest.fixture(autouse=True)
def clear_env_message(monkeypatch):
monkeypatch.delenv("SECRET_MESSAGE", raising=False)
monkeypatch.delenv("ENV_MESSAGE", raising=False)
def test_messages_set(monkeypatch):
monkeypatch.setenv("ENV_MESSAGE", "Test message")
monkeypatch.setenv("SECRET_MESSAGE", "Test secret message")
response = client.get("/")
assert response.status_code == 200
data = response.json()
assert data["env-message"] == "Test message"
assert data["secret-message"] == "Test secret message"