test / tests /test_app.py
noranisa's picture
Create tests/test_app.py
8241523 verified
raw
history blame contribute delete
853 Bytes
import pytest
from app import app
@pytest.fixture
def client():
app.config.update({"TESTING": True})
with app.test_client() as client:
yield client
def test_index_page(client):
resp = client.get("/")
assert resp.status_code == 200
assert b"Komoditas logam" in resp.data
def test_predict_invalid(client):
resp = client.post("/predict", data={"commodity": "unknownmetal"}, follow_redirects=True)
assert resp.status_code == 200
# Should flash an error message in Indonesian
assert b"Tidak menemukan simbol" in resp.data or b"Data historis" in resp.data
# Ensure templates only use ASCII in titles
import re
def test_ascii_titles():
with open("templates/base.html", "r", encoding="utf-8") as f:
html = f.read()
# Ensure no bullet character
assert "\u2022" not in html
# ======================= end tests/test_app.py ===============================