Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions puppy_store/puppies/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ def setUp(self):
'color': 'White'
}

self.invalid_payload_age = {
'name': 'Spot',
'age': 'ten',
'breed': 'Pamerion',
'color': 'White'
}

def test_create_valid_puppy(self):
response = client.post(
reverse('get_post_puppies'),
Expand All @@ -94,6 +101,14 @@ def test_create_invalid_puppy(self):
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

def test_create_invalid_puppy_age(self):
response = client.post(
reverse('get_post_puppies'),
data=json.dumps(self.invalid_payload_age),
content_type='application/json'
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

class UpdateSinglePuppyTest(TestCase):
""" Test module for updating an existing puppy record """

Expand Down
2 changes: 1 addition & 1 deletion puppy_store/puppies/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_post_puppies(request):
if request.method == 'POST':
data = {
'name': request.data.get('name'),
'age': int(request.data.get('age')),
'age': request.data.get('age'),
'breed': request.data.get('breed'),
'color': request.data.get('color')
}
Expand Down