-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
55 lines (36 loc) · 1.36 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
import pytest
from conf_tests import api, client
def test_basic_route(api):
@api.route("/home")
def home(req, resp):
resp.text = "YOLO"
def test_route_overlap_throws_exception(api):
@api.route("/home")
def home(req, resp):
resp.text = "YOLO"
with pytest.raises(AssertionError):
@api.route("/home")
def home2(req, resp):
resp.text = "YOLO"
def test_bumbo_test_client_can_send_requests(api, client):
RESPONSE_TEXT = "THIS IS COOL"
@api.route("/hey")
def cool(req, resp):
resp.text = RESPONSE_TEXT
assert client.get("http://testserver/hey").text == RESPONSE_TEXT
def test_parameterized_route(api, client):
@api.route("/{name}")
def hello(req, resp, name):
resp.text = f"hey {name}"
assert client.get("http://testserver/matthew").text == "hey matthew"
assert client.get("http://testserver/ashley").text == "hey ashley"
def test_default_404_response(client):
response = client.get("http://testserver/doesnotexist")
assert response.status_code == 404
assert response.text == "Not found."
def test_alternative_route(api, client):
response_text = "Alternative way to add a route"
def home(req, resp):
resp.text = response_text
api.add_route("/alternative", home)
assert client.get("http://testserver/alternative").text == response_text