File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,23 @@ def test_get_dogs_structure(self, mock_query):
9191 self .assertEqual (len (data ), 1 )
9292 self .assertEqual (set (data [0 ].keys ()), {'id' , 'name' , 'breed' })
9393
94+ @patch ('app.db.session.query' )
95+ def test_get_dog_not_found (self , mock_query ):
96+ """Test 404 error when dog is not found by ID"""
97+ # Arrange
98+ mock_query_instance = MagicMock ()
99+ mock_query .return_value = mock_query_instance
100+ mock_query_instance .join .return_value = mock_query_instance
101+ mock_query_instance .filter .return_value = mock_query_instance
102+ mock_query_instance .first .return_value = None # Simulate dog not found
103+
104+ # Act
105+ response = self .app .get ('/api/dogs/999' )
106+
107+ # Assert
108+ self .assertEqual (response .status_code , 404 )
109+ data = json .loads (response .data )
110+ self .assertEqual (data ['error' ], "Dog not found" )
94111
95112if __name__ == '__main__' :
96113 unittest .main ()
You can’t perform that action at this time.
0 commit comments