-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_app.py
62 lines (46 loc) · 1.99 KB
/
test_app.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
56
57
58
59
60
61
62
import json, pytest
from app import app as flask_app
@pytest.fixture
def app():
yield flask_app
@pytest.fixture
def client(app):
return app.test_client()
def test_add_transactions(client):
url = "http://localhost:5000/add_transactions"
data = {"payer": "DANNON", "points": 1000, "timestamp": "2020-11-02T14:00:00Z"}
response = client.post(url, json = data)
assert response.status_code == 200
data = { "payer": "UNILEVER", "points": 200, "timestamp": "2020-10-31T11:00:00Z" }
response = client.post(url, json = data)
assert response.status_code == 200
data = {"payer": "DANNON", "points": -200, "timestamp": "2020-10-31T15:00:00Z"}
response = client.post(url, json = data)
assert response.status_code == 200
data = {"payer": "MILLER COORS", "points": 10000, "timestamp": "2020-11-01T14:00:00Z"}
response = client.post(url, json = data)
assert response.status_code == 200
data = {"payer": "DANNON", "points": 300, "timestamp": "2020-10-31T10:00:00Z"}
response = client.post(url, json = data)
assert response.status_code == 200
def test_spend_points(client):
url = "http://localhost:5000/spend_points"
data = { "points": -3}
response = client.post(url, json = data)
assert response.status_code == 400
data = { "points": 30000}
response = client.post(url, json = data)
assert response.status_code == 400
data = { "points": 5000 }
response = client.post(url, json = data)
data = json.loads(response.get_data())
assert response.status_code == 200
assert data == [{ "payer": "DANNON", "points": -100 },
{ "payer": "UNILEVER", "points": -200 },
{ "payer": "MILLER COORS", "points": -4700 }]
def test_check_balance(client):
url = "http://localhost:5000/check_balance"
response = client.get(url)
data = json.loads(response.get_data())
assert response.status_code == 200
assert data == {"DANNON": 1000, "UNILEVER": 0, "MILLER COORS": 5300}