-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_app.py
61 lines (41 loc) · 1.6 KB
/
test_app.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
59
60
61
from streamlit.testing.v1 import AppTest
from example.utils import url_serde
def test_show_app_unauthenticated():
at = AppTest.from_file("app.py").run()
# TODO: no components for unauthenticated user, what else can we assert?
assert len(at.button) == 0
def test_show_app_authenticated():
at = AppTest.from_file("app.py")
at.session_state["logged_in"] = True
at.session_state["username"] = "John Doe"
at.run()
assert at.button[0].label == "Share"
assert at.button[1].label == "Log out"
def test_logout_button_click():
at = AppTest.from_file("app.py")
at.session_state["logged_in"] = True
at.session_state["username"] = "John Doe"
at.run()
at.button[1].click().run()
assert at.session_state["logged_in"] is False
assert at.session_state["username"] is None
def test_decode_valid_state():
at = AppTest.from_file("app.py")
at.query_params["s"] = url_serde.encode({"k1": "v1", "k2": "v2"})
at.run()
assert at.session_state["k1"] == "v1"
assert at.session_state["k2"] == "v2"
def test_decode_and_merge_valid_state():
at = AppTest.from_file("app.py")
at.session_state["k1"] = "v1"
at.session_state["k2"] = "v2"
at.query_params["s"] = url_serde.encode({"k2": "updated v2", "k3": "v3"})
at.run()
assert at.session_state["k1"] == "v1"
assert at.session_state["k2"] == "updated v2"
assert at.session_state["k3"] == "v3"
def test_decode_invalid_state():
at = AppTest.from_file("app.py")
at.query_params["s"] = "invalid state"
at.run()
assert at.exception[0].message == "pickle data was truncated"