-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_flask.py
92 lines (79 loc) · 2.76 KB
/
test_flask.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import json
import pytest
from flask import url_for
from app import app, db, Transaction
def test_method_get_response_405():
response = app.test_client().get('/transaction')
assert response.status_code == 405
def test_transaction_status_code_insert_body_clear():
response = app.test_client().post(
'/transaction',
data=json.dumps({}),
content_type='application/json'
)
assert response.status_code == 400
def test_transaction_status_code_insert_body():
response = app.test_client().post(
'/transaction',
data=json.dumps({
"estabelecimento": "45.283.163/0001-69",
"cliente": "094.214.930-01",
"valor": 10.5,
"descricao": "compra via Shipay, Mercado"
}),
content_type='application/json',
)
recorded_number = len(Transaction.query.filter_by(custumer="094.214.930-01").all())
last_record = Transaction.query.filter_by(id=recorded_number).all()
db.session.delete(last_record[0])
db.session.commit()
assert response.status_code == 201
def test_transaction_response_body():
response = app.test_client().post(
'/transaction',
data=json.dumps({
"estabelecimento": "45.283.163/0001-69",
"cliente": "094.214.930-01",
"valor": 10.5,
"descricao": "compra via Shipay, Mercado"
}),
content_type='application/json',
)
data = json.loads(response.get_data(as_text=True))
response = {
"aceito": True
}
recorded_number = len(Transaction.query.filter_by(custumer="094.214.930-01").all())
last_record = Transaction.query.filter_by(id=recorded_number).all()
db.session.delete(last_record[0])
db.session.commit()
assert data == response
def test_transaction_status_code_empty_field():
response = app.test_client().post(
'/transaction',
data=json.dumps({
"estabelecimento": "",
"cliente": "094.214.930-01",
"valor": 2.00,
"descricao": "compra via Shipay, Mercado"
}),
content_type='application/json',
)
assert response.status_code == 400
def test_record_db():
record_number = len(Transaction.query.filter_by(custumer="094.214.930-01").all())
app.test_client().post(
'/transaction',
data=json.dumps({
"estabelecimento": "45.283.163/0001-69",
"cliente": "094.214.930-01",
"valor": 10.5,
"descricao": "compra via Shipay, Mercado"
}),
content_type='application/json',
)
recorded_number = len(Transaction.query.filter_by(custumer="094.214.930-01").all())
last_record = Transaction.query.filter_by(id=recorded_number).all()
db.session.delete(last_record[0])
db.session.commit()
assert record_number < recorded_number