400 Response when submitting invalid place data and testing more edge cases
This commit is contained in:
		@@ -126,49 +126,130 @@ class TestPlaceCreateView(ViewTestCase):
 | 
				
			|||||||
            )
 | 
					            )
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        def test_positive_image(self):
 | 
					    def test_positive_image(self):
 | 
				
			||||||
            self.client.login(username='testpeter', password='Develop123')
 | 
					        self.client.login(username='testpeter', password='Develop123')
 | 
				
			||||||
            image = open(
 | 
					        image = open(
 | 
				
			||||||
                path.join(
 | 
					            path.join(
 | 
				
			||||||
                    settings.BASE_DIR,
 | 
					                settings.BASE_DIR,
 | 
				
			||||||
                    'testdata',
 | 
					                'testdata',
 | 
				
			||||||
                    'test_image.jpg'
 | 
					                'test_image.jpg'
 | 
				
			||||||
                )
 | 
					 | 
				
			||||||
            )
 | 
					 | 
				
			||||||
            response = self.client.post(
 | 
					 | 
				
			||||||
                reverse('place_create'),
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    'name': 'test place 894',
 | 
					 | 
				
			||||||
                    'location': 'test location',
 | 
					 | 
				
			||||||
                    '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.
 | 
					 | 
				
			||||||
                    """,
 | 
					 | 
				
			||||||
                    'images': [image]
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            )
 | 
					 | 
				
			||||||
            self.assertHttpRedirect(response)
 | 
					 | 
				
			||||||
            place =  Place.objects.get(name='test place 894')
 | 
					 | 
				
			||||||
            self.assertNotEqual(
 | 
					 | 
				
			||||||
                None,
 | 
					 | 
				
			||||||
                place,
 | 
					 | 
				
			||||||
                msg='Submitted place not found in database / model'
 | 
					 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
            self.assertNotEqual(
 | 
					            'rb'
 | 
				
			||||||
                None,
 | 
					        )
 | 
				
			||||||
                re.search(
 | 
					        response = self.client.post(
 | 
				
			||||||
                    """.*%s""" % reverse(
 | 
					            reverse('place_create'),
 | 
				
			||||||
                        'place_detail', kwargs={'pk': place.id}
 | 
					            {
 | 
				
			||||||
                    ),
 | 
					                'name': 'test place 894',
 | 
				
			||||||
                    response.url
 | 
					                'location': 'test location',
 | 
				
			||||||
                )
 | 
					                'latitude': 45.804192,
 | 
				
			||||||
            )
 | 
					                'longitude': 1.860222,
 | 
				
			||||||
            self.assertEqual(
 | 
					                'description': """
 | 
				
			||||||
                len(place.placeimages.all()),
 | 
					                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.
 | 
				
			||||||
                1,
 | 
					                """,
 | 
				
			||||||
                msg='Expecting the place to have exactly 1 place image'
 | 
					                'filename': [image]
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        self.assertHttpRedirect(response)
 | 
				
			||||||
 | 
					        place =  Place.objects.get(name='test place 894')
 | 
				
			||||||
 | 
					        self.assertNotEqual(
 | 
				
			||||||
 | 
					            None,
 | 
				
			||||||
 | 
					            place,
 | 
				
			||||||
 | 
					            msg='Submitted place not found in database / model'
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
 | 
					        self.assertNotEqual(
 | 
				
			||||||
 | 
					            None,
 | 
				
			||||||
 | 
					            re.search(
 | 
				
			||||||
 | 
					                """.*%s""" % reverse(
 | 
				
			||||||
 | 
					                    'place_detail', kwargs={'pk': place.id}
 | 
				
			||||||
 | 
					                ),
 | 
				
			||||||
 | 
					                response.url
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        self.assertEqual(
 | 
				
			||||||
 | 
					            len(place.placeimages.all()),
 | 
				
			||||||
 | 
					            1,
 | 
				
			||||||
 | 
					            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):
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user