Skip to content

Commit 50f0c74

Browse files
committed
Merge branch 'main' of https://github.com/AdaGold/task-list-api into ay_update_wave6_test
2 parents 3c150d3 + 6355329 commit 50f0c74

File tree

8 files changed

+87
-123
lines changed

8 files changed

+87
-123
lines changed

ada-project-docs/wave_01.md

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -150,32 +150,19 @@ As a client, I want to be able to make a `PUT` request to `/tasks/1` when there
150150

151151
and get this response:
152152

153-
`200 OK`
153+
`204 No Content`
154154

155-
```json
156-
{
157-
"task": {
158-
"id": 1,
159-
"title": "Updated Task Title",
160-
"description": "Updated Test Description",
161-
"is_complete": false
162-
}
163-
}
164-
```
155+
The response should have a mimetype of "application/json" to keep our API response type consistent.
165156

166157
Note that the update endpoint does update the `completed_at` attribute. This will be updated with custom endpoints implemented in Wave 3.
167158

168159
#### Delete Task: Deleting a Task
169160

170161
As a client, I want to be able to make a `DELETE` request to `/tasks/1` when there is at least one saved task and get this response:
171162

172-
`200 OK`
163+
`204 No Content`
173164

174-
```json
175-
{
176-
"details": "Task 1 \"Go on my daily walk 🏞\" successfully deleted"
177-
}
178-
```
165+
The response should have a mimetype of "application/json" to keep our API response type consistent.
179166

180167
#### No Matching Task: Get, Update, and Delete
181168

ada-project-docs/wave_03.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ when I send a `PATCH` request to `/tasks/1/mark_complete`,
3434

3535
then the task is updated, so that its `completed_at` value is the current date, and I get this response:
3636

37+
`204 No Content`
38+
39+
The response should have a mimetype of "application/json" to keep our API response type consistent.
40+
41+
After I have made the `PATCH` request, I can submit a `GET` request to `/tasks/1`, which will return the response:
42+
3743
`200 OK`
3844

3945
```json
@@ -58,6 +64,12 @@ when I send a `PATCH` request to `/tasks/1/mark_incomplete`,
5864

5965
then the task is updated, so that its `completed_at` value is `null`/`None`, and I get this response:
6066

67+
`204 No Content`
68+
69+
The response should have a mimetype of "application/json" to keep our API response type consistent.
70+
71+
After I have made the `PATCH` request, I can submit a `GET` request to `/tasks/1`, which will return the response:
72+
6173
`200 OK`
6274

6375
```json
@@ -82,6 +94,12 @@ when I send a `PATCH` request to `/tasks/1/mark_complete`,
8294

8395
then I want this to behave exactly like `/tasks/1/mark_complete` for an incomplete task. The task is updated, so that its `completed_at` value is the current date, and I get this response:
8496

97+
`204 No Content`
98+
99+
The response should have a mimetype of "application/json" to keep our API response type consistent.
100+
101+
After I have made the `PATCH` request, I can submit a `GET` request to `/tasks/1`, which will return the response:
102+
85103
`200 OK`
86104

87105
```json
@@ -106,6 +124,12 @@ when I send a `PATCH` request to `/tasks/1/mark_incomplete`,
106124

107125
then I want this to behave exactly like `/tasks/1/mark_incomplete` for a complete task. Its `completed_at` value remains as `null`/`None`, and I get this response:
108126

127+
`204 No Content`
128+
129+
The response should have a mimetype of "application/json" to keep our API response type consistent.
130+
131+
After I have made the `PATCH` request, I can submit a `GET` request to `/tasks/1`, which will return the response:
132+
109133
`200 OK`
110134

111135
```json

ada-project-docs/wave_05.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,28 +125,17 @@ As a client, I want to be able to make a `PUT` request to `/goals/1` when there
125125

126126
and get this response:
127127

128-
`200 OK`
128+
`204 No Content`
129129

130-
```json
131-
{
132-
"goal": {
133-
"id": 1,
134-
"title": "Updated Goal Title"
135-
}
136-
}
137-
```
130+
The response should have a mimetype of "application/json" to keep our API response type consistent.
138131

139132
### Delete Goal: Deleting a Goal
140133

141134
As a client, I want to be able to make a `DELETE` request to `/goals/1` when there is at least one saved goal and get this response:
142135

143-
`200 OK`
136+
`204 No Content`
144137

145-
```json
146-
{
147-
"details": "Goal 1 \"Build a habit of going outside daily\" successfully deleted"
148-
}
149-
```
138+
The response should have a mimetype of "application/json" to keep our API response type consistent.
150139

151140
### No matching Goal: Get, Update, and Delete
152141

tests/conftest.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ def one_task(app):
5757
def three_tasks(app):
5858
db.session.add_all([
5959
Task(title="Water the garden 🌷",
60-
description="",
61-
completed_at=None),
60+
description="",
61+
completed_at=None),
6262
Task(title="Answer forgotten email 📧",
63-
description="",
64-
completed_at=None),
63+
description="",
64+
completed_at=None),
6565
Task(title="Pay my outstanding tickets 😭",
66-
description="",
67-
completed_at=None)
66+
description="",
67+
completed_at=None)
6868
])
6969
db.session.commit()
7070

@@ -77,7 +77,7 @@ def three_tasks(app):
7777
def completed_task(app):
7878
new_task = Task(title="Go on my daily walk 🏞",
7979
description="Notice something new every day",
80-
completed_at=datetime.utcnow())
80+
completed_at=datetime.now())
8181
db.session.add(new_task)
8282
db.session.commit()
8383

@@ -99,7 +99,9 @@ def one_goal(app):
9999
# goal has this task, and the task belongs to one goal
100100
@pytest.fixture
101101
def one_task_belongs_to_one_goal(app, one_goal, one_task):
102-
task = Task.query.first()
103-
goal = Goal.query.first()
102+
task_query = db.select(Task).where(Task.id == 1)
103+
goal_query = db.select(Goal).where(Goal.id == 1)
104+
task = db.session.scalar(task_query)
105+
goal = db.session.scalar(goal_query)
104106
goal.tasks.append(task)
105-
db.session.commit()
107+
db.session.commit()

tests/test_wave_01.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from app.models.task import Task
2+
from app.db import db
23
import pytest
34

45

@@ -86,7 +87,10 @@ def test_create_task(client):
8687
"is_complete": False
8788
}
8889
}
89-
new_task = Task.query.get(1)
90+
91+
query = db.select(Task).where(Task.id == 1)
92+
new_task = db.session.scalar(query)
93+
9094
assert new_task
9195
assert new_task.title == "A Brand New Task"
9296
assert new_task.description == "Test Description"
@@ -100,25 +104,19 @@ def test_update_task(client, one_task):
100104
"title": "Updated Task Title",
101105
"description": "Updated Test Description",
102106
})
103-
response_body = response.get_json()
104107

105108
# Assert
106-
assert response.status_code == 200
107-
assert "task" in response_body
108-
assert response_body == {
109-
"task": {
110-
"id": 1,
111-
"title": "Updated Task Title",
112-
"description": "Updated Test Description",
113-
"is_complete": False
114-
}
115-
}
116-
task = Task.query.get(1)
109+
assert response.status_code == 204
110+
111+
query = db.select(Task).where(Task.id == 1)
112+
task = db.session.scalar(query)
113+
117114
assert task.title == "Updated Task Title"
118115
assert task.description == "Updated Test Description"
119116
assert task.completed_at == None
120117

121118

119+
122120
@pytest.mark.skip(reason="No way to test this feature yet")
123121
def test_update_task_not_found(client):
124122
# Act
@@ -141,16 +139,12 @@ def test_update_task_not_found(client):
141139
def test_delete_task(client, one_task):
142140
# Act
143141
response = client.delete("/tasks/1")
144-
response_body = response.get_json()
145142

146143
# Assert
147-
assert response.status_code == 200
148-
assert "details" in response_body
149-
assert response_body == {
150-
"details": 'Task 1 "Go on my daily walk 🏞" successfully deleted'
151-
}
152-
assert Task.query.get(1) == None
144+
assert response.status_code == 204
153145

146+
query = db.select(Task).where(Task.id == 1)
147+
assert db.session.scalar(query) == None
154148

155149
@pytest.mark.skip(reason="No way to test this feature yet")
156150
def test_delete_task_not_found(client):
@@ -166,7 +160,7 @@ def test_delete_task_not_found(client):
166160
# **Complete test with assertion about response body***************
167161
# *****************************************************************
168162

169-
assert Task.query.all() == []
163+
assert db.session.scalars(db.select(Task)).all() == []
170164

171165

172166
@pytest.mark.skip(reason="No way to test this feature yet")
@@ -183,7 +177,7 @@ def test_create_task_must_contain_title(client):
183177
assert response_body == {
184178
"details": "Invalid data"
185179
}
186-
assert Task.query.all() == []
180+
assert db.session.scalars(db.select(Task)).all() == []
187181

188182

189183
@pytest.mark.skip(reason="No way to test this feature yet")
@@ -200,4 +194,4 @@ def test_create_task_must_contain_description(client):
200194
assert response_body == {
201195
"details": "Invalid data"
202196
}
203-
assert Task.query.all() == []
197+
assert db.session.scalars(db.select(Task)).all() == []

tests/test_wave_03.py

Lines changed: 17 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from unittest.mock import Mock, patch
33
from datetime import datetime
44
from app.models.task import Task
5+
from app.db import db
56
import pytest
67

78

@@ -25,41 +26,24 @@ def test_mark_complete_on_incomplete_task(client, one_task):
2526

2627
# Act
2728
response = client.patch("/tasks/1/mark_complete")
28-
response_body = response.get_json()
2929

3030
# Assert
31-
assert response.status_code == 200
32-
assert "task" in response_body
33-
assert response_body["task"]["is_complete"] == True
34-
assert response_body == {
35-
"task": {
36-
"id": 1,
37-
"title": "Go on my daily walk 🏞",
38-
"description": "Notice something new every day",
39-
"is_complete": True
40-
}
41-
}
42-
assert Task.query.get(1).completed_at
31+
assert response.status_code == 204
32+
33+
query = db.select(Task).where(Task.id == 1)
34+
assert db.session.scalar(query).completed_at
4335

4436

4537
@pytest.mark.skip(reason="No way to test this feature yet")
4638
def test_mark_incomplete_on_complete_task(client, completed_task):
4739
# Act
4840
response = client.patch("/tasks/1/mark_incomplete")
49-
response_body = response.get_json()
41+
5042

5143
# Assert
52-
assert response.status_code == 200
53-
assert response_body["task"]["is_complete"] == False
54-
assert response_body == {
55-
"task": {
56-
"id": 1,
57-
"title": "Go on my daily walk 🏞",
58-
"description": "Notice something new every day",
59-
"is_complete": False
60-
}
61-
}
62-
assert Task.query.get(1).completed_at == None
44+
assert response.status_code == 204
45+
query = db.select(Task).where(Task.id == 1)
46+
assert db.session.scalar(query).completed_at == None
6347

6448

6549
@pytest.mark.skip(reason="No way to test this feature yet")
@@ -82,41 +66,24 @@ def test_mark_complete_on_completed_task(client, completed_task):
8266

8367
# Act
8468
response = client.patch("/tasks/1/mark_complete")
85-
response_body = response.get_json()
69+
8670

8771
# Assert
88-
assert response.status_code == 200
89-
assert "task" in response_body
90-
assert response_body["task"]["is_complete"] == True
91-
assert response_body == {
92-
"task": {
93-
"id": 1,
94-
"title": "Go on my daily walk 🏞",
95-
"description": "Notice something new every day",
96-
"is_complete": True
97-
}
98-
}
99-
assert Task.query.get(1).completed_at
72+
assert response.status_code == 204
10073

74+
query = db.select(Task).where(Task.id == 1)
75+
assert db.session.scalar(query).completed_at
10176

10277
@pytest.mark.skip(reason="No way to test this feature yet")
10378
def test_mark_incomplete_on_incomplete_task(client, one_task):
10479
# Act
10580
response = client.patch("/tasks/1/mark_incomplete")
106-
response_body = response.get_json()
10781

10882
# Assert
109-
assert response.status_code == 200
110-
assert response_body["task"]["is_complete"] == False
111-
assert response_body == {
112-
"task": {
113-
"id": 1,
114-
"title": "Go on my daily walk 🏞",
115-
"description": "Notice something new every day",
116-
"is_complete": False
117-
}
118-
}
119-
assert Task.query.get(1).completed_at == None
83+
assert response.status_code == 204
84+
85+
query = db.select(Task).where(Task.id == 1)
86+
assert db.session.scalar(query).completed_at == None
12087

12188

12289
@pytest.mark.skip(reason="No way to test this feature yet")

tests/test_wave_05.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,17 @@ def test_update_goal_not_found(client):
111111
def test_delete_goal(client, one_goal):
112112
# Act
113113
response = client.delete("/goals/1")
114-
response_body = response.get_json()
115114

116115
# Assert
117-
assert response.status_code == 200
118-
assert "details" in response_body
119-
assert response_body == {
120-
"details": 'Goal 1 "Build a habit of going outside daily" successfully deleted'
121-
}
116+
assert response.status_code == 204
122117

123118
# Check that the goal was deleted
124119
response = client.get("/goals/1")
125120
assert response.status_code == 404
126121

122+
response_body = response.get_json()
123+
assert "message" in response_body
124+
127125
raise Exception("Complete test with assertion about response body")
128126
# *****************************************************************
129127
# **Complete test with assertion about response body***************

0 commit comments

Comments
 (0)