22from app .db import db
33import 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")
66def 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")
2457def 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" )
4698def test_get_tasks_no_saved_tasks (client ):
0 commit comments