400 Response when submitting invalid place data and testing more edge cases

This commit is contained in:
reverend 2021-06-12 15:52:52 +02:00
parent b0bf40aa0b
commit 4f465b3162
2 changed files with 124 additions and 42 deletions

View File

@ -133,7 +133,8 @@ class TestPlaceCreateView(ViewTestCase):
settings.BASE_DIR,
'testdata',
'test_image.jpg'
)
),
'rb'
)
response = self.client.post(
reverse('place_create'),
@ -145,7 +146,7 @@ class TestPlaceCreateView(ViewTestCase):
'description': """
Cupiditate harum reprehenderit ipsam iure consequuntur eaque eos reiciendis. Blanditiis vel minima minus repudiandae voluptate aut quia sed. Provident ex omnis illo molestiae. Ullam eos et est provident enim deserunt.
""",
'images': [image]
'filename': [image]
}
)
self.assertHttpRedirect(response)
@ -170,6 +171,86 @@ class TestPlaceCreateView(ViewTestCase):
msg='Expecting the place to have exactly 1 place image'
)
def test_negative_no_name(self):
self.client.login(username='testpeter', password='Develop123')
response = self.client.post(
reverse('place_create'),
{
'location': 'test location 456',
'latitude': 45.804192,
'longitude': 1.860222,
'description': """
Cupiditate harum reprehenderit ipsam iure consequuntur eaque eos reiciendis. Blanditiis vel minima minus repudiandae voluptate aut quia sed. Provident ex omnis illo molestiae. Ullam eos et est provident enim deserunt.
"""
}
)
self.assertHttpBadRequest(response)
self.assertEqual(
len(Place.objects.filter(location='test location 456')),
0,
msg='Expecting no place to be created'
)
def test_negative_no_location(self):
self.client.login(username='testpeter', password='Develop123')
response = self.client.post(
reverse('place_create'),
{
'name': 'test name 376',
'latitude': 45.804192,
'longitude': 1.860222,
'description': """
Cupiditate harum reprehenderit ipsam iure consequuntur eaque eos reiciendis. Blanditiis vel minima minus repudiandae voluptate aut quia sed. Provident ex omnis illo molestiae. Ullam eos et est provident enim deserunt.
"""
}
)
self.assertHttpBadRequest(response)
self.assertEqual(
len(Place.objects.filter(name='test name 376')),
0,
msg='Expecting no place to be created'
)
def test_negative_no_latitude(self):
self.client.login(username='testpeter', password='Develop123')
response = self.client.post(
reverse('place_create'),
{
'name': 'test name 417',
'location': 'location',
'longitude': 1.860222,
'description': """
Cupiditate harum reprehenderit ipsam iure consequuntur eaque eos reiciendis. Blanditiis vel minima minus repudiandae voluptate aut quia sed. Provident ex omnis illo molestiae. Ullam eos et est provident enim deserunt.
"""
}
)
self.assertHttpBadRequest(response)
self.assertEqual(
len(Place.objects.filter(name='test name 417')),
0,
msg='Expecting no place to be created'
)
def test_negative_no_longitude(self):
self.client.login(username='testpeter', password='Develop123')
response = self.client.post(
reverse('place_create'),
{
'name': 'test name 417',
'location': 'location',
'latitude': 45.804192,
'description': """
Cupiditate harum reprehenderit ipsam iure consequuntur eaque eos reiciendis. Blanditiis vel minima minus repudiandae voluptate aut quia sed. Provident ex omnis illo molestiae. Ullam eos et est provident enim deserunt.
"""
}
)
self.assertHttpBadRequest(response)
self.assertEqual(
len(Place.objects.filter(name='test name 417')),
0,
msg='Expecting no place to be created'
)
class PlaceDetailViewTestCase(TaggableViewTestCaseMixin, MapableViewTestCaseMixin, ViewTestCase):
view = PlaceDetailView

View File

@ -111,7 +111,8 @@ class PlaceCreateView(MultiplePlaceImageUploadMixin, IsAuthenticatedMixin, View)
context={
'place_form': place_form,
'place_image_form': PlaceImageForm()
}
},
status=400
)
class PlaceDeleteView(IsAuthenticatedMixin, IsPlaceSubmitterMixin, DeleteView):