noranisa commited on
Commit
8241523
·
verified ·
1 Parent(s): e3032d2

Create tests/test_app.py

Browse files
Files changed (1) hide show
  1. tests/test_app.py +34 -0
tests/test_app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+ from app import app
3
+
4
+
5
+ @pytest.fixture
6
+ def client():
7
+ app.config.update({"TESTING": True})
8
+ with app.test_client() as client:
9
+ yield client
10
+
11
+
12
+ def test_index_page(client):
13
+ resp = client.get("/")
14
+ assert resp.status_code == 200
15
+ assert b"Komoditas logam" in resp.data
16
+
17
+
18
+ def test_predict_invalid(client):
19
+ resp = client.post("/predict", data={"commodity": "unknownmetal"}, follow_redirects=True)
20
+ assert resp.status_code == 200
21
+ # Should flash an error message in Indonesian
22
+ assert b"Tidak menemukan simbol" in resp.data or b"Data historis" in resp.data
23
+
24
+
25
+ # Ensure templates only use ASCII in titles
26
+ import re
27
+
28
+
29
+ def test_ascii_titles():
30
+ with open("templates/base.html", "r", encoding="utf-8") as f:
31
+ html = f.read()
32
+ # Ensure no bullet character
33
+ assert "\u2022" not in html
34
+ # ======================= end tests/test_app.py ===============================