Fakultas Ilmu Komputer UI

Commit 9179558f authored by Dwi Nanda Susanto's avatar Dwi Nanda Susanto
Browse files

Merge branch 'exercise10' into 'master'

Exercise10

See merge request !14
parents c6327ee1 409faad7
Pipeline #27129 failed with stages
in 59 seconds
......@@ -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.
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
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
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
......@@ -39,6 +39,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'lists',
'accounts',
'behave_django',
]
AUTH_USER_MODEL = 'accounts.User'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment