-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_web.py
54 lines (42 loc) ยท 1.47 KB
/
test_web.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
import json
import pytest
from bs4 import BeautifulSoup
from main import app
@pytest.fixture
def client():
"""Create a test client for the app"""
app.config["TESTING"] = True
with app.test_client() as client:
yield client
def test_home_route(client):
"""Test that the home route returns 200"""
response = client.get("/next")
assert response.status_code == 200
def test_action_route_detailed(client):
"""Test the action route with detailed HTML parsing"""
test_data = {
"update": json.dumps(
{
"action": "update",
"gameId": "abcdef",
"homeTeam": "ืืืื ืืืคื",
"guestTeam": "ืืคืืขื ืืืคื",
"specsWord": "ืืื ืื ื",
"specsNumber": "15000",
"poll": "off",
"notes": "",
}
)
}
response = client.post("/action", data=test_data)
assert response.status_code == 200
# Parse the HTML
soup = BeautifulSoup(response.data, "html.parser")
# Check for the form
form = soup.find("form", id="updateForm")
assert form is not None
assert form["action"] == "/update"
# Check for specific input values
assert soup.find("input", {"name": "game_id"})["value"] == "abcdef"
assert soup.find("input", {"name": "home_team"})["value"] == "ืืืื ืืืคื"
assert soup.find("input", {"name": "guest_team"})["value"] == "ืืคืืขื ืืืคื"