def test_get_success_url_redirects_to_trip_detail(self):
     request = self.factory.get('/fake/')
     request.user = self.user
     view = LocationDeleteView()
     kwargs = {
         'trip_id': self.trip.id,
         'location_type': 'camp',
         'pk': self.triplocation.id
     }
     view = setup_view(view, request, **kwargs)
     success_url = view.get_success_url()
     intended_url = reverse('trips:trip_detail', args=(self.trip.id, ))
     self.assertEqual(success_url, intended_url)
 def test_get_request_raises_exception_with_invalid_location_type(self):
     """
     When a get request is sent with an invalid location_type, a
     ValueError will be raised
     """
     request = self.factory.get('/fake/')
     request.user = self.user
     view = LocationDeleteView()
     kwargs = {
         'trip_id': self.trip.id,
         'location_type': 'invalid',
         'pk': self.triplocation.id
     }
     view = setup_view(view, request, **kwargs)
     test = lambda: view.get(request, **kwargs)
     self.assertRaises(Http404, test)
 def test_get_context_data_includes_key_trip_id(self):
     '''
     The get_context_data includes key 'trip_id'
     '''
     request = self.factory.get('/fake/')
     request.user = self.user
     view = LocationDeleteView()
     kwargs = {
         'trip_id': self.trip.id,
         'location_type': 'camp',
         'pk': self.triplocation.id
     }
     view = setup_view(view, request, **kwargs)
     view.get(request, **kwargs)
     context = view.get_context_data()
     self.assertIn('trip_id', context)
 def test_post_request_redirects_to_login_if_user_not_logged_in(self):
     request = self.factory.post('/fake/')
     request.user = ''
     response = LocationDeleteView.as_view()(request)
     self.assertEqual(response.status_code, 302)
     redirect_url = reverse('authentication:login') + '?next=' + '/fake/'
     self.assertEqual(response.url, redirect_url)
 def test_value_of_instance_variables_set_through_get_camp(self):
     """
     When a get request is sent with location_type=camp in the url,
     the view will set instance variables
     """
     request = self.factory.get('/fake/')
     request.user = self.user
     view = LocationDeleteView()
     kwargs = {
         'trip_id': self.trip.id,
         'location_type': 'camp',
         'pk': self.triplocation.id
     }
     view = setup_view(view, request, **kwargs)
     view.get(request, **kwargs)
     self.assertEqual(view.page_title, 'Delete camp')
     self.assertEqual(view.submit_button_title, 'Delete Camp')
 def test_view_sets_instance_variables_through_post_request(self):
     """
     When a post request is sent, the view will set instance variables
     to be used later in the context
     """
     request = self.factory.post('/fake/')
     request.user = self.user
     view = LocationDeleteView()
     kwargs = {
         'trip_id': self.trip.id,
         'location_type': 'trailhead',
         'pk': self.triplocation.id
     }
     view = setup_view(view, request, **kwargs)
     view.get(request, **kwargs)
     self.assertIsNotNone(view.page_title)
     self.assertIsNotNone(view.submit_button_title)
 def test_view_uses_correct_template(self):
     request = self.factory.get('/fake/')
     request.user = self.user
     response = LocationDeleteView.as_view()(request,
                                             trip_id=self.trip.id,
                                             location_type='trailhead',
                                             pk=self.triplocation.id)
     self.assertTrue('trips/delete.html' in response.template_name)
 def test_200_response_from_get_request(self):
     request = self.factory.get('/fake/')
     request.user = self.user
     response = LocationDeleteView.as_view()(request,
                                             trip_id=self.trip.id,
                                             location_type='camp',
                                             pk=self.triplocation.id)
     self.assertEqual(response.status_code, 200)