-
Notifications
You must be signed in to change notification settings - Fork 336
/
Copy pathtests.py
77 lines (63 loc) · 1.89 KB
/
tests.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import re
import pytest
from dirty_equals import IsList, IsStr
from fastapi.testclient import TestClient
from . import app
@pytest.fixture
def client():
with TestClient(app) as test_client:
yield test_client
def test_index(client: TestClient):
r = client.get('/')
assert r.status_code == 200, r.text
assert r.text.startswith('<!doctype html>\n')
assert r.headers.get('content-type') == 'text/html; charset=utf-8'
def test_api_root(client: TestClient):
r = client.get('/api/')
assert r.status_code == 200
data = r.json()
assert data == [
{
'text': 'FastUI Demo',
'type': 'PageTitle',
},
{
'title': 'FastUI Demo',
'titleEvent': {'url': '/', 'type': 'go-to'},
'startLinks': IsList(length=5),
'endLinks': [],
'type': 'Navbar',
},
{
'components': [
{
'text': IsStr(regex='This site provides a demo of.*', regex_flags=re.DOTALL),
'type': 'Markdown',
},
],
'type': 'Page',
},
{
'extraText': 'FastUI Demo',
'links': IsList(length=3),
'type': 'Footer',
},
]
def get_menu_links():
"""
This is pretty cursory, we just go through the menu and load each page.
"""
with TestClient(app) as client:
r = client.get('/api/')
assert r.status_code == 200
data = r.json()
for link in data[1]['startLinks']:
url = link['onClick']['url']
yield pytest.param(f'/api{url}', id=url)
@pytest.mark.parametrize('url', get_menu_links())
def test_menu_links(client: TestClient, url: str):
r = client.get(url)
assert r.status_code == 200
data = r.json()
assert isinstance(data, list)
# TODO tests for forms, including submission