1+ import server
12from server import loadCompetitions , loadClubs
23
34
45def test_purchase_places (client ):
5-
66 test_club = loadClubs ()[0 ]
77 test_competition = loadCompetitions ()[0 ]
88 places_to_purchase = 8
@@ -18,7 +18,6 @@ def test_purchase_places(client):
1818
1919
2020def test_max_purchase_places (client ):
21-
2221 test_club = loadClubs ()[0 ]
2322 test_competition = loadCompetitions ()[0 ]
2423 places_to_purchase = 28
@@ -34,7 +33,6 @@ def test_max_purchase_places(client):
3433
3534
3635def test_has_sufficient_points (client ):
37-
3836 test_club = loadClubs ()[1 ]
3937 test_competition = loadCompetitions ()[0 ]
4038 places_to_purchase = 9
@@ -47,3 +45,24 @@ def test_has_sufficient_points(client):
4745
4846 assert response .status_code == 200
4947 assert b'Insufficiant points.' in response .data
48+
49+
50+ def test_purchase_places (client , test_clubs , test_competitions , mocker ):
51+
52+ mocker .patch ('server.loadClubs' , return_value = test_clubs )
53+ mocker .patch ('server.loadCompetitions' , return_value = test_competitions )
54+ mock_save_club = mocker .patch ('server.saveClub' )
55+
56+ mocker .patch .object (server , 'clubs' , test_clubs )
57+ mocker .patch .object (server , 'competitions' , test_competitions )
58+
59+ places_to_purchase = 9
60+
61+ response = client .post ('/purchasePlaces' , data = {
62+ 'club' : test_clubs [0 ]['name' ],
63+ 'competition' : test_competitions [0 ]['name' ],
64+ 'places' : str (places_to_purchase )
65+ })
66+
67+ assert int (test_clubs [0 ]['points' ]) == 4
68+ assert b'Great-booking complete!' in response .data
0 commit comments