diff --git a/Procfile b/Procfile new file mode 100644 index 0000000000000000000000000000000000000000..36222866bd111f61da05af9726d24ab403caa485 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: gunicorn superlists.wsgi \ No newline at end of file diff --git a/README.md b/README.md index 08f1687f879d1851d96c1b2bd8c7701d1691c873..d6598752bb0a2a7da5332fc05d500c931e1abdf0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,20 @@ Alvin Raihan 1506689074 -url : \ No newline at end of file +# Cerita Exercise 3 +## Test isolation dilakukan dengan menggabung functional test kedalam unit test django. Test isolation menggunakan class LiveServerTestCase.Pada akhirnya kita tidak menggunakan hardcode seperti perbedaan code dibawah + + +# Perbedaan code + +```python + def test_can_start_a_list_and_retrieve_it_later(self): + self.browser.get('http://localhost:8000') + +``` +Akhirnya + +```python + def test_can_start_a_list_and_retrieve_it_later(self): + self.browser.get(self.live_server_url) + +``` \ No newline at end of file diff --git a/functional_tests.py b/functional_tests.py deleted file mode 100644 index 67dae8246f3a0cbd851bf9f0ef7a27642129ab68..0000000000000000000000000000000000000000 --- a/functional_tests.py +++ /dev/null @@ -1,53 +0,0 @@ -from selenium import webdriver -import unittest - -class NewVisitorTest(unittest.TestCase): - - def setUp(self): - self.browser = webdriver.Firefox() - - def tearDown(self): - self.browser.quit() - - def test_can_start_a_list_and_retrieve_it_later(self): - # Edith has heard about a cool new online to-do app. She goes - # to check out its homepage - self.browser.get('http://localhost:8000') - - # She notices the page title and header mention to-do lists - self.assertIn('To-Do', self.browser.title) - header_text = self.browser.find_element_by_tag_name('h1').text - self.assertIn('To-Do', header_text) - - # She is invited to enter a to-do item straight away - inputbox = self.browser.find_element_by_id('id_new_item') - self.assertEqual( - inputbox.get_attribute('placeholder'), - 'Enter a to-do item' - ) - - # She types "Buy peacock feathers" into a text box (Edith's hobby - # is tying fly-fishing lures) - inputbox.send_keys('Buy peacock feathers') - - # When she hits enter, the page updates, and now the page lists - # "1: Buy peacock feathers" as an item in a to-do list table - inputbox.send_keys(Keys.ENTER) - time.sleep(1) - - table = self.browser.find_element_by_id('id_list_table') - rows = table.find_elements_by_tag_name('tr') - self.assertTrue( - any(row.text == '1: Buy peacock feathers' for row in rows) - ) - - # There is still a text box inviting her to add another item. She - # enters "Use peacock feathers to make a fly" (Edith is very - # methodical) - self.fail('Finish the test!') - - # The page updates again, and now shows both items on her list - [...] - -if __name__ == '__main__': - unittest.main(warnings='ignore') \ No newline at end of file diff --git a/functional_tests/__init__.py b/functional_tests/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/functional_tests/__pycache__/__init__.cpython-38.pyc b/functional_tests/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..719d0a31ce3d2c70bda21cee7031b4f65b4a5e2d Binary files /dev/null and b/functional_tests/__pycache__/__init__.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..cbeef91abd46ad9bea9b2d0dd789410af8338c20 Binary files /dev/null and b/functional_tests/__pycache__/tests.cpython-38.pyc differ diff --git a/functional_tests/tests.py b/functional_tests/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..8de8afeb14dda50af8bdd6e1945ff62900d34579 --- /dev/null +++ b/functional_tests/tests.py @@ -0,0 +1,68 @@ +from django.test import LiveServerTestCase +from selenium import webdriver +from selenium.webdriver.common.keys import Keys +from selenium.common.exceptions import WebDriverException +import time + +MAX_WAIT = 10 + +class NewVisitorTest(LiveServerTestCase): + + 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) + + def test_can_start_a_list_and_retrieve_it_later(self): + # Edith has heard about a cool new online to-do app. She goes + # to check out its homepage + self.browser.get(self.live_server_url) + # She notices the page title and header mention to-do lists + self.assertIn('To-Do', self.browser.title) + header_text = self.browser.find_element_by_tag_name('h1').text + self.assertIn('To-Do', header_text) + # She is invited to enter a to-do item straight away + inputbox = self.browser.find_element_by_id('id_new_item') + self.assertEqual( + inputbox.get_attribute('placeholder'), + 'Enter a to-do item' + ) + + # She types "Buy peacock feathers" into a text box (Edith's hobby + # is tying fly-fishing lures) + inputbox.send_keys('Buy peacock feathers') + # When she hits enter, the page updates, and now the page lists + # "1: Buy peacock feathers" as an item in a to-do list table + inputbox.send_keys(Keys.ENTER) + self.wait_for_row_in_list_table('1: Buy peacock feathers') + # There is still a text box inviting her to add another item. She + # enters "Use peacock feathers to make a fly" (Edith is very + # methodical) + inputbox = self.browser.find_element_by_id('id_new_item') + inputbox.send_keys('Use peacock feathers to make a fly') + inputbox.send_keys(Keys.ENTER) + # The page updates again, and now shows both items on her list + self.wait_for_row_in_list_table('1: Buy peacock feathers') + self.wait_for_row_in_list_table('2: Use peacock feathers to make a fly') + # Edith wonders whether the site will remember her list. Then she sees + # 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') \ No newline at end of file diff --git a/lists/__pycache__/models.cpython-38.pyc b/lists/__pycache__/models.cpython-38.pyc index c6edec9e458fb35da70716cf2cd0e239a189afce..2b8fe68815f8e6f4fea49161b31d2a6ae2bd6f61 100644 Binary files a/lists/__pycache__/models.cpython-38.pyc and b/lists/__pycache__/models.cpython-38.pyc differ diff --git a/lists/__pycache__/views.cpython-38.pyc b/lists/__pycache__/views.cpython-38.pyc index b16b805213660d482cf16968de9505115f0567c5..77a96e5a2688ef2f83826aec861b79ad5a00eb2a 100644 Binary files a/lists/__pycache__/views.cpython-38.pyc and b/lists/__pycache__/views.cpython-38.pyc differ diff --git a/lists/migrations/__pycache__/0001_initial.cpython-38.pyc b/lists/migrations/__pycache__/0001_initial.cpython-38.pyc index ee1e90758f19fbaf9bae9717e4f57d55e1603659..d3b77fc542f217d8f9fbbd457608da88c7f930b4 100644 Binary files a/lists/migrations/__pycache__/0001_initial.cpython-38.pyc and b/lists/migrations/__pycache__/0001_initial.cpython-38.pyc differ diff --git a/lists/migrations/__pycache__/0002_item_text.cpython-38.pyc b/lists/migrations/__pycache__/0002_item_text.cpython-38.pyc index 152ed7efbf0c976468572716f6feb320f331742d..014cfc3949c55e6f863b2154c1ec01f90647289b 100644 Binary files a/lists/migrations/__pycache__/0002_item_text.cpython-38.pyc and b/lists/migrations/__pycache__/0002_item_text.cpython-38.pyc differ diff --git a/lists/templates/home.html b/lists/templates/home.html index 9ad5489d7e4c6cf1200aca02faa96fe6787084a4..d8ebbf9cb1926baca12771ccb4dda79719cb7d7a 100644 --- a/lists/templates/home.html +++ b/lists/templates/home.html @@ -14,5 +14,12 @@
yey, waktunya berlibur
+ {% elif items|length > 0 and items|length < 5 %} +sibuk tapi santai
+ {% else %} +oh, tidak
+ {% endif %}