Created Unit Test to Detect if template is found

parent ed35d549
<html>
<head>
<title>Lets Make Froyo</title>
</head>
<body>
<h1 id="Froyo Heading">Froyo</h1>
<dl>
<dt>Ingredients</dt>
<dt>Recipes</dt>
<dt>Orders</dt>
</dl>
</body>
</html>
\ No newline at end of file
from django.test import TestCase from django.test import TestCase
from django.urls import resolve
from django.http import HttpRequest
# Create your tests here. from .views import home_page
class PageTest(TestCase):
def test_home_page_is(self):
response = self.client.get('/froyo')
self.assertTemplateUsed(response, 'homepage.html')
\ No newline at end of file
...@@ -14,8 +14,7 @@ from .views import orders_update_form_page ...@@ -14,8 +14,7 @@ from .views import orders_update_form_page
from .views import orders_create_form_page from .views import orders_create_form_page
urlpatterns = [ urlpatterns = [
url(r'^$', home_page.as_view(), name = 'home_page'), url(r'^froyo$', home_page.as_view(), name = 'home_page'),
url(r'^froyo/$', home_page.as_view(), name = 'home_page'),
url(r'^froyo/ingredients_list$', ingredients_list_page.as_view(), name = 'ingredients_list'), url(r'^froyo/ingredients_list$', ingredients_list_page.as_view(), name = 'ingredients_list'),
url(r'^froyo/ingredients_detail$', ingredients_detail_page.as_view(), name = 'ingredients_detail'), url(r'^froyo/ingredients_detail$', ingredients_detail_page.as_view(), name = 'ingredients_detail'),
url(r'^froyo/ingredients_update_form$', ingredients_update_form_page.as_view(), name = 'ingredients_update_form'), url(r'^froyo/ingredients_update_form$', ingredients_update_form_page.as_view(), name = 'ingredients_update_form'),
......
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
class home_page(TemplateView): class home_page(TemplateView):
template_name = 'froyo/homepage.html' template_name = 'homepage.html'
class ingredients_list_page(TemplateView): class ingredients_list_page(TemplateView):
template_name = 'froyo/ingredients_list.html' template_name = 'ingredients_list.html'
class ingredients_detail_page(TemplateView): class ingredients_detail_page(TemplateView):
template_name = 'froyo/ingredients_detail.html' template_name = 'ingredients_detail.html'
class ingredients_update_form_page(TemplateView): class ingredients_update_form_page(TemplateView):
template_name = 'froyo/ingredients_update_form.html' template_name = 'ingredients_update_form.html'
class ingredients_create_form_page(TemplateView): class ingredients_create_form_page(TemplateView):
template_name = 'froyo/ingredients_create_form.html' template_name = 'ingredients_create_form.html'
class recipes_list_page(TemplateView): class recipes_list_page(TemplateView):
template_name = 'froyo/recipes_list.html' template_name = 'recipes_list.html'
class recipes_detail_page(TemplateView): class recipes_detail_page(TemplateView):
template_name = 'froyo/recipes_detail.html' template_name = 'recipes_detail.html'
class recipes_update_form_page(TemplateView): class recipes_update_form_page(TemplateView):
template_name = 'froyo/recipes_update_form.html' template_name = 'recipes_update_form.html'
class recipes_create_form_page(TemplateView): class recipes_create_form_page(TemplateView):
template_name = 'froyo/recipes_create_form.html' template_name = 'recipes_create_form.html'
class orders_list_page(TemplateView): class orders_list_page(TemplateView):
template_name = 'froyo/orders_list.html' template_name = 'orders_list.html'
class orders_detail_page(TemplateView): class orders_detail_page(TemplateView):
template_name = 'froyo/orders_detail.html' template_name = 'orders_detail.html'
class orders_update_form_page(TemplateView): class orders_update_form_page(TemplateView):
template_name = 'froyo/orders_update_form.html' template_name = 'orders_update_form.html'
class orders_create_form_page(TemplateView): class orders_create_form_page(TemplateView):
template_name = 'froyo/orders_create_form.html' template_name = 'orders_create_form.html'
from selenium import webdriver from selenium import webdriver
import unittest import unittest
class NewVisitorTest(unittest.TestCase): class NewVisitorTest(unittest.TestCase):
\ No newline at end of file def setUp(self):
self.browser = webdriver.Firefox()
def tearDown(self):
self.browser.quit()
def test_can_display_models_and_their_views(self):
self.browser.get('http://localhost:8000')
# Check if the title of the homepage is Let's Make Froyo
self.assertIn('Lets Make Froyo', self.browser.title)
self.fail('Finish the test!')
if __name__ == '__main__':
unittest.main(warnings='ignore')
\ No newline at end of file
...@@ -37,6 +37,7 @@ INSTALLED_APPS = [ ...@@ -37,6 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'froyo'
] ]
MIDDLEWARE = [ MIDDLEWARE = [
...@@ -47,6 +48,7 @@ MIDDLEWARE = [ ...@@ -47,6 +48,7 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
] ]
ROOT_URLCONF = 'superlists.urls' ROOT_URLCONF = 'superlists.urls'
...@@ -54,7 +56,7 @@ ROOT_URLCONF = 'superlists.urls' ...@@ -54,7 +56,7 @@ ROOT_URLCONF = 'superlists.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
......
...@@ -13,7 +13,7 @@ Including another URLconf ...@@ -13,7 +13,7 @@ Including another URLconf
1. Import the include() function: from django.conf.urls import url, include 1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
""" """
from django.conf.urls import url from django.conf.urls import include,url
from django.contrib import admin from django.contrib import admin
urlpatterns = [ urlpatterns = [
......
...@@ -55,7 +55,7 @@ ROOT_URLCONF = 'thegoodplace.urls' ...@@ -55,7 +55,7 @@ ROOT_URLCONF = 'thegoodplace.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
......
...@@ -13,9 +13,10 @@ Including another URLconf ...@@ -13,9 +13,10 @@ Including another URLconf
1. Import the include() function: from django.conf.urls import url, include 1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
""" """
from django.conf.urls import url from django.conf.urls import url, include
from django.contrib import admin from django.contrib import admin
urlpatterns = [ urlpatterns = [
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
url(r'', include('froyo.urls')),
] ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment