1
+ import pytest
2
+ from server import app
3
+ import html
4
+
5
+ @pytest .fixture
6
+ def client ():
7
+ return app .test_client ()
8
+
9
+ def test_purchasePlaces_available_points (client ):
10
+ response = client .post ("/purchasePlaces" , data = {"places" :1 ,"competition" :"Fall Classic" ,"club" :"Iron Temple" })
11
+ assert response .status_code == 200
12
+ assert b'Great-booking complete!' in response .data
13
+
14
+ def test_purchasePlaces_unavailable_points (client ):
15
+ response = client .post ("/purchasePlaces" , data = {"places" :5 ,"competition" :"Fall Classic" ,"club" :"Iron Temple" })
16
+ assert response .status_code == 302
17
+ response_redirect = client .get ("/book/Fall%20Classic/Iron%20Temple" )
18
+ # Byte string to string into a specific encoding utf-8
19
+ response_data = response_redirect .data .decode ('UTF-8' )
20
+ # Html entities to actual special char (" ' "), human readable
21
+ converted_str = html .unescape (response_data )
22
+ assert "Places required exceed club's total points" in converted_str
23
+
24
+ def test_purchasePlaces_negative_input (client ):
25
+ response = client .post ("/purchasePlaces" , data = {"places" :- 1 ,"competition" :"Fall Classic" ,"club" :"Iron Temple" })
26
+ assert response .status_code == 302
27
+ response_redirect = client .get ("/book/Fall%20Classic/Iron%20Temple" )
28
+ # Byte string to string into a specific encoding utf-8
29
+ response_data = response_redirect .data .decode ('UTF-8' )
30
+ # Html entities to actual special char (" ' "), human readable
31
+ converted_str = html .unescape (response_data )
32
+ assert "Places required must be a positive integer" in converted_str
33
+
34
+ def test_purchasePlaces_none_input (client ):
35
+ response = client .post ("/purchasePlaces" , data = {"places" : "" ,"competition" :"Fall Classic" ,"club" :"Iron Temple" })
36
+ assert response .status_code == 302
37
+ response_redirect = client .get ("/book/Fall%20Classic/Iron%20Temple" )
38
+ # Byte string to string into a specific encoding utf-8
39
+ response_data = response_redirect .data .decode ('UTF-8' )
40
+ # Html entities to actual special char (" ' "), human readable
41
+ converted_str = html .unescape (response_data )
42
+ assert "Places required must be a positive integer" in converted_str
0 commit comments