def test_home_view_returns_context_data_with_hero_image(self): """Test home view returns context data with hero image.""" from imagersite.views import HomeView view = HomeView() data = view.get_context_data() self.assertIn('hero_img_url', data) self.assertEqual('High-Five', data['hero_img_title'])
def test_home_view_returns_context_with_photo_from_db(self): """Test that the homeview returns photo from db.""" from imagersite.views import HomeView user = UserFactory() user.set_password('password') user.save() photo = PhotoFactory(user=user, title='test', published='PUBLIC') photo.save() view = HomeView() data = view.get_context_data() self.assertIn('hero_img_url', data) self.assertEqual('test', data['hero_img_title'])
def test_home_view_status(self): """Test home view is accessible.""" from imagersite.views import HomeView req = self.request.get(reverse_lazy('home')) view = HomeView.as_view() response = view(req) self.assertEqual(response.status_code, 200)
def test_home_view_returns_status_ok(self): """Test that the home view returns a status 200 code.""" from imagersite.views import HomeView request = self.request.get('/') view = HomeView.as_view() response = view(request) self.assertEqual(response.status_code, 200)
def test_home_page_displays_photo(self): """Test that there is a photo on the home page.""" from imagersite.views import HomeView photo = Photo.objects.first() photo.published = 'PUBLIC' photo.title = 'random home photo' photo.save() request = self.request.get('/') view = HomeView.as_view() response = view(request) soup = Soup(response.rendered_content, 'html.parser') photos = soup.find_all('img') self.assertEqual(len(photos), 1)
from django.conf.urls import url, include from django.contrib import admin from django.conf import settings from django.views.generic import DetailView, ListView, TemplateView from django.conf.urls.static import static from imager_images.models import Photo, Album from django.contrib.auth.models import User from imager_profile.models import UserProfile from imagersite.views import ProfileView, PhotoCreate, PhotoView, AlbumView, AlbumsetView, PhotosetView, TagIndexView, AlbumCreate, OtherProfileView, HomeView, PhotoUpdate, AlbumUpdate from django.contrib.auth import views as auth_views # from imagersite.imagersite import views as core_views urlpatterns = [ url(r'^$', HomeView.as_view(template_name='imagersite/home.html', model=Photo, queryset=Photo.objects.all(), context_object_name='photos'), name='home'), url(r'^oauth/', include('social_django.urls', namespace='social')), url(r'^admin/', admin.site.urls), url(r'^accounts/', include('registration.backends.hmac.urls')), url(r'^login/$', auth_views.login, {'template_name': 'registration/login.html'}, name='login'), url(r'^logout/$', auth_views.logout, {'next_page': '/'}, name='logout'), url(r'^accounts/profile/$', ProfileView.as_view(template_name='imagersite/profile.html', model=UserProfile, context_object_name="user"), name='profile'), url(r'^tag/(?P<slug>[-\w]+)/$',
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf import settings from django.conf.urls import include, url from django.contrib import admin from django.conf.urls.static import static from imagersite.views import HomeView from django.contrib.auth.views import login, logout urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^$', HomeView.as_view(template_name='imagersite/home.html'), name='home'), url(r'^login/$', login, {'template_name': 'imagersite/login.html'}, name="login"), url(r'^logout/$', logout, {'next_page': '/'}, name="logout"), url(r'^accounts/', include('registration.backends.hmac.urls')), url(r'^profile/', include('imager_profile.urls')), url(r'^images/', include('imager_images.urls')) ] if settings.DEBUG: urlpatterns += static(
The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.10/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf.urls import url, include from django.contrib import admin from imagersite.views import HomeView from django.contrib.auth import views as auth_views from django.conf import settings from django.conf.urls.static import static urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^$', HomeView.as_view(), name='home'), url(r'^login/$', auth_views.login, name='login'), url(r'^logout/$', auth_views.logout, name='logout'), url(r'^registration/', include("registration.backends.hmac.urls")), url(r'^profile/', include("imager_profile.urls")), url(r'^images/', include("imager_images.urls")) ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
def test_home_view_returns_status_code_200(self): """Test home view has status 200.""" request = RequestFactory().get('/') view = HomeView.as_view(template_name='home.html') response = view(request) self.assertTrue(response.status_code == 200)