-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_app.py
31 lines (26 loc) · 995 Bytes
/
test_app.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
import pytest
from app import app
@pytest.fixture
def client():
"""Create a test client for Flask."""
app.testing = True
return app.test_client()
def test_home(client):
"""Test home route response."""
response = client.get("/")
assert response.status_code == 200
assert b"Welcome to the 2025 Fed Inflation Newscast Data API" in response.data
def test_add_numbers(client):
"""Test adding two numbers."""
response = client.get("/add?a=5&b=10")
assert response.status_code == 200
assert response.get_json()["sum"] == 15
def test_filter_valid_month(client):
"""Test filtering for a valid month (1 or 2)."""
response = client.get("/filter?month=1")
assert response.status_code == 200
assert isinstance(response.get_json(), list) # Expect list of records
def test_filter_invalid_month(client):
"""Test filtering for an invalid month (e.g., 5)."""
response = client.get("/filter?month=5")
assert response.status_code == 404