400 Response when submitting invalid place data and testing more edge cases
This commit is contained in:
parent
b0bf40aa0b
commit
4f465b3162
@ -133,7 +133,8 @@ class TestPlaceCreateView(ViewTestCase):
|
|||||||
settings.BASE_DIR,
|
settings.BASE_DIR,
|
||||||
'testdata',
|
'testdata',
|
||||||
'test_image.jpg'
|
'test_image.jpg'
|
||||||
)
|
),
|
||||||
|
'rb'
|
||||||
)
|
)
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
reverse('place_create'),
|
reverse('place_create'),
|
||||||
@ -145,7 +146,7 @@ class TestPlaceCreateView(ViewTestCase):
|
|||||||
'description': """
|
'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.
|
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)
|
self.assertHttpRedirect(response)
|
||||||
@ -170,6 +171,86 @@ class TestPlaceCreateView(ViewTestCase):
|
|||||||
msg='Expecting the place to have exactly 1 place image'
|
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):
|
class PlaceDetailViewTestCase(TaggableViewTestCaseMixin, MapableViewTestCaseMixin, ViewTestCase):
|
||||||
view = PlaceDetailView
|
view = PlaceDetailView
|
||||||
|
|
||||||
|
@ -111,7 +111,8 @@ class PlaceCreateView(MultiplePlaceImageUploadMixin, IsAuthenticatedMixin, View)
|
|||||||
context={
|
context={
|
||||||
'place_form': place_form,
|
'place_form': place_form,
|
||||||
'place_image_form': PlaceImageForm()
|
'place_image_form': PlaceImageForm()
|
||||||
}
|
},
|
||||||
|
status=400
|
||||||
)
|
)
|
||||||
|
|
||||||
class PlaceDeleteView(IsAuthenticatedMixin, IsPlaceSubmitterMixin, DeleteView):
|
class PlaceDeleteView(IsAuthenticatedMixin, IsPlaceSubmitterMixin, DeleteView):
|
||||||
|
Loading…
Reference in New Issue
Block a user