forked from marcosvbras/todo-list-python
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_todo.py
130 lines (108 loc) · 3.71 KB
/
test_todo.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# coding=utf-8
from todo import app
def test_list_tasks_must_return_status_200():
with app.test_client() as client:
response = client.get('/tasks')
assert response.status_code == 200
def test_list_tasks_must_have_json_format():
with app.test_client() as client:
response = client.get('/tasks')
assert response.content_type == 'application/json'
def test_create_task_accepts_method_post():
with app.test_client() as client:
response = client.post('/tasks')
assert response.status_code != 405
def test_create_task_returns_created_task():
with app.test_client() as client:
import json
response = client.post(
'/tasks',
data=json.dumps(
{
'title': 'The Best Title',
'description': 'The Best Description'
}
),
content_type='application/json'
)
data = json.loads(response.data.decode('utf-8'))
assert data['title'] == 'The Best Title'
assert data['description'] == 'The Best Description'
assert data['done'] == False
def test_create_task_must_returns_201_status_code():
with app.test_client() as client:
import json
response = client.post(
'/tasks',
data=json.dumps(
{
'title': 'The Incredible Title',
'description': 'The Incredible Description'
}
),
content_type='application/json'
)
assert response.status_code == 201
def test_create_task_without_description_must_returns_400():
with app.test_client() as client:
import json
response = client.post(
'/tasks',
data=json.dumps(
{
'title': 'The Best Title',
'description': None
}
),
content_type='application/json'
)
assert response.status_code == 400
def test_create_task_without_title_must_returns_400():
with app.test_client() as client:
import json
response = client.post(
'/tasks',
data=json.dumps(
{
'title': None,
'description': 'The Best Description'
}
),
content_type='application/json'
)
assert response.status_code == 400
def test_retrieve_task_by_id_must_returns_json():
with app.test_client() as client:
import json
response = client.post(
'/tasks',
data=json.dumps(
{
'title': 'The Awesome Title',
'description': 'The Awesome Description'
}
),
content_type='application/json'
)
data = json.loads(response.data.decode('utf-8'))
inserted_id = data['_id']['$oid']
response = client.get(f'/tasks/{inserted_id}')
assert response.content_type == 'application/json'
def test_retrieve_task_with_pk_must_returns_task():
with app.test_client() as client:
import json
response = client.post(
'/tasks',
data=json.dumps(
{
'title': 'The Awesome Title',
'description': 'The Awesome Description'
}
),
content_type='application/json'
)
data = json.loads(response.data.decode('utf-8'))
inserted_id = data['_id']['$oid']
response = client.get(f'/tasks/{inserted_id}')
data = json.loads(response.data.decode('utf-8'))
assert data['_id']['$oid'] == inserted_id