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_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_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)