Commit 60547524 authored by Lance Michael O. Co's avatar Lance Michael O. Co 😢

Fixed the Functional Test

parent 0af9bf8d
#froyo/tests #froyo/tests
from django.test import TestCase from django.test import TestCase
#home page tests
class HomePageTest(TestCase): class HomePageTest(TestCase):
def test_uses_home_template(self): def test_uses_home_template(self):
...@@ -9,6 +9,27 @@ class HomePageTest(TestCase): ...@@ -9,6 +9,27 @@ class HomePageTest(TestCase):
self.assertTemplateUsed(response, 'home.html') self.assertTemplateUsed(response, 'home.html')
class IngredientsHomePageTest(TestCase):
def test_uses_home_template(self):
response = self.client.get('/ingredients')
self.assertTemplateUsed(response, 'ingredients.html')
class RecipesHomePageTest(TestCase):
def test_uses_home_template(self):
response = self.client.get('/recipes')
self.assertTemplateUsed(response, 'recipes.html')
class OrdersHomePageTest(TestCase):
def test_uses_home_template(self):
response = self.client.get('/orders')
self.assertTemplateUsed(response, 'orders.html')
#ingredients tests #ingredients tests
class IngredientsListTest(TestCase): class IngredientsListTest(TestCase):
......
#froyo/urls #froyo/urls
from django.conf.urls import url from django.conf.urls import url
from .views import HomeView, IngredientsList, IngredientsDetail, IngredientsUpdate, IngredientsCreate, RecipesList, RecipesDetail, RecipesUpdate, RecipesCreate, OrdersList, OrdersDetail, OrdersUpdate, OrdersCreate from .views import (HomeView, IngredientsHomeView, RecipesHomeView, OrdersHomeView,
IngredientsList, IngredientsDetail, IngredientsUpdate, IngredientsCreate,
RecipesList, RecipesDetail, RecipesUpdate, RecipesCreate,
OrdersList, OrdersDetail, OrdersUpdate, OrdersCreate)
urlpatterns = [ urlpatterns = [
url(r'^$', HomeView, name='home_page'), #home urls
url(r'^$', HomeView.as_view(), name='home_page'),
url(r'^ingredients$', IngredientsHomeView.as_view(), name='ingredients'),
url(r'^recipes$', RecipesHomeView.as_view(), name='recipes'),
url(r'^orders$', OrdersHomeView.as_view(), name='orders'),
#ingredients urls #ingredients urls
url(r'^ingredients/list$', IngredientsList.as_view(), name='ingredients-list'), url(r'^ingredients/list$', IngredientsList.as_view(), name='ingredients-list'),
......
...@@ -5,11 +5,23 @@ from django.views.generic.detail import DetailView ...@@ -5,11 +5,23 @@ from django.views.generic.detail import DetailView
from django.views.generic.edit import UpdateView from django.views.generic.edit import UpdateView
from django.views.generic.edit import CreateView from django.views.generic.edit import CreateView
#Home Pages
class HomeView(TemplateView): class HomeView(TemplateView):
template_name = "home.html" template_name = "home.html"
class IngredientsHomeView(TemplateView):
template_name = "ingredients.html"
class RecipesHomeView(TemplateView):
template_name = "recipes.html"
class OrdersHomeView(TemplateView):
template_name = "orders.html"
#Ingredients #Ingredients
class IngredientsList(ListView): class IngredientsList(ListView):
template_name = "ingredients_list.html" template_name = "ingredients_list.html"
......
...@@ -20,32 +20,288 @@ class NewVisitorTest(unittest.TestCase): ...@@ -20,32 +20,288 @@ class NewVisitorTest(unittest.TestCase):
self.assertIn('The Good Place FroYo Shop', self.browser.title) self.assertIn('The Good Place FroYo Shop', self.browser.title)
#user sees 3 links (orders, ingredients, recipes) #user sees 3 links (orders, ingredients, recipes)
self.browser.get('http://localhost:8000/ingredients') orders = self.browser.find_element_by_id('orders')
self.browser.get('http://localhost:8000/recipes') ingredients = self.browser.find_element_by_id('ingredients')
self.browser.get('http://localhost:8000/orders') recipes = self.browser.find_element_by_id('recipes')
def test_can_see_and_use_ingredients_page(self): def test_can_see_and_use_ingredients_page(self):
#user goes to orders page #user clicks on ingredients page
self.browser.get('http://localhost:8000/ingredients') self.browser.get('http://localhost:8000')
ingredients.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/ingredients',
self.browser.current_url
)
#user checks page title to ensure he's at the right page #user checks page title to ensure he's at the right page
self.assertIn('Orders', self.browser.title) self.assertIn('Ingredients', self.browser.title)
#user sees 4 links all dealing with what he can do with ingredients.
#After each success he is returned to the home page of the ingredients.
ingredients_create = self.browser.find_element_by_id('ingredients-create-form')
ingredients_detail = self.browser.find_element_by_id('ingredients-detail')
ingredients_list = self.browser.find_element_by_id('ingredients-list')
ingredients_update = self.browser.find_element_by_id('ingredients-update-form')
#user also sees a link to take him back to the home page
back = self.browser.find_element_by_id('back_to_home_page')
#user checks list of ingredients
ingredients_list.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/ingredients/list',
self.browser.current_url
)
#user checks page title to ensure he's in the right page
self.assertIn('Ingredients - List'. self.browser.title)
#satisfied, user goes back to the ingredients page
self.browser.get('http://localhost:8000/ingredients')
#seeing that an ingredient is missing, user creates an ingredient
ingredients_create.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/ingredients/create_form',
self.browser.current_url
)
#user checks page title to ensure he's in the right page
self.assertIn('Ingredients - Create'. self.browser.title)
#satisfied, user goes back to the ingredients page
self.browser.get('http://localhost:8000/ingredients')
#user then checks the details of the ingredient
ingredients_detail.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/ingredients/detail',
self.browser.current_url
)
#user checks page title to ensure he's in the right page
self.assertIn('Ingredients - Detail'. self.browser.title)
#satisfied, user goes back to the ingredients page
self.browser.get('http://localhost:8000/ingredients')
#noticing something is missing, the user updates the ingredient
ingredients_update.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/ingredients/update',
self.browser.current_url
)
#user checks page title to ensure he's in the right page
self.assertIn('Ingredients - Update'. self.browser.title)
#satisfied, user goes back to the ingredients page
self.browser.get('http://localhost:8000/ingredients')
#finished checking the ingredients, the user then returns to the home page
back.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/',
self.browser.current_url
)
def test_can_see_and_use_recipes_page(self): def test_can_see_and_use_recipes_page(self):
#user goes to orders page #user clicks on recipes page
self.browser.get('http://localhost:8000/recipes') self.browser.get('http://localhost:8000')
recipes.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/recipes',
self.browser.current_url
)
#user checks page title to ensure he's at the right page #user checks page title to ensure he's at the right page
self.assertIn('Orders', self.browser.title) self.assertIn('Recipes', self.browser.title)
#user sees 4 links all dealing with what he can do with recipes.
#After each success he is returned to the home page of the recipes.
recipes_create = self.browser.find_element_by_id('recipes-create-form')
recipes_detail = self.browser.find_element_by_id('recipes-detail')
recipes_list = self.browser.find_element_by_id('recipes-list')
recipes_update = self.browser.find_element_by_id('recipes-update-form')
#user also sees a link to take him back to the home page
back = self.browser.find_element_by_id('back_to_home_page')
#user checks list of recipes
recipes_list.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/recipes/list',
self.browser.current_url
)
#user checks page title to ensure he's in the right page
self.assertIn('Recipes - List'. self.browser.title)
#satisfied, user goes back to the recipes page
self.browser.get('http://localhost:8000/recipes')
#seeing that an recipe is missing, user creates an recipe
recipes_create.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/recipes/create_form',
self.browser.current_url
)
#user checks page title to ensure he's in the right page
self.assertIn('Recipes - Create'. self.browser.title)
#satisfied, user goes back to the recipes page
self.browser.get('http://localhost:8000/recipes')
#user then checks the details of the recipe
recipes_detail.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/recipes/detail',
self.browser.current_url
)
#user checks page title to ensure he's in the right page
self.assertIn('Recipes - Detail'. self.browser.title)
#satisfied, user goes back to the recipes page
self.browser.get('http://localhost:8000/recipes')
#noticing something is missing, the user updates the recipe
recipes_update.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/recipes/update',
self.browser.current_url
)
#user checks page title to ensure he's in the right page
self.assertIn('Recipes - Update'. self.browser.title)
#satisfied, user goes back to the recipes page
self.browser.get('http://localhost:8000/recipes')
#finished checking the recipes, the user then returns to the home page
back.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/',
self.browser.current_url
)
def test_can_see_and_use_orders_page(self): def test_can_see_and_use_orders_page(self):
#user goes to orders page #user clicks on orders page
self.browser.get('http://localhost:8000/orders') self.browser.get('http://localhost:8000')
orders.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/orders',
self.browser.current_url
)
#user checks page title to ensure he's at the right page #user checks page title to ensure he's at the right page
self.assertIn('Orders', self.browser.title) self.assertIn('Orders', self.browser.title)
#user sees 4 links all dealing with what he can do with orders.
#After each success he is returned to the home page of the orders.
orders_create = self.browser.find_element_by_id('orders-create-form')
orders_detail = self.browser.find_element_by_id('orders-detail')
orders_list = self.browser.find_element_by_id('orders-list')
orders_update = self.browser.find_element_by_id('orders-update-form')
#user also sees a link to take him back to the home page
back = self.browser.find_element_by_id('back_to_home_page')
#user checks list of orders
orders_list.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/orders/list',
self.browser.current_url
)
#user checks page title to ensure he's in the right page
self.assertIn('Orders - List'. self.browser.title)
#satisfied, user goes back to the orders page
self.browser.get('http://localhost:8000/orders')
#seeing that an order is missing, user creates an order
orders_create.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/orders/create_form',
self.browser.current_url
)
#user checks page title to ensure he's in the right page
self.assertIn('Orders - Create'. self.browser.title)
#satisfied, user goes back to the orders page
self.browser.get('http://localhost:8000/orders')
#user then checks the details of the order
orders_detail.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/orders/detail',
self.browser.current_url
)
#user checks page title to ensure he's in the right page
self.assertIn('Orders - Detail'. self.browser.title)
#satisfied, user goes back to the orders page
self.browser.get('http://localhost:8000/orders')
#noticing something is missing, the user updates the order
orders_update.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/orders/update',
self.browser.current_url
)
#user checks page title to ensure he's in the right page
self.assertIn('Orders - Update'. self.browser.title)
#satisfied, user goes back to the orders page
self.browser.get('http://localhost:8000/orders')
#finished checking the orders, the user then returns to the home page
back.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/',
self.browser.current_url
)
if __name__='__main__': if __name__='__main__':
......
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