diff --git a/functional_test/test_footer_header.py b/functional_test/test_footer_header.py new file mode 100644 index 0000000000000000000000000000000000000000..3884cdf4dcd9468b286c401380e60fbff2d0256f --- /dev/null +++ b/functional_test/test_footer_header.py @@ -0,0 +1,16 @@ +from selenium.webdriver.common.keys import Keys + +from .tests import FunctionalTest + +class FooterHeaderTest(FunctionalTest): + + def test_home_page_whether_satisfies_user_needs(self): + self.browser.get(self.live_server_url) + + owner_full_name = "Izzatul Muttaqin" + + header = self.browser.find_element_by_class_name("header") + footer = self.browser.find_element_by_class_name("footer") + + self.assertIn(owner_full_name, header.text) + self.assertIn(owner_full_name, footer.text) diff --git a/functional_test/test_list.py b/functional_test/test_list.py index e027cda65ff512990759ca58f4d8e1c8fd4dec86..70e81efa6ddad89a351c38ad6336ab6afd29d886 100644 --- a/functional_test/test_list.py +++ b/functional_test/test_list.py @@ -18,9 +18,9 @@ class ItemValidationTest(FunctionalTest): )) self.get_item_input_box().send_keys(Keys.ENTER) - self.wait_for_row_in_list_table('2: Buy milk') + self.wait_for_row_in_list_table('2: Buy milk Delete') self.get_item_input_box().send_keys('Buy cheese') self.get_item_input_box().send_keys(Keys.ENTER) - self.wait_for_row_in_list_table('3: Buy cheese') \ No newline at end of file + self.wait_for_row_in_list_table('3: Buy cheese Delete') \ No newline at end of file diff --git a/functional_test/tests.py b/functional_test/tests.py index 0901d3a0aa629d679a25194b7956486065218760..9dd251ecfececefa657c721156f897a0e3e83c7d 100644 --- a/functional_test/tests.py +++ b/functional_test/tests.py @@ -67,13 +67,8 @@ class FunctionalTest(StaticLiveServerTestCase): self.assertIn(row_text, [row.text for row in rows]) @wait - def wait_to_be_logged_in(self, email): - self.browser.find_element_by_link_text('Log out') - navbar = self.browser.find_element_by_css_selector('.navbar') - self.assertIn(email, navbar.text) - - @wait - def wait_to_be_logged_out(self, email): - self.browser.find_element_by_name('email') - navbar = self.browser.find_element_by_css_selector('.navbar') - self.assertNotIn(email, navbar.text) \ No newline at end of file + def wait_for_row_not_in_list_table(self, row_text): + table = self.browser.find_element_by_id('id_list_table') + rows = table.find_elements_by_tag_name('tr') + self.assertNotIn(row_text, [row.text for row in rows]) + \ No newline at end of file diff --git a/lists/templates/homepage/home.html b/lists/templates/homepage/home.html index a75d9eb7806a35a431f9d04b64cb3423e9372826..c1f75084cad7432a4ec3951e44081c2e4ff7f0fa 100644 --- a/lists/templates/homepage/home.html +++ b/lists/templates/homepage/home.html @@ -1,19 +1,55 @@ <html> - <title>To-Do lists {{ name }}</title> - <body> - <h1 id="intro">Hello, this is {{ name }}.</h1> - <h1>Your To-Do list</h1> - <form method="POST"> - <input name="item_text" id="id_new_item" placeholder="Enter a to-do item" /> - {% csrf_token %} - </form> +<title>To-Do lists {{ name }}</title> +<style> + /* Style the body */ + body { + font-family: Arial; + margin: 0; + } + + .footer { + position: fixed; + left: 0; + bottom: 0; + width: 100%; + text-align: center; + } + + /* Header/Logo Title */ + .header { + padding: 60px; + text-align: center; + background: #1abc9c; + color: white; + font-size: 30px; + } +</style> + +<body> + <div class="header"> + <h1>Website PMPL practice</h1> + <p>This owned by Izzatul Muttaqin</p> + </div> + <h1 id="intro">Hello, this is {{ name }}.</h1> + <h1>Your To-Do list</h1> + <form method="POST"> + <input name="item_text" id="id_new_item" placeholder="Enter a to-do item" /> + {% csrf_token %} + </form> + + <h1 id="comment">{{ comment }}</h1> + + <table id="id_list_table"> + {% for item in items %} + <tr> + <td> {{ forloop.counter }}: {{ item.text }} <a id={{item.id}} href="/delete-item/?id={{ item.id }}"> Delete + </a></td> + </tr> + {% endfor %} + </table> + <div class="footer"> + <p>Owned by Izzatul Muttaqin</p> + </div> +</body> - <h1 id="comment">{{ comment }}</h1> - - <table id="id_list_table"> - {% for item in items %} - <tr><td>{{ forloop.counter }}: {{ item.text }}</td></tr> - {% endfor %} - </table> - </body> </html> \ No newline at end of file diff --git a/lists/tests.py b/lists/tests.py index 0611d7a9d9d488f9289f190bb0131efed6b39e2c..be583f546702c4f27e94367639eecd294653e8eb 100644 --- a/lists/tests.py +++ b/lists/tests.py @@ -70,6 +70,22 @@ class HomePageTest(TestCase): self.assertIn('itemey 1', response.content.decode()) self.assertIn('itemey 2', response.content.decode()) + def test_delete_item(self): + item = Item.objects.create(text='itemey 1') + + request = HttpRequest() + response = home_page(request) + + self.assertIn('sibuk tapi santai', response.content.decode()) + + response = Client().get('/delete-item/?id=' + str(item.id)) + + request = HttpRequest() + response = home_page(request) + + self.assertIn('yey, waktunya libur', response.content.decode()) + self.assertNotIn(item, Item.objects.all()) + def test_all_comment(self): request = HttpRequest() response = home_page(request) diff --git a/lists/urls.py b/lists/urls.py index 61f727effab1102f96e92440bfbdc1b3a94f3eec..aa3c1c79d9c59485bd5f9aca4351d8bb643173e8 100644 --- a/lists/urls.py +++ b/lists/urls.py @@ -1,6 +1,7 @@ from django.conf.urls import url -from .views import home_page +from .views import home_page, delete_item #url for app urlpatterns = [ - url(r'^$', home_page, name='home_page') + url(r'^$', home_page, name='home_page'), + url(r'delete-item/$', delete_item, name='delete_item') ] diff --git a/lists/views.py b/lists/views.py index c7d9c07b827b31da6e7c47af0a3ea80bbfda2f3d..0b0ad79c92a0cac9f5b5eaa7eaf2375c2c55c22b 100644 --- a/lists/views.py +++ b/lists/views.py @@ -6,7 +6,15 @@ def home_page(request): if request.method == 'POST': Item.objects.create(text=request.POST['item_text']) return redirect('/') - + items = Item.objects.all() comment = counter_comment(Item.objects.count()) return render(request, 'homepage/home.html', {'items': items, 'comment' : comment, 'name': 'Izzatul Muttaqin'}) + +def delete_item(request): + if request.method=='GET': + id = request.GET.get('id') + if id is not None: + Item.objects.filter(id=id).delete() + return redirect('/') + diff --git a/requirements.txt b/requirements.txt index 8d4036aaf172e5d429ea4c6e44df89bc8b214105..b1068f52b4e33879045711bde529a5d0fae57ca9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,18 +1,29 @@ +astmonkey==0.3.6 astroid==1.5.3 colorama==0.3.9 coverage==4.4.1 -dj-database-url==0.4.2 +dj-database-url==0.5.0 Django==2.2.5 +django-appconf==1.0.3 +django-compressor==2.3 django-environ==0.4.4 -gunicorn==19.7.1 -isort==4.2.15 -lazy-object-proxy==1.3.1 -mccabe==0.6.1 -psycopg2==2.7.3.1 -pylint==1.7.2 -pytz==2017.2 -requests==2.18.4 -selenium==3.5.0 -six==1.10.0 -whitenoise==3.3.0 -wrapt==1.10.11 \ No newline at end of file +django-mutpy==0.1.2 +django-sass-processor==0.7.3 +gunicorn==19.9.0 +Jinja2==2.10.3 +libsass==0.19.3 +MarkupSafe==1.1.1 +MutPy==0.6.0 +psycopg2-binary==2.8.3 +pydot==1.4.1 +pyparsing==2.4.2 +pytz==2019.2 +PyYAML==5.1.2 +rcssmin==1.0.6 +rjsmin==1.1.0 +selenium==3.141.0 +six==1.12.0 +sqlparse==0.3.0 +termcolor==1.1.0 +urllib3==1.25.3 +whitenoise==4.1.3 \ No newline at end of file