Fakultas Ilmu Komputer UI

Commit df432cb4 authored by Izzatul Muttaqin's avatar Izzatul Muttaqin
Browse files

branch no deploy

parent 36230bf4
Pipeline #20608 passed with stage
in 4 minutes and 39 seconds
......@@ -38,3 +38,5 @@ Deployment:
environment:
name: production
url: $HEROKU_APP_HOST
only:
- master
# Created by https://www.gitignore.io/api/python,intellij+iml
### Intellij+iml ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Intellij+iml Patch ###
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
*.iml
modules.xml
.idea/misc.xml
*.ipr
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# dotenv
.env
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# virtualenv
.venv
venv/
ENV/
# Spyder project settings
.spyderproject
# Rope project settings
.ropeproject
# End of https://www.gitignore.io/api/python,intellij+iml
#Ignore files for Lab1
db.sqlite3
chromedriver
chromedriver.exe
geckodriver.log
__pycache__/
\ No newline at end of file
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class ListsConfig(AppConfig):
name = 'lists'
def counter_comment(number):
if number == 0:
return 'yey, waktunya libur'
if number < 5:
return 'sibuk tapi santai'
if number >= 5:
return 'oh tidak'
return 'input tidak valid'
\ No newline at end of file
from django.db import models
class Item(models.Model):
text = models.TextField(default='')
\ No newline at end of file
<html>
<title>To-Do lists</title>
<body>
<h1>Your To-Do list</h1>
<form method="POST">
<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />
{% csrf_token %}
</form>
<table id="id_list_table">
{% for item in items %}
<tr><td>{{ forloop.counter }}: {{ item.text }}</td></tr>
{% endfor %}
</table>
</body>
</html>
\ No newline at end of file
from django.urls import reverse
from django.test import TestCase, Client
from django.http import HttpRequest
from .models import Item
from .views import home_page
from .helper import counter_comment
class HomePageTest(TestCase):
def test_root_url_resolves_to_home_page_view(self):
response = Client().get('/')
self.assertEqual(response.status_code,200)
def test_home_page_returns_correct_html(self):
request = HttpRequest() #1
response = home_page(request) #2
self.assertTrue(response.content.startswith(b'<html>')) #3
self.assertIn(b'<title>To-Do lists</title>', response.content)
self.assertIn(b'yey, waktunya libur', response.content)
self.assertTrue(response.content.endswith(b'</html>')) #5
def test_home_page_only_saves_items_when_necessary(self):
request = HttpRequest()
home_page(request)
self.assertEqual(Item.objects.count(), 0)
def test_home_page_can_save_a_POST_request(self):
request = HttpRequest()
request.method = 'POST'
request.POST['item_text'] = 'A new list item'
response = home_page(request)
self.assertEqual(Item.objects.count(), 1)
self.assertIn(b'sibuk tapi santai', response.content)
new_item = Item.objects.first()
self.assertEqual(new_item.text, 'A new list item')
self.assertEqual(response.status_code, 302)
self.assertEqual(response['location'], '/lists/')
def test_home_page_displays_all_list_items(self):
Item.objects.create(text='itemey 1')
Item.objects.create(text='itemey 2')
request = HttpRequest()
response = home_page(request)
self.assertIn('itemey 1', response.content.decode())
self.assertIn('itemey 2', response.content.decode())
def test_home_page_redirects_after_POST(self):
request = HttpRequest()
request.method = 'POST'
request.POST['item_text'] = 'A new list item'
response = home_page(request)
self.assertEqual(response.status_code, 302)
self.assertEqual(response['location'], '/lists/')
class ItemModelTest(TestCase):
def test_saving_and_retrieving_items(self):
first_item = Item()
first_item.text = 'The first (ever) list item'
first_item.save()
second_item = Item()
second_item.text = 'Item the second'
second_item.save()
saved_items = Item.objects.all()
self.assertEqual(saved_items.count(), 2)
first_saved_item = saved_items[0]
second_saved_item = saved_items[1]
self.assertEqual(first_saved_item.text, 'The first (ever) list item')
self.assertEqual(second_saved_item.text, 'Item the second')
class HelperTest(TestCase):
def helper_counterTest(self):
counter_zero = counter_comment(0)
counter_one = counter_comment(1)
counter_five = counter_comment(5)
counter_not_valid = counter_comment(-1)
self.assertEqual(counter_zero, 'yey, waktunya libur')
self.assertEqual(counter_one, 'sibuk tapi santai')
self.assertEqual(counter_five, 'oh tidak')
self.assertEqual(counter_not_valid, 'input tidak valid')
\ No newline at end of file
from django.conf.urls import url
from .views import home_page
#url for app
urlpatterns = [
url(r'^$', home_page, name='home_page'),
url(r'^view', home_page, name='home_page'),
]
\ No newline at end of file
from django.shortcuts import redirect, render
from .models import Item
def home_page(request):
if request.method == 'POST':
Item.objects.create(text=request.POST['item_text'])
return redirect('/lists/')
items = Item.objects.all()
return render(request, 'home.html', {'items': items})
\ No newline at end of file
......@@ -2,7 +2,7 @@ def counter_comment(number):
if number == 0:
return 'yey, waktunya libur'
if number < 5:
if (number < 5 and number > 0):
return 'sibuk tapi santai'
if number >= 5:
......
......@@ -6,11 +6,13 @@
<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />
{% csrf_token %}
</form>
<h1>{{ comment }}</h1>
<table id="id_list_table">
{% for item in items %}
<tr><td>{{ forloop.counter }}: {{ item.text }}</td></tr>
{% endfor %}
{% endfor %}
</table>
</body>
</html>
\ No newline at end of file
......@@ -33,13 +33,16 @@ class HomePageTest(TestCase):
response = home_page(request)
self.assertEqual(Item.objects.count(), 1)
self.assertIn(b'sibuk tapi santai', response.content)
new_item = Item.objects.first()
self.assertEqual(new_item.text, 'A new list item')
self.assertEqual(response.status_code, 302)
self.assertEqual(response['location'], '/lists/')
request = HttpRequest()
response = home_page(request)
self.assertIn(b'sibuk tapi santai', response.content)
def test_home_page_displays_all_list_items(self):
Item.objects.create(text='itemey 1')
Item.objects.create(text='itemey 2')
......@@ -60,7 +63,7 @@ class HomePageTest(TestCase):
self.assertEqual(response.status_code, 302)
self.assertEqual(response['location'], '/lists/')
class ItemModelTest(TestCase):
class OtherTest(TestCase):
def test_saving_and_retrieving_items(self):
first_item = Item()
......@@ -79,9 +82,7 @@ class ItemModelTest(TestCase):
self.assertEqual(first_saved_item.text, 'The first (ever) list item')
self.assertEqual(second_saved_item.text, 'Item the second')
class HelperTest(TestCase):
def helper_counterTest(self):
def test_helper_counterTest(self):
counter_zero = counter_comment(0)
counter_one = counter_comment(1)
counter_five = counter_comment(5)
......@@ -91,5 +92,7 @@ class HelperTest(TestCase):
self.assertEqual(counter_one, 'sibuk tapi santai')
self.assertEqual(counter_five, 'oh tidak')
self.assertEqual(counter_not_valid, 'input tidak valid')
\ No newline at end of file
from django.shortcuts import redirect, render
from .models import Item
from .helper import counter_comment
def home_page(request):
if request.method == 'POST':
......@@ -7,4 +8,5 @@ def home_page(request):
return redirect('/lists/')
items = Item.objects.all()
return render(request, 'todo/home.html', {'items': items})
\ No newline at end of file
comment = counter_comment(Item.objects.count())
return render(request, 'todo/home.html', {'items': items, 'comment' : comment})
\ No newline at end of file
......@@ -18,10 +18,10 @@ from django.conf.urls import url, include
from django.urls import path
import personal_page.urls as personal_page
import personal_todo.urls as todo
import personal_todo.urls as lists
urlpatterns = [
url('admin/', admin.site.urls),
url(r'^', include((personal_page, 'personal_page'), namespace='personal_page')),
url(r'^todo/', include((todo, 'todo'), namespace='todo'))
url(r'^lists/', include((lists, 'lists'), namespace='lists'))
]
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