def test_get_context_data_includes_key_camp_dict(self):
     request = self.factory.get('/fake/')
     request.user = self.user
     view = TripDetailView()
     kwargs = {'pk': self.trip.id}
     view = setup_view(view, request, **kwargs)
     view.object = self.trip
     context = view.get_context_data()
     self.assertIn('camp_dict', context)
 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 = TripDetailView()
     kwargs = {'pk': self.trip.id}
     view = setup_view(view, request, **kwargs)
     view.object = self.trip
     context = view.get_context_data()
     self.assertIn('detail_page_title', context)
 def test_get_context_data_returns_end_date_zero_night(self):
     '''
     The get_context_data does not return 'end_date' if the trip has
     number_nights==0
     '''
     request = self.factory.get('/fake/')
     request.user = self.user
     view = TripDetailView()
     kwargs = {'pk': self.trip.id}
     view = setup_view(view, request, **kwargs)
     view.object = self.trip
     context = view.get_context_data()
     self.assertNotIn('end_date', context)
 def test_get_context_data_includes_end_date_multi_night(self):
     '''
     The get_context_data includes a key 'end_date' if the trip has
     number_nights > 0
     '''
     request = self.factory.get('/fake/')
     request.user = self.user
     view = TripDetailView()
     kwargs = {'pk': self.trip.id}
     self.trip.number_nights = 1
     self.trip.save()
     view = setup_view(view, request, **kwargs)
     view.object = self.trip
     context = view.get_context_data()
     self.assertIn('end_date', context)
 def test_get_request_redirects_to_login_if_user_not_logged_in(self):
     request = self.factory.get('/fake/')
     request.user = ''
     response = TripDetailView.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 = TripDetailView.as_view()(request, pk=self.trip.id)
     self.assertTrue('trips/detail.html' in response.template_name)
 def test_200_response_from_get_request(self):
     request = self.factory.get('/fake/')
     request.user = self.user
     response = TripDetailView.as_view()(request, pk=self.trip.id)
     self.assertEqual(response.status_code, 200)
Beispiel #8
0
urlpatterns = [
    path('', home_view, name='home'),
    path('contact/', contact_view),
    path('product/', product_detail_view),
    path('create/', product_create_view),
    path('about/', about_view),
    path('admin/', admin.site.urls),
    # Login and Profile
    path('register/', user_views.register, name='register'),
    path('profile/', user_views.profile, name='profile'),
    path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'),
    path('logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name='logout'),
    # Flights
    path('flights/', search_flights_view, name='flights'),
    path('result_flights/', flights_results_view, name='result_flights'),
    path('add_flight/', add_flight, name='add_flight'),
    # Hotels
    path('hotels/<str:location>', search_hotels_view, name='hotels'),
    # Trips
    path('trips/', login_required(user_views.FlightListView.as_view()), name='trips'),
    path('dashboard/', login_required(TripsDashboard.as_view()), name='dashboard'),
    path('add_trip/', add_trip, name='add_trip'),
    path('add_image_url/', add_image_url, name='add_image_url'),
    path('trip/<int:pk>/', login_required(TripDetailView.as_view()), name='trip-detail')

]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)