Skip to content

Commit d3b9a42

Browse files
committed
wave 3 all tests passed
1 parent 579987e commit d3b9a42

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

app/routes/task_routes.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from flask import Blueprint, abort, make_response, request, Response
22
from app.models.task import Task
33
from ..db import db
4+
from datetime import datetime
45

56

67
tasks_bp = Blueprint("tasks_bp", __name__, url_prefix="/tasks")
@@ -123,8 +124,6 @@ def update_task(task_id):
123124
def delete_task(task_id):
124125
task = validate_task(task_id)
125126
task_title = task.title
126-
print(task_title)
127-
128127

129128
db.session.delete(task)
130129
db.session.commit()
@@ -133,8 +132,21 @@ def delete_task(task_id):
133132

134133
return response_body
135134

135+
@tasks_bp.patch("/<task_id>/mark_complete")
136+
def mark_complete(task_id):
137+
task = validate_task(task_id)
138+
task.completed_at = datetime.now()
139+
db.session.commit()
140+
response = {"task": get_dict(task)}
141+
return make_response(response, 200)
136142

137-
143+
@tasks_bp.patch("/<task_id>/mark_incomplete")
144+
def mark_incomplete(task_id):
145+
task = validate_task(task_id)
146+
task.completed_at = None
147+
db.session.commit()
148+
response = {"task": get_dict(task)}
149+
return make_response(response,200)
138150
#helperfunctions
139151

140152
def check_for_completion(task):

tests/test_wave_03.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66

77

8-
@pytest.mark.skip(reason="No way to test this feature yet")
8+
# ## @pytest.mark.skip(reason="No way to test this feature yet")
99
def test_mark_complete_on_incomplete_task(client, one_task):
1010
# Arrange
1111
"""
@@ -23,8 +23,8 @@ def test_mark_complete_on_incomplete_task(client, one_task):
2323
with patch("requests.post") as mock_get:
2424
mock_get.return_value.status_code = 200
2525

26-
# Act
27-
response = client.patch("/tasks/1/mark_complete")
26+
# Act
27+
response = client.patch("/tasks/1/mark_complete")
2828
response_body = response.get_json()
2929

3030
# Assert
@@ -42,7 +42,7 @@ def test_mark_complete_on_incomplete_task(client, one_task):
4242
assert Task.query.get(1).completed_at
4343

4444

45-
@pytest.mark.skip(reason="No way to test this feature yet")
45+
# ## ## @pytest.mark.skip(reason="No way to test this feature yet")
4646
def test_mark_incomplete_on_complete_task(client, completed_task):
4747
# Act
4848
response = client.patch("/tasks/1/mark_incomplete")
@@ -62,7 +62,7 @@ def test_mark_incomplete_on_complete_task(client, completed_task):
6262
assert Task.query.get(1).completed_at == None
6363

6464

65-
@pytest.mark.skip(reason="No way to test this feature yet")
65+
## @pytest.mark.skip(reason="No way to test this feature yet")
6666
def test_mark_complete_on_completed_task(client, completed_task):
6767
# Arrange
6868
"""
@@ -99,7 +99,7 @@ def test_mark_complete_on_completed_task(client, completed_task):
9999
assert Task.query.get(1).completed_at
100100

101101

102-
@pytest.mark.skip(reason="No way to test this feature yet")
102+
## @pytest.mark.skip(reason="No way to test this feature yet")
103103
def test_mark_incomplete_on_incomplete_task(client, one_task):
104104
# Act
105105
response = client.patch("/tasks/1/mark_incomplete")
@@ -119,31 +119,22 @@ def test_mark_incomplete_on_incomplete_task(client, one_task):
119119
assert Task.query.get(1).completed_at == None
120120

121121

122-
@pytest.mark.skip(reason="No way to test this feature yet")
122+
## @pytest.mark.skip(reason="No way to test this feature yet")
123123
def test_mark_complete_missing_task(client):
124124
# Act
125125
response = client.patch("/tasks/1/mark_complete")
126126
response_body = response.get_json()
127127

128128
# Assert
129129
assert response.status_code == 404
130+
assert response_body == {"details": f"task 1 not found"}
130131

131-
raise Exception("Complete test with assertion about response body")
132-
# *****************************************************************
133-
# **Complete test with assertion about response body***************
134-
# *****************************************************************
135-
136-
137-
@pytest.mark.skip(reason="No way to test this feature yet")
132+
## @pytest.mark.skip(reason="No way to test this feature yet")
138133
def test_mark_incomplete_missing_task(client):
139134
# Act
140135
response = client.patch("/tasks/1/mark_incomplete")
141136
response_body = response.get_json()
142137

143138
# Assert
144139
assert response.status_code == 404
145-
146-
raise Exception("Complete test with assertion about response body")
147-
# *****************************************************************
148-
# **Complete test with assertion about response body***************
149-
# *****************************************************************
140+
assert response_body == {"details": f"task 1 not found"}

0 commit comments

Comments
 (0)