good luck
This commit is contained in:
44
tests/test_routes.py
Normal file
44
tests/test_routes.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import json
|
||||
|
||||
|
||||
class TestIndexRoute:
|
||||
def test_returns_200(self, flask_client):
|
||||
response = flask_client.get("/")
|
||||
assert response.status_code == 200
|
||||
|
||||
def test_returns_html(self, flask_client):
|
||||
response = flask_client.get("/")
|
||||
assert b"NHL Scoreboard" in response.data
|
||||
|
||||
|
||||
class TestScoreboardRoute:
|
||||
def test_returns_200(self, flask_client):
|
||||
response = flask_client.get("/scoreboard")
|
||||
assert response.status_code == 200
|
||||
|
||||
def test_returns_json_with_expected_keys(self, flask_client):
|
||||
response = flask_client.get("/scoreboard")
|
||||
data = json.loads(response.data)
|
||||
assert "live_games" in data
|
||||
assert "pre_games" in data
|
||||
assert "final_games" in data
|
||||
|
||||
def test_live_games_have_required_fields(self, flask_client):
|
||||
response = flask_client.get("/scoreboard")
|
||||
data = json.loads(response.data)
|
||||
if data["live_games"]:
|
||||
game = data["live_games"][0]
|
||||
assert "Home Team" in game
|
||||
assert "Away Team" in game
|
||||
assert "Home Score" in game
|
||||
assert "Away Score" in game
|
||||
assert "Game State" in game
|
||||
assert game["Game State"] == "LIVE"
|
||||
|
||||
def test_missing_file_returns_error(self, flask_client, monkeypatch):
|
||||
import app.routes as routes
|
||||
|
||||
monkeypatch.setattr(routes, "SCOREBOARD_DATA_FILE", "/nonexistent/path.json")
|
||||
response = flask_client.get("/scoreboard")
|
||||
data = json.loads(response.data)
|
||||
assert "error" in data
|
||||
Reference in New Issue
Block a user