Skip to content

Commit 2da675f

Browse files
committed
(test) purchasePlaces function redeem more points than available
1 parent 81e09c8 commit 2da675f

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ bin
22
include
33
lib
44
.Python
5-
tests/
65
.envrc
7-
__pycache__
6+
__pycache__
7+
.DS_Store

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
3+
testpaths = tests

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ itsdangerous==1.1.0
44
Jinja2==2.11.2
55
MarkupSafe==1.1.1
66
Werkzeug==1.0.1
7+
pytest

tests/__init__.py

Whitespace-only changes.

tests/test_endpoints.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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

Comments
 (0)