From caf057f78208bdee5ed6d408c8713cb751f6ffe2 Mon Sep 17 00:00:00 2001 From: Dwi Nanda Susanto Date: Sun, 8 Dec 2019 11:26:37 +0700 Subject: [PATCH 1/2] exercise 10 --- features/environment.py | 8 +++++ features/my_lists.feature | 23 ++++++++++++++ features/steps/my_lists.py | 63 ++++++++++++++++++++++++++++++++++++++ superlists/settings.py | 1 + 4 files changed, 95 insertions(+) create mode 100644 features/environment.py create mode 100644 features/my_lists.feature create mode 100644 features/steps/my_lists.py diff --git a/features/environment.py b/features/environment.py new file mode 100644 index 0000000..aff6589 --- /dev/null +++ b/features/environment.py @@ -0,0 +1,8 @@ +from selenium import webdriver + +def before_all(context): + context.browser = webdriver.Firefox() +def after_all(context): + context.browser.quit() +def before_feature(context, feature): + pass \ No newline at end of file diff --git a/features/my_lists.feature b/features/my_lists.feature new file mode 100644 index 0000000..54ae604 --- /dev/null +++ b/features/my_lists.feature @@ -0,0 +1,23 @@ +Feature: My Lists + As a logged-in user + I want to be able to see all my lists in one page + So that I can find them all after I've written them + + Scenario: Create two lists and see them on the My Lists page + + Given I am a logged-in user + + When I create a list with first item "Reticulate Splines" + And I add an item "Immanentize Eschaton" + And I create a list with first item "Buy milk" + + Then I will see a link to "My lists" + + When I click the link to "My lists" + Then I will see a link to "Reticulate Splines" + And I will see a link to "Buy milk" + + When I click the link to "Reticulate Splines" + Then I will be on the "Reticulate Splines" list page + + When I create a list with first item "Reticulate Splines" \ No newline at end of file diff --git a/features/steps/my_lists.py b/features/steps/my_lists.py new file mode 100644 index 0000000..390c57d --- /dev/null +++ b/features/steps/my_lists.py @@ -0,0 +1,63 @@ +from functional_tests.base import wait +from behave import given, when, then + +from functional_tests.management.commands.create_session import \ + create_pre_authenticated_session +from django.conf import settings + +@given('I am a logged-in user') +def given_i_am_logged_in(context): + session_key = create_pre_authenticated_session(email='edith@example.com') + ## to set a cookie we need to first visit the domain. + ## 404 pages load the quickest! + context.browser.get(context.get_url("/404_no_such_url/")) + context.browser.add_cookie(dict( + name=settings.SESSION_COOKIE_NAME, + value=session_key, + path='/', + )) + +@given('I create a list with first item "Reticulate Splines"') +def step_impl(context): + raise NotImplementedError( + u'STEP: When I create a list with first item "Reticulate Splines"' + ) + + +@when('I create a list with first item "{first_item_text}"') +def create_a_list(context, first_item_text): + context.browser.get(context.get_url('/')) + context.browser.find_element_by_id('id_text').send_keys(first_item_text) + context.browser.find_element_by_id('id_text').send_keys(Keys.ENTER) + wait_for_list_item(context, first_item_text) + +@wait +def wait_for_list_item(context, item_text): + context.test.assertIn( + item_text, + context.browser.find_element_by_css_selector('#id_list_table').text + ) + +@when('I add an item "{item_text}"') +def add_an_item(context, item_text): + context.browser.find_element_by_id('id_text').send_keys(item_text) + context.browser.find_element_by_id('id_text').send_keys(Keys.ENTER) + wait_for_list_item(context, item_text) + +@then('I will see a link to "{link_text}"') +@wait +def see_a_link(context, link_text): + context.browser.find_element_by_link_text(link_text) + +@when('I click the link to "{link_text}"') +def click_link(context, link_text): + context.browser.find_element_by_link_text(link_text).click() + +@then('I will be on the "{first_item_text}" list page') +@wait +def on_list_page(context, first_item_text): + first_row = context.browser.find_element_by_css_selector( + '#id_list_table tr:first-child' + ) + expected_row_text = '1: ' + first_item_text + context.test.assertEqual(first_row.text, expected_row_text) \ No newline at end of file diff --git a/superlists/settings.py b/superlists/settings.py index a05f2c7..c81bd13 100644 --- a/superlists/settings.py +++ b/superlists/settings.py @@ -39,6 +39,7 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'lists', 'accounts', + 'behave_django', ] AUTH_USER_MODEL = 'accounts.User' -- GitLab From 0f46c1e67eb8edd7f36163893607338130e5bec7 Mon Sep 17 00:00:00 2001 From: Dwi Nanda Susanto Date: Sun, 8 Dec 2019 11:29:43 +0700 Subject: [PATCH 2/2] update readme md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 37ef64d..b61fbee 100644 --- a/README.md +++ b/README.md @@ -82,4 +82,8 @@ Sedangkan mocking dengan `library`, dilakukan dengan menggunakan library dari Py self.assertEqual(to_list, ['edith@example.com']) ``` -Dengan memberikan anotasi `@Patch` fungsi yang berada dibawahnya akan secara otomatis dibuatkan versi Mock-nya oleh library tersebut. \ No newline at end of file +Dengan memberikan anotasi `@Patch` fungsi yang berada dibawahnya akan secara otomatis dibuatkan versi Mock-nya oleh library tersebut. + +# Exercise 10 + +Setiap kali kita melakukan perubahan pada models, sebelum manjalankan aplikasi, kita harus terlebih dahulu mengupdate skema ORM django ke dalam format db dengan melakukan `makemigrations` dan `migrate` agar tidak terjadi ```IntegrityError```. Karena adanya penambahan attribute pada models juga akan menyebabkan pengupdate-an column pada table. agar tidak error. -- GitLab