Skip to content

Commit ce5b532

Browse files
committed
Add test for 404 error when dog is not found by ID
1 parent 5744d20 commit ce5b532

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

server/test_app.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff 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

95112
if __name__ == '__main__':
96113
unittest.main()

0 commit comments

Comments
 (0)