11import pytest
2-
2+ from werkzeug . exceptions import HTTPException
33from app .models .goal import Goal
44from app .models .task import Task
55from app .routes .route_utilities import create_model , validate_model
@@ -23,6 +23,32 @@ def test_route_utilities_validate_model_with_task(client, three_tasks):
2323 assert task_3 .id == 3
2424 assert task_3 .title == "Pay my outstanding tickets 😭"
2525
26+
27+ @pytest .mark .skip (reason = "No way to test this feature yet" )
28+ def test_route_utilities_validate_model_with_task_invalid_id (client , three_tasks ):
29+ #Act & Assert
30+ # Calling `validate_model` without being invoked by a route will
31+ # cause an `HTTPException` when an `abort` statement is reached
32+ with pytest .raises (HTTPException ) as e :
33+ result_task = validate_model (Task , "One" )
34+
35+ # Test that the correct status code and response message are returned
36+ response = e .value .get_response ()
37+ assert response .status_code == 400
38+ assert response .get_json () == {"message" : "Task One invalid" }
39+
40+ @pytest .mark .skip (reason = "No way to test this feature yet" )
41+ def test_route_utilities_validate_model_with_task_missing_id (client , three_tasks ):
42+ #Act & Assert
43+ with pytest .raises (HTTPException ) as e :
44+ result_task = validate_model (Task , 4 )
45+
46+ raise Exception ("Complete test with assertion status code and response body" )
47+ # *****************************************************************************
48+ # **Complete test with assertion about status code response body***************
49+ # *****************************************************************************
50+
51+
2652@pytest .mark .skip (reason = "No way to test this feature yet" )
2753def test_route_utilities_validate_model_with_goal (client , one_goal ):
2854 #Act
@@ -32,6 +58,28 @@ def test_route_utilities_validate_model_with_goal(client, one_goal):
3258 assert goal_1 .id == 1
3359 assert goal_1 .title == "Build a habit of going outside daily"
3460
61+ @pytest .mark .skip (reason = "No way to test this feature yet" )
62+ def test_route_utilities_validate_model_with_goal_invalid_id (client , one_goal ):
63+ #Act & Assert
64+ with pytest .raises (HTTPException ) as e :
65+ result_task = validate_model (Goal , "One" )
66+
67+ raise Exception ("Complete test with assertion status code and response body" )
68+ # *****************************************************************************
69+ # **Complete test with assertion about status code response body***************
70+ # *****************************************************************************
71+
72+ @pytest .mark .skip (reason = "No way to test this feature yet" )
73+ def test_route_utilities_validate_model_with_goal_missing_id (client , one_goal ):
74+ #Act & Assert
75+ with pytest .raises (HTTPException ) as e :
76+ result_task = validate_model (Goal , 4 )
77+
78+ raise Exception ("Complete test with assertion status code and response body" )
79+ # *****************************************************************************
80+ # **Complete test with assertion about status code response body***************
81+ # *****************************************************************************
82+
3583@pytest .mark .skip (reason = "No way to test this feature yet" )
3684def test_route_utilities_create_model_with_task (client ):
3785 #Arrange
@@ -51,6 +99,23 @@ def test_route_utilities_create_model_with_task(client):
5199 assert response [0 ]["is_complete" ] == False
52100 assert response [1 ] == 201
53101
102+ @pytest .mark .skip (reason = "No way to test this feature yet" )
103+ def test_route_utilities_create_model_with_task_missing_title (client ):
104+ #Arrange
105+ request_body = {
106+ "description" : "" ,
107+ "completed_at" : None
108+ }
109+
110+ #Act
111+ with pytest .raises (HTTPException ) as e :
112+ create_model (Task , request_body )
113+
114+ response = e .value .get_response ()
115+ assert response .status_code == 400
116+ assert response .get_json () == {"message" : "Invalid request: missing title" }
117+
118+
54119@pytest .mark .skip (reason = "No way to test this feature yet" )
55120def test_route_utilities_create_model_with_goal (client ):
56121 #Arrange
@@ -64,4 +129,19 @@ def test_route_utilities_create_model_with_goal(client):
64129 #Assert
65130 assert response [0 ]["id" ] == 1 #create_model returns a tuple
66131 assert response [0 ]["title" ] == "Seize the Day!"
67- assert response [1 ] == 201
132+ assert response [1 ] == 201
133+
134+ @pytest .mark .skip (reason = "No way to test this feature yet" )
135+ def test_route_utilities_create_model_with_goal_missing_title (client ):
136+ #Arrange
137+ request_body = {
138+ }
139+
140+ #Act
141+ with pytest .raises (HTTPException ) as e :
142+ create_model (Goal , request_body )
143+
144+ raise Exception ("Complete test with assertion status code and response body" )
145+ # *****************************************************************************
146+ # **Complete test with assertion about status code response body***************
147+ # *****************************************************************************
0 commit comments