-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenerated_tests copy.py
58 lines (50 loc) · 2.14 KB
/
generated_tests copy.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
import requests
import pytest
BASE_URL = os.getenv("TEST_API_URL", "http://localhost:8000")
def test_endpoint_with_max():
"""
main.py returns 200 if param == 'max' (and never checks auth).
"""
response = requests.get(f"{BASE_URL}/api/endpoint?param=max")
assert response.status_code == 200, f"Expected 200, got {response.status_code}"
assert response.json() == {"result": "success"}
def test_endpoint_with_min():
"""
main.py returns 200 if param == 'min'.
"""
response = requests.get(f"{BASE_URL}/api/endpoint?param=min")
assert response.status_code == 200, f"Expected 200, got {response.status_code}"
assert response.json() == {"result": "success"}
def test_endpoint_no_param_no_auth_header():
"""
If param != 'max'/'min' and no Authorization header, main.py returns 401.
"""
response = requests.get(f"{BASE_URL}/api/endpoint")
assert response.status_code == 401, f"Expected 401, got {response.status_code}"
def test_endpoint_invalid_api_key():
"""
If param != 'max'/'min' and header == 'Bearer invalid-api-key', main.py returns 403.
"""
headers = {"Authorization": "Bearer invalid-api-key"}
response = requests.get(f"{BASE_URL}/api/endpoint?param=something", headers=headers)
assert response.status_code == 403, f"Expected 403, got {response.status_code}"
def test_endpoint_random_auth_key():
"""
If param != 'max'/'min' and header != 'Bearer invalid-api-key', main.py returns 404.
"""
headers = {"Authorization": "Bearer some-random-key"}
response = requests.get(f"{BASE_URL}/api/endpoint?param=something", headers=headers)
assert response.status_code == 404, f"Expected 404, got {response.status_code}"
def test_nonexistent_endpoint():
"""
/api/nonexistent always returns 404.
"""
response = requests.get(f"{BASE_URL}/api/nonexistent")
assert response.status_code == 404, f"Expected 404, got {response.status_code}"
def test_error_endpoint():
"""
/api/error always returns 500.
"""
response = requests.get(f"{BASE_URL}/api/error")
assert response.status_code == 500, f"Expected 500, got {response.status_code}"