Commit 0b2f51e9 authored by littleredpanda14's avatar littleredpanda14

Created a functional test

parent 975b07de
import unittest
import time
from selenium import webdriver
class WelcomeToTheGoodPlaceTest(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox()
def tearDown(self):
self.browser.quit()
def test_can_summon_janet_with_all_froyo_info(self):
# Eleanor wants to find out more about the Froyo Shop
# She calls on The Good Place's omniscient database Janet to find out more.
self.browser.get('http://localhost:8000')
# She summons Janet, and is met with the response (header and title)
# 'Hi. My name is Janet.'
self.assertIn('Hi. My name is Janet.', self.browser.title)
#Janet gives Eleanor all the information she has on the Froyo shop which includes:
#Ingredients, Recipes and Orders
froyo = self.browser.find_element_by_id('janet')
self.assertEqual(
'ul',
froyo.tag_name
)
# When she asks for information about the Ingredients, Janet sends her to another page
# which has the list of ingredients.
ingredients = self.browser.find_element_by_id('ingredients_list')
ingredients.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/froyo/ingredients',
self.browser.getCurrentUrl()
)
# It is called the 'Ingredients - List' Janet tells her.
self.assertIn('Ingredients - List', self.browser.title)
# Eleanor asks Janet to give more specific details on each item on the list
# so Janet sends her to a different page depending on the ingredient Eleanor has selected
ingredients_detail = self.browser.find_element_by_id('almonds')
ingredients_detail.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/froyo/ingredients/almonds',
self.browser.getCurrentUrl()
)
# Eleanor wants to update the ingredient information because she can. So she asks Janet
# to give her an ingredients update form.
ingredients_update_form = self.browser.find_element_by_id('ingredients_update')
ingredients_update_form.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/froyo/ingredients/update',
self.browser.getCurrentUrl()
)
# Eleanor then decides that she wants to create new ingredients for the inventory.
# She asks Janet to provide an ingredients create form for her to use.
ingredients_create_form = self.browser.find_element_by_id('ingredients_create')
ingredients_create_form.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/froyo/ingredients/create',
self.browser.getCurrentUrl()
)
# While she browsing through any specific janet page (either ingredients, recipes or orders),
# she sees a button labeled "Back to Janet".
# She clicks this and is sent back to Janet.
back_button = self.browser.find_element_by_id('back_button')
self.assertEqual(
'Back to Janet',
back_button.text
)
back_button.click()
time.sleep(1)
self.assertEqual(
'http://localhost:8000/froyo/ingredients',
self.browser.getCurrentUrl()
)
self.fail('Finish the test!')
if __name__ == '__main__':
unittest.main(warnings='ignore')
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