Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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')
Ejemplo n.º 5
0
 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)