From b6b9f7e94e7b625192ae6a07f9693294b08870fd Mon Sep 17 00:00:00 2001 From: Dwi Nanda Susanto Date: Sun, 22 Dec 2019 19:36:36 +0700 Subject: [PATCH 1/9] [RED] create fail-test for feature : RESET ITEMS (delete all) --- db.sqlite3 | Bin 155648 -> 155648 bytes lists/templates/base.html | 4 ++-- lists/tests.py | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/db.sqlite3 b/db.sqlite3 index 4fd81550fde7b53b36e850b1105ccbe6568c970d..5c3c787f88b5a3b06baf7e4b3e253763c7a2ddcf 100644 GIT binary patch delta 202 zcmZoTz}awsbAmLZ%0wAwMwN{TOXP*v`HL9%ck@5zZ{lCWKb`*uf6-<|g&2MTK2Byu z#+=OJlH&NxlGI%0$xZsff^3{Ayd2DmoDgv!+5Aj@`!jt;xeGju{C^mLNS=X#L2k2P z!W(`eCPpR(ULcp5{|N*CH~zQ$Pk`dr__f%XSr~*li_+5BnLv!RqI3>M76wtyR3M8B lto{?wB>wOGpMdJ0@bj}Ub22i62qtD`PEOvti-(Z{P^Vjypq(slKAFl`rDuBGs<09&hmj#U^B~xKk}OzSRf1ltuG-v diff --git a/lists/templates/base.html b/lists/templates/base.html index f126f08..9773edb 100644 --- a/lists/templates/base.html +++ b/lists/templates/base.html @@ -9,7 +9,7 @@ -
+
diff --git a/lists/tests.py b/lists/tests.py index ce8be8b..ba0c570 100644 --- a/lists/tests.py +++ b/lists/tests.py @@ -65,6 +65,20 @@ class HomePageTest(TestCase): response = self.client.get('/') self.assertIn('oh tidak', 'oh tidak') + def test_delete_all_items(self): + for i in range(6): + Item.objects.create(text='itemey %d' % i) + + all_items = Item.objects.all() + if len(all_items) > 0 : + for i in all_items: + i.delete() + else: + pass + + response = self.client.get('/') + self.assertFalse('itemey 1', response.decode()) + class ItemModelTest(TestCase): def test_saving_and_retrieving_items(self): first_item = Item() -- GitLab From be85603bbeb11d4ef69d9c024e999c828befa932 Mon Sep 17 00:00:00 2001 From: Dwi Nanda Susanto Date: Sun, 22 Dec 2019 20:18:25 +0700 Subject: [PATCH 2/9] [IMPLEMENTATION] create function for reset all items at a certain lists/{list.id}/ and go back to / after reset items on that list.id page --- db.sqlite3 | Bin 155648 -> 155648 bytes lists/templates/base.html | 4 ++++ lists/urls.py | 9 +++++---- lists/views.py | 12 +++++++++++- superlists/urls.py | 8 +++++--- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/db.sqlite3 b/db.sqlite3 index 5c3c787f88b5a3b06baf7e4b3e253763c7a2ddcf..04bb060b8d6de13d7ed64d1b85ecb634f5128a5f 100644 GIT binary patch delta 690 zcma)(ziZTB7{}iyx!fi9BhS5Wt{!@oUK~V3IMGEMTr3CD z)(OL#ihuD>-s2xU~0QVoTxsT6jc@;0~r?^gM-?v6j29;RDa+#e*e$`?&ZT8G(2RfEI=_4x6X97g7J~2I4Q%7H4S42Cezd}%<8C3 zne0?Tb-DOb+>HQDMK;`(12-Sg?O|VP=Zl&JcRC>G$qv?tq!W$VY=@!@V+;Q>G%&Rp zbQbrGv|q%uhvWIqYsDSz5C70S>|Wy0!$uolkL!n^Yqc3@T5UmBy#RX0lZ}>L*?-Z+ zQK;(`hF&fE(94cwJMT!a7fO=oxso(<#+Kkt*^i$p41{h~ya<803IPyx|vOVq{|A1#+4BpD^%$ zOTQZ;{VS738?-FKR*jI UCnGb6U}9$G + +
+ +
diff --git a/lists/urls.py b/lists/urls.py index 9d619c6..297f59e 100644 --- a/lists/urls.py +++ b/lists/urls.py @@ -2,7 +2,8 @@ from django.conf.urls import url from lists import views urlpatterns = [ -url(r'^new$', views.new_list, name='new_list'), -url(r'^(\d+)/$', views.view_list, name='view_list'), -url(r'^(\d+)/add_item$', views.add_item, name='add_item'), -] + url(r'^new$', views.new_list, name='new_list'), + url(r'^(\d+)/$', views.view_list, name='view_list'), + url(r'^(\d+)/add_item$', views.add_item, name='add_item'), + url(r'^(\d+)/reset_items/$', views.reset_items, name='reset_items'), +] \ No newline at end of file diff --git a/lists/views.py b/lists/views.py index 9457be2..235df8b 100644 --- a/lists/views.py +++ b/lists/views.py @@ -1,6 +1,6 @@ from django.shortcuts import redirect, render -from lists.models import Item from lists.models import Item, List +from django.http import HttpResponse def home_page(request): return render(request, 'home.html') @@ -29,3 +29,13 @@ def add_item(request, list_id): list_ = List.objects.get(id=list_id) Item.objects.create(text=request.POST['item_text'], list=list_) return redirect(f'/lists/{list_.id}/') + +def reset_items(request, list_id): + print("AAAAAAAAAAAAAAAAA----") + + if request.method == 'GET': + Item.objects.all().delete() + return redirect('/') + items = Item.objects.all() + return redirect('/') + \ No newline at end of file diff --git a/superlists/urls.py b/superlists/urls.py index 4e14dcb..208f663 100644 --- a/superlists/urls.py +++ b/superlists/urls.py @@ -2,9 +2,11 @@ from django.conf.urls import include, url from lists import views as list_views from lists import urls as list_urls from accounts import urls as accounts_urls +from django.urls import path +from lists import views urlpatterns = [ -url(r'^$', list_views.home_page, name='home'), -url(r'^lists/', include(list_urls)), -url(r'^accounts/', include(accounts_urls)), + url(r'^$', list_views.home_page, name='home'), + url(r'^lists/', include(list_urls)), + url(r'^accounts/', include(accounts_urls)), ] -- GitLab From 4c409bed71d7201b449c27bde2578ea587cc0016 Mon Sep 17 00:00:00 2001 From: Dwi Nanda Susanto Date: Sun, 22 Dec 2019 20:18:56 +0700 Subject: [PATCH 3/9] [GREEN] pass all test, debug and ready to merge to master --- lists/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lists/tests.py b/lists/tests.py index ba0c570..50c52d8 100644 --- a/lists/tests.py +++ b/lists/tests.py @@ -77,7 +77,7 @@ class HomePageTest(TestCase): pass response = self.client.get('/') - self.assertFalse('itemey 1', response.decode()) + self.assertFalse(self.assertIn('itemey 1', response.content.decode('utf8'))) class ItemModelTest(TestCase): def test_saving_and_retrieving_items(self): -- GitLab From 70c89754eadec923c745b8a26c539e513cdc22df Mon Sep 17 00:00:00 2001 From: Dwi Nanda Susanto Date: Sun, 22 Dec 2019 20:25:25 +0700 Subject: [PATCH 4/9] [GREEN] passed tests --- lists/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lists/tests.py b/lists/tests.py index 50c52d8..75bf615 100644 --- a/lists/tests.py +++ b/lists/tests.py @@ -77,7 +77,7 @@ class HomePageTest(TestCase): pass response = self.client.get('/') - self.assertFalse(self.assertIn('itemey 1', response.content.decode('utf8'))) + self.assertNotContains('itemey 1', response.content.decode('utf8')) class ItemModelTest(TestCase): def test_saving_and_retrieving_items(self): -- GitLab From c10f5f995dfeac1550602d8c9fbd54978054374f Mon Sep 17 00:00:00 2001 From: Dwi Nanda Susanto Date: Sun, 22 Dec 2019 20:28:58 +0700 Subject: [PATCH 5/9] [GREEN] debug --- lists/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lists/tests.py b/lists/tests.py index 75bf615..e9fc6a6 100644 --- a/lists/tests.py +++ b/lists/tests.py @@ -77,7 +77,7 @@ class HomePageTest(TestCase): pass response = self.client.get('/') - self.assertNotContains('itemey 1', response.content.decode('utf8')) + self.assertNotContains(text='itemey 1', response=response.content.decode('utf8')) class ItemModelTest(TestCase): def test_saving_and_retrieving_items(self): -- GitLab From 0c0d8045a620d1bd66923b2a4cb0262c376bbbb2 Mon Sep 17 00:00:00 2001 From: Dwi Nanda Susanto Date: Sun, 22 Dec 2019 20:36:33 +0700 Subject: [PATCH 6/9] [GREEN] debug --- lists/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lists/tests.py b/lists/tests.py index e9fc6a6..1acc56f 100644 --- a/lists/tests.py +++ b/lists/tests.py @@ -77,7 +77,7 @@ class HomePageTest(TestCase): pass response = self.client.get('/') - self.assertNotContains(text='itemey 1', response=response.content.decode('utf8')) + self.assertFalse('itemey 1', response.content.decode('utf8')) class ItemModelTest(TestCase): def test_saving_and_retrieving_items(self): -- GitLab From 5a95eb738f6e6127fad06f8a825d1453671a946e Mon Sep 17 00:00:00 2001 From: Dwi Nanda Susanto Date: Sun, 22 Dec 2019 20:43:28 +0700 Subject: [PATCH 7/9] [GREEN] debug --- lists/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lists/tests.py b/lists/tests.py index 1acc56f..25d4720 100644 --- a/lists/tests.py +++ b/lists/tests.py @@ -77,7 +77,7 @@ class HomePageTest(TestCase): pass response = self.client.get('/') - self.assertFalse('itemey 1', response.content.decode('utf8')) + self.assertNotIn('itemey 1', response.content.decode('utf8')) class ItemModelTest(TestCase): def test_saving_and_retrieving_items(self): -- GitLab From 993055a2c8a6c3fba26c2acea1cd8cacf0828f5e Mon Sep 17 00:00:00 2001 From: Dwi Nanda Susanto Date: Sun, 22 Dec 2019 20:59:18 +0700 Subject: [PATCH 8/9] [GREEN] pass all tests, update readme md adding code coverage on readme md --- README.md | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/README.md b/README.md index 39ca5f8..c97a018 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,81 @@ The **deployed** simple home page can be accessed here : [![coverage report](https://gitlab.cs.ui.ac.id/pmpl/practice-collection/2019/1506722720-practice/badges/fix_uas_take_home/coverage.svg)](https://gitlab.cs.ui.ac.id/pmpl/practice-collection/2019/1506722720-practice/commits/fix_uas_take_home) +# UAS TAKE HOME PROGRAMMING +first task is done : implementing header and footer in SQA way, branch is `fix_uas_take_home` + +second task is done also : create my own feature, `reset all items` on branch `new_ftr_uas_take_home` + +>here below is the code coverage for the the `unittest` + +``` +$ coverage report +Name Stmts Miss Cover +----------------------------------------------------------- +accounts/__init__.py 0 0 100% +accounts/admin.py 1 0 100% +accounts/authentication.py 22 0 100% +accounts/migrations/0001_initial.py 6 0 100% +accounts/migrations/__init__.py 0 0 100% +accounts/models.py 30 4 87% +accounts/tests/test_authentication.py 30 0 100% +accounts/tests/test_models.py 13 0 100% +accounts/tests/test_views.py 29 0 100% +accounts/urls.py 4 0 100% +accounts/views.py 28 2 93% +lists/__init__.py 0 0 100% +lists/admin.py 1 0 100% +lists/migrations/0001_initial.py 6 0 100% +lists/migrations/__init__.py 0 0 100% +lists/models.py 6 0 100% +lists/tests.py 74 0 100% +lists/urls.py 3 0 100% +lists/views.py 30 21 30% +manage.py 13 6 54% +superlists/__init__.py 0 0 100% +superlists/settings.py 30 0 100% +superlists/urls.py 7 0 100% +----------------------------------------------------------- +TOTAL 333 33 90% +Job succeeded +``` + +>and here below is the code coverage for the `functional test` +``` +$ coverage report -m +Name Stmts Miss Cover Missing +---------------------------------------------------------------------------- +accounts/__init__.py 0 0 100% +accounts/admin.py 1 0 100% +accounts/apps.py 3 3 0% 1-5 +accounts/authentication.py 22 6 73% 10-11, 16-17, 25-26 +accounts/migrations/0001_initial.py 6 0 100% +accounts/migrations/__init__.py 0 0 100% +accounts/models.py 30 4 87% 20, 22, 33, 37 +accounts/tests.py 1 0 100% +accounts/urls.py 4 0 100% +accounts/views.py 28 0 100% +functional_test/__init__.py 0 0 100% +functional_test/base.py 55 18 67% 34-37, 41-56, 76-77 +functional_test/test_layout_and_styling.py 9 0 100% +functional_test/test_list_item_validation.py 15 8 47% 12-19 +functional_test/test_login.py 36 4 89% 38, 76-78 +functional_test/test_my_lists.py 32 4 88% 44-47 +functional_test/tests.py 52 12 77% 43-58 +lists/__init__.py 0 0 100% +lists/admin.py 1 0 100% +lists/apps.py 3 3 0% 1-5 +lists/migrations/0001_initial.py 6 0 100% +lists/migrations/__init__.py 0 0 100% +lists/models.py 6 0 100% +lists/tests.py 74 0 100% +lists/urls.py 3 0 100% +lists/views.py 30 11 63% 15, 19, 29-31, 34-40 +---------------------------------------------------------------------------- +TOTAL 417 73 82% +Job succeeded +``` + # Exercise 3 Pada exercise 3 kali ini dibuat sebuah integration test yang akan mengautomasi waktu menunggu hingga terjadi perubahan pada rows. Pada integration test ini sudah bisa melakukan listening terhadap request dari url LiveServer yang sedang aktif. Jadi tidak perlu melihat lagi url apa yang sedang berjalan. -- GitLab From 66d37c0ddbc387ed79a87628289da526d190b1cd Mon Sep 17 00:00:00 2001 From: Dwi Nanda Susanto Date: Sun, 22 Dec 2019 21:24:32 +0700 Subject: [PATCH 9/9] add coverage score and pipeline status to readme md --- README.md | 6 ++++-- coverage.svg | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c97a018..d279bf4 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,13 @@ The **deployed** simple home page can be accessed here : [http://dwi-simplehomepage.herokuapp.com/](http://dwi-simplehomepage.herokuapp.com/) -[![pipeline status](https://gitlab.cs.ui.ac.id/pmpl/practice-collection/2019/1506722720-practice/badges/fix_uas_take_home/pipeline.svg)](https://gitlab.cs.ui.ac.id/pmpl/practice-collection/2019/1506722720-practice/commits/fix_uas_take_home) +[![pipeline status](https://gitlab.cs.ui.ac.id/pmpl/practice-collection/2019/1506722720-practice/badges/fix_uas_take_home/pipeline.svg)](https://gitlab.cs.ui.ac.id/pmpl/practice-collection/2019/1506722720-practice/commits/master) -[![coverage report](https://gitlab.cs.ui.ac.id/pmpl/practice-collection/2019/1506722720-practice/badges/fix_uas_take_home/coverage.svg)](https://gitlab.cs.ui.ac.id/pmpl/practice-collection/2019/1506722720-practice/commits/fix_uas_take_home) +[![coverage report](coverage.svg)](https://gitlab.cs.ui.ac.id/pmpl/practice-collection/2019/1506722720-practice/commits/master) # UAS TAKE HOME PROGRAMMING +`duration of coding : almost 4 days` + first task is done : implementing header and footer in SQA way, branch is `fix_uas_take_home` second task is done also : create my own feature, `reset all items` on branch `new_ftr_uas_take_home` diff --git a/coverage.svg b/coverage.svg index ae1c350..c149003 100644 --- a/coverage.svg +++ b/coverage.svg @@ -9,13 +9,13 @@ - + coverage coverage - 54% - 54% + 90% + 90% -- GitLab