Fakultas Ilmu Komputer UI

Commit 1fc9f9f9 authored by Fannyah Dita Cahya's avatar Fannyah Dita Cahya
Browse files

Merge branch 'appendix-e' into 'master'

Appendix e

See merge request !27
parents e22431af 11acec9d
Pipeline #26949 passed with stages
in 6 minutes and 31 seconds
......@@ -369,7 +369,7 @@ class MyListsTest(FunctionalTest):
Pada FT di 18.3, setiap proses FT diharuskan untuk melakukan ulang authentication dan proses log in email. Sehingga hal ini memakan waktu lebih lama dibandingkan dengan FT yang dibuat pada subbab 20.1. Sehingga FT pada 20.1 lebih baik
## Deploy dan Error Functional Test (20.1 dan 20.2)
## Deploy dan Error Functional Test (21.1 dan 21.2)
Pada saat melakukan functional test yang telah di deploy ke Heroku, terjadi error yang seperti pada instruksi:
1. Error karena tidak dapat log in sehingga elemen 'Log out' tidak dapat ditemukan (NoSuchElement)
```
......@@ -388,4 +388,36 @@ Error yang muncul pada Log heroku adalah
2019-11-25T09:20:19.396438+00:00 app[web.1]: raise SMTPSenderRefused(code, resp, from_addr)
2019-11-25T09:20:19.396446+00:00 app[web.1]: smtplib.SMTPSenderRefused: (530, b'5.5.1 Authentication Required. Learn more at\n5.5.1 https://support.google.com/mail/?p=WantAuthError c37sm3626119qta.56 - gsmtp', 'noreply@superlists')
```
karena password dari email yang diinput belum di export, sehingga ada error ketika hendak log in.
\ No newline at end of file
karena password dari email yang diinput belum di export, sehingga ada error ketika hendak log in.
# EXERCISE 10
## Pentingnya melakukan migrasi data
Data migration adalah proses pemindahan atau penggabungan data dari satu sistem ke sistem lain dengan mengubah penyimpanan, database, atau aplikasi itu sendiri. Pada exercise sebelum-sebelumnya, tidak dilakukan data migration dan kita hanya melakukan penghapusan terhadap data yang lama. Padahal dalam keaadan nyatanya bisa saja data tersebut masih dibutuhkan, dan merupakan hal yang penting. Dalam hal itu migrasi data mengambil peran yang penting.
Hal ini dilakukan dengan menambahkan unique constraint pada elemen list dan text di tabel Lists, dan menyesuaikan migrations file agar tidak ada duplikasi dan bersifat unique.
``lists/migrations/0002_remove_duplicates.py``
```python
def find_dupes(apps, schema_editor):
List = apps.get_model("lists", "List")
for list_ in List.objects.all():
items = list_.item_set.all()
texts = set()
for ix, item in enumerate(items):
if item.text in texts:
item.text = '{} ({})'.format(item.text, ix)
item.save()
texts.add(item.text)
```
## Populate data
Untuk exercise ini, dilakukan populate data sebanyak 100 data. Dibuat 10 list dengan masing-masing list memiliki 10 item.
```python
def create_data(apps, schema_editor):
List = apps.get_model("lists", "List")
Item = apps.get_model("lists", "Item")
for i in range(10):
_list = List.objects.create()
for j in range(10):
data = Item.objects.create(text='dump-data-' + str(j), list=_list)
```
\ No newline at end of file
......@@ -7,7 +7,6 @@ class ItemValidationTest(FunctionalTest):
def test_cannot_add_empty_list_items(self):
# Edith goes to the home page and accidentally tries to submit
# an empty list item. She hits Enter on the empty input box
#self.browser.get(self.live_server_url)
self.browser.get(self.live_server_url)
self.browser.find_element_by_id('id_new_item').send_keys(Keys.ENTER)
......@@ -18,23 +17,22 @@ class ItemValidationTest(FunctionalTest):
"You can't have an empty list item"
))
# # She tries again with some text for the item, which now works
# self.browser.find_element_by_id('id_new_item').send_keys('Buy milk')
# self.browser.find_element_by_id('id_new_item').send_keys(Keys.ENTER)
# self.wait_for_row_in_list_table('1: Buy milk')
# She tries again with some text for the item, which now works
self.browser.find_element_by_id('id_new_item').send_keys('Buy milk')
self.browser.find_element_by_id('id_new_item').send_keys(Keys.ENTER)
self.wait_for_row_in_list_table('1: Buy milk')
# # Perversely, she now decides to submit a second blank list item
# self.browser.find_element_by_id('id_new_item').send_keys(Keys.ENTER)
# Perversely, she now decides to submit a second blank list item
self.browser.find_element_by_id('id_new_item').send_keys(Keys.ENTER)
# # She receives a similar warning on the list page
# self.wait_for(lambda: self.assertEqual(
# self.browser.find_element_by_css_selector('.has-error').text,
# "You can't have an empty list item"
# ))
# She receives a similar warning on the list page
self.wait_for(lambda: self.assertEqual(
self.browser.find_element_by_css_selector('.has-error').text,
"You can't have an empty list item"
))
# # And she can correct it by filling some text in
# self.browser.find_element_by_id('id_new_item').send_keys('Make tea')
# self.browser.find_element_by_id('id_new_item').send_keys(Keys.ENTER)
# self.wait_for_row_in_list_table('1: Buy milk')
# self.wait_for_row_in_list_table('2: Make tea')
# And she can correct it by filling some text in
self.browser.find_element_by_id('id_new_item').send_keys('Make tea')
self.browser.find_element_by_id('id_new_item').send_keys(Keys.ENTER)
self.wait_for_row_in_list_table('1: Buy milk')
self.wait_for_row_in_list_table('2: Make tea')
# Generated by Django 2.2.5 on 2019-12-08 06:58
from django.db import models, migrations
def find_dupes(apps, schema_editor):
List = apps.get_model("lists", "List")
for list_ in List.objects.all():
items = list_.item_set.all()
texts = set()
for ix, item in enumerate(items):
if item.text in texts:
item.text = '{} ({})'.format(item.text, ix)
item.save()
texts.add(item.text)
class Migration(migrations.Migration):
dependencies = [
('lists', '0001_initial'),
]
operations = [
migrations.RunPython(find_dupes),
]
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('lists', '0002_remove_duplicates'),
]
operations = [
migrations.AlterModelOptions(
name='item',
options={'ordering': ('id',)},
),
migrations.AlterUniqueTogether(
name='item',
unique_together={('list', 'text')},
),
]
from django.db import models, migrations
def create_data(apps, schema_editor):
List = apps.get_model("lists", "List")
Item = apps.get_model("lists", "Item")
for i in range(10):
_list = List.objects.create()
for j in range(10):
data = Item.objects.create(text='dump-data-' + str(j), list=_list)
class Migration(migrations.Migration):
dependencies = [
('lists', '0003_unique_together'),
]
operations = [
migrations.RunPython(create_data),
]
......@@ -6,3 +6,7 @@ class List(models.Model):
class Item(models.Model):
text = models.TextField(default='')
list = models.ForeignKey(List, default=None, on_delete=models.CASCADE)
class Meta:
ordering = ('id',)
unique_together = ('list', 'text')
Markdown is supported
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