File tree Expand file tree Collapse file tree 5 files changed +60
-3
lines changed Expand file tree Collapse file tree 5 files changed +60
-3
lines changed Original file line number Diff line number Diff line change
1
+ [pytest]
2
+ filterwarnings =
3
+ ignore::DeprecationWarning
Original file line number Diff line number Diff line change @@ -4,3 +4,5 @@ itsdangerous==1.1.0
4
4
Jinja2 == 2.11.2
5
5
MarkupSafe == 1.1.1
6
6
Werkzeug == 1.0.1
7
+
8
+ pytest ~= 8.2.2
Original file line number Diff line number Diff line change @@ -52,10 +52,18 @@ def purchasePlaces():
52
52
competition = \
53
53
[c for c in competitions if c ['name' ] == request .form ['competition' ]][0 ]
54
54
club = [c for c in clubs if c ['name' ] == request .form ['club' ]][0 ]
55
+
55
56
placesRequired = int (request .form ['places' ])
57
+
58
+ if placesRequired > 12 :
59
+ flash ('Max purchase 12.' )
60
+ return render_template ('welcome.html' , club = club ,
61
+ competitions = competitions )
62
+
56
63
competition ['numberOfPlaces' ] = int (
57
64
competition ['numberOfPlaces' ]) - placesRequired
58
65
flash ('Great-booking complete!' )
66
+
59
67
return render_template ('welcome.html' , club = club ,
60
68
competitions = competitions )
61
69
Original file line number Diff line number Diff line change
1
+ import pytest
2
+
3
+ from server import app , loadClubs , loadCompetitions
4
+
5
+
6
+ @pytest .fixture
7
+ def client ():
8
+ app .config ['TESTING' ] = True
9
+ with app .test_client () as client :
10
+ yield client
Original file line number Diff line number Diff line change
1
+ from server import loadCompetitions , loadClubs
1
2
2
3
3
- class PurchasePlaces :
4
- def test_purchase_places (self ):
5
- assert False
4
+ def test_purchase_places (client ):
5
+
6
+ clubs = loadClubs ()
7
+ competitions = loadCompetitions ()
8
+
9
+ test_club = clubs [0 ]
10
+ test_competition = competitions [0 ]
11
+ places_to_purchase = 8
12
+
13
+ response = client .post ('/purchasePlaces' , data = {
14
+ 'club' : test_club ['name' ],
15
+ 'competition' : test_competition ['name' ],
16
+ 'places' : places_to_purchase
17
+ })
18
+
19
+ assert response .status_code == 200
20
+ assert b'Great-booking complete!' in response .data
21
+
22
+
23
+ def test_max_purchase_places (client ):
24
+
25
+ clubs = loadClubs ()
26
+ competitions = loadCompetitions ()
27
+
28
+ test_club = clubs [0 ]
29
+ test_competition = competitions [0 ]
30
+ places_to_purchase = 28
31
+
32
+ response = client .post ('/purchasePlaces' , data = {
33
+ 'club' : test_club ['name' ],
34
+ 'competition' : test_competition ['name' ],
35
+ 'places' : places_to_purchase
36
+ })
37
+
38
+ assert response .status_code == 200
39
+ assert b'Max purchase 12.' in response .data
You can’t perform that action at this time.
0 commit comments