Skip to content

Commit c05e9b3

Browse files
committed
Add negative tests for Task and Goal to_dict and from_dict
1 parent ebd21db commit c05e9b3

File tree

2 files changed

+110
-26
lines changed

2 files changed

+110
-26
lines changed

tests/test_wave_01.py

Lines changed: 68 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,25 @@
22
from app.db import db
33
import pytest
44

5-
@pytest.mark.skip(reason="No way to test this feature yet")
5+
# @pytest.mark.skip(reason="No way to test this feature yet")
66
def test_task_to_dict():
7+
#Arrange
8+
new_task = Task(id = 1, title="Make My Bed",
9+
description="Start the day off right!",
10+
completed_at=None)
11+
12+
#Act
13+
task_dict = new_task.to_dict()
14+
15+
#Assert
16+
assert len(task_dict) == 4
17+
assert task_dict["id"] == 1
18+
assert task_dict["title"] == "Make My Bed"
19+
assert task_dict["description"] == "Start the day off right!"
20+
assert task_dict["is_complete"] == False
21+
22+
# @pytest.mark.skip(reason="No way to test this feature yet")
23+
def test_task_to_dict_missing_id():
724
#Arrange
825
new_task = Task(title="Make My Bed",
926
description="Start the day off right!",
@@ -13,14 +30,30 @@ def test_task_to_dict():
1330
task_dict = new_task.to_dict()
1431

1532
#Assert
16-
assert task_dict == {
17-
"id": None,
18-
"title": "Make My Bed",
19-
"description": "Start the day off right!",
20-
"is_complete": False
21-
}
33+
assert len(task_dict) == 4
34+
assert task_dict["id"] is None
35+
assert task_dict["title"] == "Make My Bed"
36+
assert task_dict["description"] == "Start the day off right!"
37+
assert task_dict["is_complete"] == False
38+
39+
# @pytest.mark.skip(reason="No way to test this feature yet")
40+
def test_task_to_dict_missing_title():
41+
#Arrange
42+
new_task = Task(id = 1,
43+
description="Start the day off right!",
44+
completed_at=None)
45+
46+
#Act
47+
task_dict = new_task.to_dict()
2248

23-
@pytest.mark.skip(reason="No way to test this feature yet")
49+
#Assert
50+
assert len(task_dict) == 4
51+
assert task_dict["id"] == 1
52+
assert task_dict["title"] is None
53+
assert task_dict["description"] == "Start the day off right!"
54+
assert task_dict["is_complete"] == False
55+
56+
# @pytest.mark.skip(reason="No way to test this feature yet")
2457
def test_task_from_dict():
2558
#Arrange
2659
task_dict = {
@@ -29,18 +62,37 @@ def test_task_from_dict():
2962
"is_complete": False
3063
}
3164

32-
expected_task = Task(title="Make My Bed",
33-
description="Start the day off right!",
34-
completed_at=None)
35-
3665
#Act
3766
task_obj = Task.from_dict(task_dict)
3867

3968
#Assert
40-
assert task_obj.id is None
41-
assert task_obj.title == expected_task.title
42-
assert task_obj.description == expected_task.description
43-
assert task_obj.completed_at == expected_task.completed_at
69+
assert task_obj.title == "Make My Bed"
70+
assert task_obj.description == "Start the day off right!"
71+
assert task_obj.completed_at is None
72+
73+
# @pytest.mark.skip(reason="No way to test this feature yet")
74+
def test_task_from_dict_no_title():
75+
#Arrange
76+
task_dict = {
77+
"description": "Start the day off right!",
78+
"is_complete": False
79+
}
80+
81+
#Act & Assert
82+
with pytest.raises(KeyError, match = 'title'):
83+
Task.from_dict(task_dict)
84+
85+
# @pytest.mark.skip(reason="No way to test this feature yet")
86+
def test_task_from_dict_no_description():
87+
#Arrange
88+
task_dict = {
89+
"title": "Make My Bed",
90+
"is_complete": False
91+
}
92+
93+
#Act & Assert
94+
with pytest.raises(KeyError, match = 'description'):
95+
Task.from_dict(task_dict)
4496

4597
@pytest.mark.skip(reason="No way to test this feature yet")
4698
def test_get_tasks_no_saved_tasks(client):

tests/test_wave_05.py

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,67 @@
11
from app.models.goal import Goal
22
import pytest
33

4-
@pytest.mark.skip(reason="No way to test this feature yet")
4+
# @pytest.mark.skip(reason="No way to test this feature yet")
55
def test_goal_to_dict():
6+
#Arrange
7+
new_goal = Goal(id=1, title="Seize the Day!")
8+
9+
#Act
10+
goal_dict = new_goal.to_dict()
11+
12+
#Assert
13+
assert goal_dict["id"] == 1
14+
assert goal_dict["title"] == "Seize the Day!"
15+
16+
# @pytest.mark.skip(reason="No way to test this feature yet")
17+
def test_goal_to_dict_no_id():
618
#Arrange
719
new_goal = Goal(title="Seize the Day!")
820

921
#Act
1022
goal_dict = new_goal.to_dict()
1123

1224
#Assert
13-
assert goal_dict == {
14-
"id": None,
15-
"title": "Seize the Day!"
16-
}
25+
assert goal_dict["id"] is None
26+
assert goal_dict["title"] == "Seize the Day!"
1727

18-
@pytest.mark.skip(reason="No way to test this feature yet")
28+
# @pytest.mark.skip(reason="No way to test this feature yet")
29+
def test_goal_to_dict_no_title():
30+
#Arrange
31+
new_goal = Goal(id=1)
32+
33+
#Act
34+
goal_dict = new_goal.to_dict()
35+
36+
#Assert
37+
assert goal_dict["id"] == 1
38+
assert goal_dict["title"] is None
39+
40+
41+
42+
# @pytest.mark.skip(reason="No way to test this feature yet")
1943
def test_goal_from_dict():
2044
#Arrange
2145
goal_dict = {
2246
"title": "Seize the Day!",
2347
}
2448

25-
expected_goal = Goal(title="Seize the Day!")
26-
2749
#Act
2850
goal_obj = Goal.from_dict(goal_dict)
2951

3052
#Assert
31-
assert goal_obj.id is None
32-
assert goal_obj.title == expected_goal.title
53+
assert goal_obj.title == "Seize the Day!"
54+
55+
# @pytest.mark.skip(reason="No way to test this feature yet")
56+
def test_goal_from_dict_no_title():
57+
#Arrange
58+
goal_dict = {
59+
}
60+
61+
#Act & Assert
62+
with pytest.raises(KeyError, match = 'title'):
63+
Goal.from_dict(goal_dict)
64+
3365

3466
@pytest.mark.skip(reason="No way to test this feature yet")
3567
def test_get_goals_no_saved_goals(client):

0 commit comments

Comments
 (0)