def test_get_context_data_includes_key_cancel_button_path(self): request = self.factory.get('/fake/') request.user = self.user view = TripCreateView() kwargs = {} view = setup_view(view, request, **kwargs) view.object = Trip() context = view.get_context_data() self.assertIn('cancel_button_path', context)
def test_get_success_url_redirects_to_trip_detail(self): request = self.factory.get('/fake/') request.user = self.user view = TripCreateView() kwargs = {} view = setup_view(view, request, **kwargs) trip = Trip.objects.create(title='title', start_date=timezone.now().date()) view.object = trip success_url = view.get_success_url() intended_url = reverse('trips:trip_detail', args=(trip.id, )) self.assertEqual(success_url, intended_url)
def test_get_context_data_includes_key_page_title(self): ''' The get_context_data includes key 'page_title' ''' request = self.factory.get('/fake/') request.user = self.user view = TripCreateView() kwargs = {} view = setup_view(view, request, **kwargs) view.object = Trip() context = view.get_context_data() self.assertIn('page_title', context)
def test_post_request_redirects_to_login_if_user_not_logged_in(self): request = self.factory.post('/fake/') request.user = '' response = TripCreateView.as_view()(request) self.assertEqual(response.status_code, 302) redirect_url = reverse('authentication:login') + '?next=' + '/fake/' self.assertEqual(response.url, redirect_url)
def test_view_uses_correct_template(self): request = self.factory.get('/fake/') request.user = self.user response = TripCreateView.as_view()(request) self.assertTrue('trips/create.html' in response.template_name)
def test_200_response_from_get_request(self): request = self.factory.get('/fake/') request.user = self.user response = TripCreateView.as_view()(request) self.assertEqual(response.status_code, 200)