diff --git a/functional_tests/__pycache__/__init__.cpython-38.pyc b/functional_tests/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..388874bd6b95d0b4dd15d9e42142087ef946c85e Binary files /dev/null and b/functional_tests/__pycache__/__init__.cpython-38.pyc differ diff --git a/functional_tests/__pycache__/base.cpython-38.pyc b/functional_tests/__pycache__/base.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..11a3958d80ba6f5832b5886830e62cdde4a4196f Binary files /dev/null and b/functional_tests/__pycache__/base.cpython-38.pyc differ diff --git a/functional_tests/__pycache__/test_layout_and_styling.cpython-38.pyc b/functional_tests/__pycache__/test_layout_and_styling.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e946463659fe69d4f57c70eaea0e7991d38c4627 Binary files /dev/null and b/functional_tests/__pycache__/test_layout_and_styling.cpython-38.pyc differ diff --git a/functional_tests/__pycache__/test_list_item_validation.cpython-38.pyc b/functional_tests/__pycache__/test_list_item_validation.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9238b98c92eb623d974e52f9733a53d33a8ff0c1 Binary files /dev/null and b/functional_tests/__pycache__/test_list_item_validation.cpython-38.pyc differ diff --git a/functional_tests/__pycache__/test_simple_list_creation.cpython-38.pyc b/functional_tests/__pycache__/test_simple_list_creation.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..dd48b6200ab12ecfbd4d9257708a7fe2ca58c07c Binary files /dev/null and b/functional_tests/__pycache__/test_simple_list_creation.cpython-38.pyc differ diff --git a/functional_tests/__pycache__/tests.cpython-38.pyc b/functional_tests/__pycache__/tests.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5da2e2d50fc8b00c1c33a7b4e18e7de76b4df5d2 Binary files /dev/null and b/functional_tests/__pycache__/tests.cpython-38.pyc differ diff --git a/functional_tests/base.py b/functional_tests/base.py new file mode 100644 index 0000000000000000000000000000000000000000..5ff22725e13468256f1829aa3d500066e211dcf3 --- /dev/null +++ b/functional_tests/base.py @@ -0,0 +1,28 @@ +from django.contrib.staticfiles.testing import StaticLiveServerTestCase +from selenium import webdriver +from selenium.webdriver.common.keys import Keys +from selenium.common.exceptions import WebDriverException +import time + + +MAX_WAIT = 10 +class FunctionalTest(StaticLiveServerTestCase): + + def setUp(self): + self.browser = webdriver.Firefox() + + def tearDown(self): + self.browser.quit() + + def wait_for_row_in_list_table(self, row_text): + start_time = time.time() + while True: + try: + table = self.browser.find_element_by_id('id_list_table') + rows = table.find_elements_by_tag_name('tr') + self.assertIn(row_text, [row.text for row in rows]) + return + except (AssertionError, WebDriverException) as e: + if time.time() - start_time > MAX_WAIT: + raise e + time.sleep(0.5) diff --git a/functional_tests/test_layout_and_styling.py b/functional_tests/test_layout_and_styling.py new file mode 100644 index 0000000000000000000000000000000000000000..a38bc5865b87e10010cd617712aca9671a6a5232 --- /dev/null +++ b/functional_tests/test_layout_and_styling.py @@ -0,0 +1,17 @@ +from selenium.webdriver.common.keys import Keys +from .base import FunctionalTest + +class LayoutAndStylingTest(FunctionalTest): + + def test_layout_and_styling(self): + # Edith goes to the home page + self.browser.get(self.live_server_url) + self.browser.set_window_size(1024, 768) + + # She notices the input box is nicely centered + inputbox = self.browser.find_element_by_id('id_new_item') + self.assertAlmostEqual( + inputbox.location['x'] + inputbox.size['width'] / 2, + 512, + delta=10 + ) \ No newline at end of file diff --git a/functional_tests/test_list_item_validation.py b/functional_tests/test_list_item_validation.py new file mode 100644 index 0000000000000000000000000000000000000000..2dcfcd9fe74be318ebf8f7a64e575de77bcaa8bc --- /dev/null +++ b/functional_tests/test_list_item_validation.py @@ -0,0 +1,10 @@ +from selenium.webdriver.common.keys import Keys +from unittest import skip +from .base import FunctionalTest + +class ItemValidationTest(FunctionalTest): + + @skip + def test_cannot_add_empty_list_items(self): + [...] + diff --git a/functional_tests/tests.py b/functional_tests/test_simple_list_creation.py similarity index 59% rename from functional_tests/tests.py rename to functional_tests/test_simple_list_creation.py index 362dee37e9ba887e92132db49df21b85d418b414..157e94eb0a9d57469b279f77120990bf1ab8f2fa 100644 --- a/functional_tests/tests.py +++ b/functional_tests/test_simple_list_creation.py @@ -1,44 +1,9 @@ -from django.contrib.staticfiles.testing import StaticLiveServerTestCase +from .base import FunctionalTest from selenium import webdriver from selenium.webdriver.common.keys import Keys -from selenium.common.exceptions import WebDriverException -import time -MAX_WAIT = 10 -class NewVisitorTest(StaticLiveServerTestCase): - - def setUp(self): - self.browser = webdriver.Firefox() - - def tearDown(self): - self.browser.quit() - - def test_layout_and_styling(self): - # Edith goes to the home page - self.browser.get(self.live_server_url) - self.browser.set_window_size(1024, 768) - - # She notices the input box is nicely centered - inputbox = self.browser.find_element_by_id('id_new_item') - self.assertAlmostEqual( - inputbox.location['x'] + inputbox.size['width'] / 2, - 512, - delta=10 - ) - - def wait_for_row_in_list_table(self, row_text): - start_time = time.time() - while True: - try: - table = self.browser.find_element_by_id('id_list_table') - rows = table.find_elements_by_tag_name('tr') - self.assertIn(row_text, [row.text for row in rows]) - return - except (AssertionError, WebDriverException) as e: - if time.time() - start_time > MAX_WAIT: - raise e - time.sleep(0.5) +class NewVisitorTest(FunctionalTest): def test_can_start_a_list_and_retrieve_it_later(self): # Edith has heard about a cool new online to-do app. She goes @@ -75,7 +40,3 @@ class NewVisitorTest(StaticLiveServerTestCase): # that the site has generated a unique URL for her -- there is some # explanatory text to that effect. # She visits that URL - her to-do list is still there - - -if __name__ == '__main__': - unittest.main(warnings='ignore') diff --git a/lists/tests.py b/lists/tests.py deleted file mode 100644 index 9fd32d32d51337835c583309d7e81963160692b7..0000000000000000000000000000000000000000 --- a/lists/tests.py +++ /dev/null @@ -1,62 +0,0 @@ -from django.urls import resolve -from django.test import TestCase -from django.http import HttpRequest - -from lists.views import home_page -from lists.models import Item - - -class HomePageTest(TestCase): - - def test_root_url_resolves_to_home_page_view(self): - found = resolve('/') - self.assertEqual(found.func, home_page) - def test_home_page_returns_correct_html(self): - request = HttpRequest() - response = home_page(request) - html = response.content.decode('utf8') - self.assertTrue(html.startswith('')) - self.assertIn('To-Do lists', html) - self.assertTrue(html.endswith('')) - def test_uses_home_template(self): - response = self.client.get('/') - self.assertTemplateUsed(response, 'home.html') - def test_can_save_a_POST_request(self): - response = self.client.post('/', data={'item_text': 'A new list item'}) - self.assertEqual(Item.objects.count(), 1) - new_item = Item.objects.first() - self.assertEqual(new_item.text, 'A new list item') - self.assertEqual(response.status_code, 302) - self.assertEqual(response['location'], '/') - def test_only_saves_items_when_necessary(self): - self.client.get('/') - self.assertEqual(Item.objects.count(), 0) - -class ItemModelTest(TestCase): - - def test_saving_and_retrieving_items(self): - first_item = Item() - first_item.text = 'The first (ever) list item' - first_item.save() - - second_item = Item() - second_item.text = 'Item the second' - second_item.save() - - saved_items = Item.objects.all() - self.assertEqual(saved_items.count(), 2) - - first_saved_item = saved_items[0] - second_saved_item = saved_items[1] - self.assertEqual(first_saved_item.text, 'The first (ever) list item') - self.assertEqual(second_saved_item.text, 'Item the second') - - def test_can_save_a_POST_request(self): - response = self.client.post('/', data={'item_text': 'A new list item'}) - - self.assertEqual(Item.objects.count(), 1) - new_item = Item.objects.first() - self.assertEqual(new_item.text, 'A new list item') - - self.assertIn('A new list item', response.content.decode()) - self.assertTemplateUsed(response, 'home.html') \ No newline at end of file diff --git a/lists/tests/__init__.py b/lists/tests/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/lists/tests/__pycache__/__init__.cpython-38.pyc b/lists/tests/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ae6c3e1154dfe7f2ef567703d906bcc5bd93fcab Binary files /dev/null and b/lists/tests/__pycache__/__init__.cpython-38.pyc differ diff --git a/lists/tests/__pycache__/test_all.cpython-38.pyc b/lists/tests/__pycache__/test_all.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..abe57bce4684a5481dba070e149ba2c970e9119f Binary files /dev/null and b/lists/tests/__pycache__/test_all.cpython-38.pyc differ diff --git a/lists/tests/__pycache__/test_models.cpython-38.pyc b/lists/tests/__pycache__/test_models.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3567afd232eee1185e4598ffefa134c42e793675 Binary files /dev/null and b/lists/tests/__pycache__/test_models.cpython-38.pyc differ diff --git a/lists/tests/__pycache__/test_views.cpython-38.pyc b/lists/tests/__pycache__/test_views.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7e58641e916623dc4b53f05300546ecb1182157b Binary files /dev/null and b/lists/tests/__pycache__/test_views.cpython-38.pyc differ diff --git a/lists/tests/test_models.py b/lists/tests/test_models.py new file mode 100644 index 0000000000000000000000000000000000000000..796d6870477efeb48cdf3b9d57030d9b012be133 --- /dev/null +++ b/lists/tests/test_models.py @@ -0,0 +1,65 @@ +from django.urls import resolve +from django.test import TestCase +from django.http import HttpRequest + +from lists.views import home_page +from lists.models import Item + + +class HomePageTest(TestCase): + + def test_root_url_resolves_to_home_page_view(self): + found = resolve('/') + self.assertEqual(found.func, home_page) + + def test_home_page_returns_correct_html(self): + request = HttpRequest() + response = home_page(request) + html = response.content.decode('utf8') + self.assertTrue(html.startswith('')) + self.assertIn('To-Do lists', html) + self.assertTrue(html.endswith('')) + + def test_uses_home_template(self): + response = self.client.get('/') + self.assertTemplateUsed(response, 'home.html') + + def test_can_save_a_POST_request(self): + response = self.client.post('/', data={'item_text': 'A new list item'}) + self.assertEqual(Item.objects.count(), 1) + new_item = Item.objects.first() + self.assertEqual(new_item.text, 'A new list item') + self.assertEqual(response.status_code, 302) + self.assertEqual(response['location'], '/') + def test_only_saves_items_when_necessary(self): + self.client.get('/') + self.assertEqual(Item.objects.count(), 0) + +class ItemModelTest(TestCase): + + def test_saving_and_retrieving_items(self): + first_item = Item() + first_item.text = 'The first (ever) list item' + first_item.save() + + second_item = Item() + second_item.text = 'Item the second' + second_item.save() + + saved_items = Item.objects.all() + self.assertEqual(saved_items.count(), 2) + + first_saved_item = saved_items[0] + second_saved_item = saved_items[1] + self.assertEqual(first_saved_item.text, 'The first (ever) list item') + self.assertEqual(second_saved_item.text, 'Item the second') + + def test_can_save_a_POST_request(self): + response = self.client.post('/', data={'item_text': 'A new list item'}) + + self.assertEqual(Item.objects.count(), 1) + new_item = Item.objects.first() + self.assertEqual(new_item.text, 'A new list item') + + self.assertIn('A new list item', response.content.decode()) + self.assertTemplateUsed(response, 'home.html') \ No newline at end of file diff --git a/lists/tests/test_views.py b/lists/tests/test_views.py new file mode 100644 index 0000000000000000000000000000000000000000..e460908944a4f1e42eb671c77097c06a01cfe3dc --- /dev/null +++ b/lists/tests/test_views.py @@ -0,0 +1,36 @@ +from django.urls import resolve +from django.test import TestCase +from django.http import HttpRequest + +from lists.views import home_page +from lists.models import Item + + +class HomePageTest(TestCase): + + def test_root_url_resolves_to_home_page_view(self): + found = resolve('/') + self.assertEqual(found.func, home_page) + + def test_home_page_returns_correct_html(self): + request = HttpRequest() + response = home_page(request) + html = response.content.decode('utf8') + self.assertTrue(html.startswith('')) + self.assertIn('To-Do lists', html) + self.assertTrue(html.endswith('')) + + def test_uses_home_template(self): + response = self.client.get('/') + self.assertTemplateUsed(response, 'home.html') + + def test_can_save_a_POST_request(self): + response = self.client.post('/', data={'item_text': 'A new list item'}) + self.assertEqual(Item.objects.count(), 1) + new_item = Item.objects.first() + self.assertEqual(new_item.text, 'A new list item') + self.assertEqual(response.status_code, 302) + self.assertEqual(response['location'], '/') + def test_only_saves_items_when_necessary(self): + self.client.get('/') + self.assertEqual(Item.objects.count(), 0) \ No newline at end of file diff --git a/superlists/settings.py b/superlists/settings.py index b0a0d7f4475561284047fc68e032b776415e052b..675b69ff5edca4a65d18191066c70981eaa61b9e 100644 --- a/superlists/settings.py +++ b/superlists/settings.py @@ -25,7 +25,7 @@ SECRET_KEY = '4o%--sf57&nkwk%o=d29#zdccko+ms^pepk_#4ah8k92c_52ut' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = ['testch1-3.herokuapp.com','localhost'] +ALLOWED_HOSTS = ['alvinraihanhome.herokuapp.com','localhost'] # Application definition