Fakultas Ilmu Komputer UI

Commit e6a5f191 authored by PRIAMBUDI LINTANG BAGASKARA's avatar PRIAMBUDI LINTANG BAGASKARA 🎱

Merge branch 'takehome' into 'master'

Takehome

See merge request !16
parents 10dd442f 9c8e84fd
Pipeline #27685 passed with stages
in 50 minutes and 14 seconds
This source diff could not be displayed because it is too large. You can view the blob instead.
[run]
branch = true
omit = */tests.py, */migrations/*, */apps.py, */urls.py, */settings/*, */wsgi.py, manage.py, fabfile.py
omit = */tests.py, */superlists/*, */lists/admin.py, */accounts/admin.py, */functional_tests/*, */lists/tests/*, */accounts/tests/*, */virtualenv/*, */migrations/*, */apps.py, */urls.py, */settings/*, */wsgi.py, manage.py, fabfile.py
source = .
[report]
......
......@@ -11,13 +11,6 @@ before_script:
- service postgresql start
- sudo -u $DB_DEFAULT_OWNER psql -c "CREATE USER $DB_USERNAME WITH PASSWORD '$DB_PASSWORD' CREATEDB"
- sudo -u $DB_DEFAULT_OWNER psql -c "CREATE DATABASE $DB_NAME OWNER $DB_USERNAME"
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
- echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
- wget https://chromedriver.storage.googleapis.com/77.0.3865.40/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip
- apt-get update -qq && apt-get install -y -qq unzip
- apt-get install -y google-chrome-stable
- apt-get install -y xvfb
- pip install --upgrade pip
- pip install -r requirements.txt
- python manage.py makemigrations
......@@ -29,39 +22,93 @@ ListsTest:
image: python:latest
stage: Unit Test
script:
- python manage.py test lists.tests
- coverage run --source='.' manage.py test lists.tests.test_models && coverage report -m
- coverage run --source='.' manage.py test lists.tests.test_models
AccountsTest:
image: python:latest
stage: Unit Test
script:
- python manage.py test accounts.tests
- coverage run --source='.' manage.py test accounts.tests.test_models && coverage report -m
- coverage run --source='.' manage.py test accounts.tests.test_models
LayoutAndStylingTest:
image: python:latest
stage: Functional Test
script:
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
- echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
- wget https://chromedriver.storage.googleapis.com/79.0.3945.36/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip
- apt-get update -qq && apt-get install -y -qq unzip
- apt-get install -y google-chrome-stable
- apt-get install -y xvfb
- python manage.py test functional_tests.test_layout_and_styling
AuthorNameTest:
image: python:latest
stage: Functional Test
script:
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
- echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
- wget https://chromedriver.storage.googleapis.com/79.0.3945.36/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip
- apt-get update -qq && apt-get install -y -qq unzip
- apt-get install -y google-chrome-stable
- apt-get install -y xvfb
- python manage.py test functional_tests.test_author_name
ListItemValidationTest:
image: python:latest
stage: Functional Test
script:
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
- echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
- wget https://chromedriver.storage.googleapis.com/79.0.3945.36/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip
- apt-get update -qq && apt-get install -y -qq unzip
- apt-get install -y google-chrome-stable
- apt-get install -y xvfb
- python manage.py test functional_tests.test_list_item_validation
SimpleListCreationTest:
image: python:latest
stage: Functional Test
script:
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
- echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
- wget https://chromedriver.storage.googleapis.com/79.0.3945.36/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip
- apt-get update -qq && apt-get install -y -qq unzip
- apt-get install -y google-chrome-stable
- apt-get install -y xvfb
- python manage.py test functional_tests.test_simple_list_creation
LoginTest:
image: python:latest
stage: Functional Test
script:
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
- echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
- wget https://chromedriver.storage.googleapis.com/79.0.3945.36/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip
- apt-get update -qq && apt-get install -y -qq unzip
- apt-get install -y google-chrome-stable
- apt-get install -y xvfb
- python manage.py test functional_tests.test_login
CoverageTable:
image: python:latest
stage: Functional Test
script:
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
- echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
- wget https://chromedriver.storage.googleapis.com/79.0.3945.36/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip
- apt-get update -qq && apt-get install -y -qq unzip
- apt-get install -y google-chrome-stable
- apt-get install -y xvfb
- coverage run --source='.' manage.py test
- coverage report -m
coverage: '/TOTAL.+ ([0-9]{1,3}%)/'
Deployment:
image: ruby:2.4
......
......@@ -143,9 +143,19 @@ dengan fungsi
![hehe](func.png)
test yang dibuat akan gagal.
# Cerita Exercise 8
# Cerita Exercise 9
## Chapter 20
Salah satu perbedaannya adalah pada subbab 20.1, menerapkan decorator `@wait`. Subbab 20.1 lebih baik karena ada separation of concern yang membuat functional test lebih efisien.
## Chapter 21
Tidak terjadi error saat melakukan functional test.
# Cerita Exercise 10
Untuk mengerjakan exercise ini tanpa adanya perubahan, tidak bisa saya lakukan karena script di bawah tidak berfungsi lagi.
```
scp elspeth@superlists.ottg.eu:\
/home/elspeth/sites/superlists.ottg.eu/database/db.sqlite3 .
```
Permasalahan migrasi data kali ini adalah jika proyek kita gede, kita harus memperhitungkan seberapa lama proses migrasi data akan berlangsung. Ada kemungkinan saat melakukan migrasi data tersebut, terjadi eror karena skema baru tidak cocok dengan data yang ada di database. Sebaiknya migrasi data dilakukan untuk menghindari kemungkinan eror tersebut.
s
\ No newline at end of file
......@@ -84,3 +84,8 @@ class LoginViewTest(TestCase):
mock_auth.authenticate.return_value = None
self.client.get('/accounts/login?token=abcd123')
self.assertEqual(mock_auth.login.called, False)
class LogoutViewTest(TestCase):
def test_redirects_to_home_page(self):
response = self.client.get('/accounts/logout')
self.assertRedirects(response, '/')
......@@ -7,7 +7,6 @@ from accounts.models import Token
from django.contrib.auth import login as auth_login, logout as auth_logout
def send_login_email(request):
email = request.POST['email']
token = Token.objects.create(email=email)
......
from selenium.webdriver.common.keys import Keys
from .base import FunctionalTest
author_name = "Priambudi Lintang Bagaskara"
class AuthorNameTest(FunctionalTest):
def test_author_name(self):
self.browser.get(self.live_server_url)
header_author = self.browser.find_element_by_id('author-name-header').text
footer_author = self.browser.find_element_by_id('author-name-footer').text
self.assertIn(author_name, header_author)
self.assertIn(author_name, footer_author)
\ No newline at end of file
......@@ -18,4 +18,5 @@ class LayoutAndStylingtest(FunctionalTest):
inputbox.location['x'] + inputbox.size['width'] / 2,
512,
delta=10
)
\ No newline at end of file
)
\ No newline at end of file
......@@ -67,6 +67,11 @@ class NewVisitorTest(FunctionalTest):
self.check_for_auto_comment('oh tidak')
deletebox = self.browser.find_element_by_id('id_delete_item')
deletebox.send_keys(Keys.ENTER)
self.check_for_auto_comment("yey, waktunya berlibur")
def check_for_auto_comment(self, text):
auto_comment = self.browser.find_element_by_id('comment').text
self.assertEqual(text, auto_comment)
\ No newline at end of file
......@@ -32,7 +32,7 @@
{% csrf_token %}
</form>
{% endif %}
<span id="author-name-header">Priambudi Lintang Bagaskara</span>
</div>
<div class="container text-center">
<h1 id='name'>Priambudi Lintang Bagaskara</h1>
......@@ -42,9 +42,13 @@
<p id="comment">{{comment}}</p>
<p class="has-error">{{error}}</p>
<form method="POST">
<input name="item_text" class="right" id="id_new_item" placeholder="Enter a to-do item" />
{% csrf_token %}
</form>
<input name="item_text" class="right" id="id_new_item" placeholder="Enter a to-do item" />
{% csrf_token %}
</form>
<form method="POST">
<input type="submit" id="id_delete_item" name="delete_button" value="Delete List"/>
{% csrf_token %}
</form>
<table id="id_list_table">
{% for item in items %}
......@@ -52,6 +56,7 @@
{% endfor %}
</table>
</div>
<span id="author-name-footer">Priambudi Lintang Bagaskara</span>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
......
......@@ -32,6 +32,19 @@ class HomePageUnitTest(TestCase):
self.assertEqual(response.status_code, 302)
self.assertEqual(response['location'], '/')
def test_can_delete_list(self):
response = self.client.post('/', data={'item_text': 'A new list item'})
self.assertEqual(Item.objects.count(), 1)
response = self.client.post('/', data={'delete_button': 'Delete List'})
self.assertEqual(Item.objects.count(), 0)
def test_redirects_after_delete_list(self):
response = self.client.post('/', data={'item_text': 'A new list item'})
response = self.client.post('/')
self.assertEqual(response.status_code, 302)
self.assertEqual(response['location'], '/')
def test_only_saves_items_when_necessary(self):
self.client.get('/')
self.assertEqual(Item.objects.count(), 0)
......
......@@ -6,15 +6,21 @@ from lists.models import Item
def home_page(request):
items = Item.objects.all()
if request.method == 'POST':
if len(request.POST['item_text']) == 0:
return render(request, 'index.html',
is_item_text_valid = request.POST.get('item_text', False)
# if is_item_text_valid != False:
if "item_text" in request.POST:
if len(is_item_text_valid) == 0:
return render(request, 'index.html',
{
'items': items,
'comment': comment_text(len(items)),
'error': "You can't have an empty list item"
})
Item.objects.create(text=request.POST['item_text'])
return redirect('/')
Item.objects.create(text=request.POST['item_text'])
return redirect('/')
else:
items.all().delete()
return redirect('/')
return render(request, 'index.html', {'items': items, 'comment': comment_text(len(items))})
def comment_text(length):
......
......@@ -18,4 +18,5 @@ whitenoise==3.3.1
django-mutpy
django-environ==0.4.5
appdirs==1.4.0
coverage
\ No newline at end of file
coverage
behave_django
\ No newline at end of file
......@@ -55,6 +55,7 @@ INSTALLED_APPS = [
'django_mutpy',
'lists',
'accounts',
'behave_django',
]
AUTH_USER_MODEL = 'accounts.User'
......
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