Fakultas Ilmu Komputer UI

Commit 3e2ec979 authored by Izzatul Muttaqin's avatar Izzatul Muttaqin
Browse files

Merge branch 'tutorial-3' into 'master'

Tutorial 3

See merge request !4
parents f0335d14 84863147
Pipeline #21722 failed with stages
in 2 minutes and 48 seconds
......@@ -153,4 +153,4 @@ chromedriver
chromedriver.exe
geckodriver.log
__pycache__/
*/migrations/
\ No newline at end of file
*/migrations/
stages:
- test
- deploy
- functional_test
# - functional_test
UnitTest:
image: python:3.6
......@@ -12,11 +12,10 @@ UnitTest:
- pip3 install django-environ
- python3 manage.py makemigrations
- python3 manage.py migrate
- python3 manage.py collectstatic --no-input
- python3 manage.py runserver 8000 &
when: on_success
script:
- coverage run --include='personal_*' manage.py test
- coverage run manage.py test practice
- coverage report -m
Deployment:
......@@ -36,22 +35,22 @@ Deployment:
only:
- master
FunctionalTest:
image: python:3.6
stage: functional_test
before_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
- pip3 install -r requirements.txt
- pip3 install requests
- pip3 install django-environ
- apt-get update -qq && apt-get install -y -qq unzip
- apt-get install -y google-chrome-stable
- apt-get install -y xvfb
- wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip
when: on_success
script:
- python3 functional_tests.py
only:
- master
\ No newline at end of file
# FunctionalTest:
# image: python:3.6
# stage: functional_test
# before_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
# - pip3 install -r requirements.txt
# - pip3 install requests
# - pip3 install django-environ
# - apt-get update -qq && apt-get install -y -qq unzip
# - apt-get install -y google-chrome-stable
# - apt-get install -y xvfb
# - wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip
# - unzip chromedriver_linux64.zip
# when: on_success
# script:
# - python3 functional_tests.py
# only:
# - master
migrate: bash deployment.sh
web: gunicorn testproject.wsgi --log-file -
\ No newline at end of file
web: gunicorn testproject.wsgi --log-file -
# 1606837915-practice
[Izzatul Muttaqin - PMPL A](https://pmpl-project.herokuapp.com/)
\ No newline at end of file
[Izzatul Muttaqin - PMPL A](https://pmpl-project.herokuapp.com/)
## Latihan 3
Test isolation yang dilakukan adalah test dapat berjalan sesuai dengan request dari url liveserver bukan dari url yang ditentukan pada awal yaitu localhost
Fitur yang ditambahkan adalah proses menunggu 10 detik tidak dilakukan hanya dengan serta merta menunggu melainkan dengan proses menunggu dari webdriver hingga input muncul selama 10 detik
\ No newline at end of file
#!/bin/bash
python manage.py makemigrations
python manage.py migrate
\ No newline at end of file
python manage.py migrate
from selenium import webdriver
from django.test import LiveServerTestCase
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.chrome.options import Options
from django.test import LiveServerTestCase
import time
import unittest
import environ
MAX_WAIT = 5
class NewVisitorTest(unittest.TestCase):
class NewVisitorTest(LiveServerTestCase):
def setUp(self):
chrome_options = Options()
chrome_options.add_argument('--dns-prefetch-disable')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('disable-gpu')
try:
self.browser = webdriver.Chrome('./chromedriver.exe', chrome_options=chrome_options)
except:
self.browser = webdriver.Chrome('./chromedriver', chrome_options=chrome_options)
super(NewVisitorTest, self).setUp()
self.browser = webdriver.Chrome()
def tearDown(self):
self.browser.close()
self.browser.quit()
def check_for_row(self, row_text):
table = self.browser.find_element_by_id('id_list_table')
......@@ -30,12 +26,18 @@ class NewVisitorTest(unittest.TestCase):
self.assertIn(row_text, [row.text for row in rows])
def test_can_start_a_list_and_retrieve_it_later(self):
self.browser.get('https://pmpl-project.herokuapp.com/lists')
self.browser.get(self.live_server_url)
self.assertIn('To-Do', self.browser.title)
header_text = self.browser.find_element_by_tag_name('h1').text
self.assertIn('To-Do', header_text)
introduction = self.browser.find_element_by_id("intro")
self.assertIn('Izzatul', introduction.text)
comment = self.browser.find_element_by_id('comment')
self.assertEqual(comment.text, 'yey, waktunya libur')
inputbox = self.browser.find_element_by_id('id_new_item')
self.assertEqual(
inputbox.get_attribute('placeholder'),
......@@ -65,4 +67,4 @@ class NewVisitorTest(unittest.TestCase):
# self.fail('Finish the test!')
if __name__ == '__main__':
unittest.main(warnings='ignore')
\ No newline at end of file
unittest.main(warnings='ignore')
# 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.apps import AppConfig
class PersonalPageConfig(AppConfig):
name = 'personal_page'
from django.db import models
# Create your models here.
<html>
<title>Home Page {{ name }}</title>
<body>
<h1>Hello, this is {{ name }}.</h1>
</body>
</html>
\ No newline at end of file
from django.test import TestCase
from django.test import Client
from django.urls import resolve
from .views import home_page
from django.http import HttpRequest
from unittest import skip
# Create your tests here.
class PersonalPage(TestCase):
def test_url_is_exist(self):
response = Client().get('/')
self.assertEqual(response.status_code,200)
def test_using_home_page_func(self):
found = resolve('/')
self.assertEqual(found.func, home_page)
def test_landing_page_is_completed(self):
request = HttpRequest()
response = home_page(request)
html_response = response.content.decode('utf8')
self.assertIn('Hello, this is Izzatul Muttaqin.', html_response)
from django.shortcuts import render
def home_page(request):
return render(request, 'screen/home.html',{'name': 'Izzatul Muttaqin'})
from django.contrib import admin
# Register your models here.
from django.conf.urls import url
from .views import home_page
#url for app
urlpatterns = [
url(r'^$', home_page, name='home_page'),
]
\ No newline at end of file
from django.apps import AppConfig
class PersonalTodoConfig(AppConfig):
name = 'personal_todo'
class PracticeConfig(AppConfig):
name = 'practice'
......@@ -8,4 +8,4 @@ def counter_comment(number):
if number >= 5:
return 'oh tidak'
return 'input tidak valid'
\ No newline at end of file
return 'input tidak valid'
from django.db import models
# Create your models here.
from django.db import models
class Item(models.Model):
text = models.TextField(default='')
\ No newline at end of file
text = models.TextField(default='')
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