diff --git a/puppy_store/puppies/tests/test_views.py b/puppy_store/puppies/tests/test_views.py index 61af938..16cf549 100644 --- a/puppy_store/puppies/tests/test_views.py +++ b/puppy_store/puppies/tests/test_views.py @@ -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'), @@ -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 """ diff --git a/puppy_store/puppies/views.py b/puppy_store/puppies/views.py index 21fda1d..8f5ee99 100644 --- a/puppy_store/puppies/views.py +++ b/puppy_store/puppies/views.py @@ -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') }