Fakultas Ilmu Komputer UI

Commit 042001ef authored by Izzan Fakhril Islam's avatar Izzan Fakhril Islam
Browse files

Merge branch 'tutorial-1' into 'master'

Tutorial 1 PMPL Finish

See merge request !3
parents b1c97276 9b09ae68
Pipeline #20230 passed with stages
in 14 minutes and 55 seconds
......@@ -2,37 +2,45 @@ stages:
- test
- deploy
before_script:
- apt-get install -f
- apt-get update -qy
- apt-get install -y python-dev python-pip sudo postgresql postgresql-client libpq-dev libxss1 libappindicator1 libindicator7
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
- echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
- apt-get update -qq && apt-get install -y -qq unzip
- apt-get install -y google-chrome-stable
- export CHROME_BIN=/usr/bin/google-chrome
- google-chrome --version
- apt-get install -y xvfb
- wget https://chromedriver.storage.googleapis.com/77.0.3865.40/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip
- 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"
- pip install --upgrade pip
- pip install -r requirements.txt
- pip install --upgrade --ignore-installed urllib3
- python manage.py makemigrations
- python manage.py migrate
- python manage.py collectstatic --no-input
- python manage.py runserver 8000 &
UnitTest:
stage: test
before_script:
- apt-get install -f
- apt-get update -qy
- apt-get install -y python-dev python-pip sudo postgresql postgresql-client libpq-dev libxss1 libappindicator1 libindicator7
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
- echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
- apt-get update -qq && apt-get install -y -qq unzip
- apt-get install -y google-chrome-stable
- export CHROME_BIN=/usr/bin/google-chrome
- google-chrome --version
- apt-get install -y xvfb
- wget https://chromedriver.storage.googleapis.com/77.0.3865.40/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip
- 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"
- pip install --upgrade pip
- pip install -r requirements.txt
- pip install --upgrade --ignore-installed urllib3
- python manage.py makemigrations
- python manage.py migrate
- python manage.py collectstatic --no-input
- python manage.py runserver 8000 &
when: on_success
script:
- coverage run --include='tutorial_*/*' manage.py test
- coverage run --include='tutorial_*/*' manage.py test -p "unit_test*.py"
- coverage report -m
FunctionalTest:
stage: test
when: on_success
script:
- coverage run --include='tutorial_*/*' manage.py test -p "functional_test*.py"
- coverage report -m
Deployment:
DeployToHeroku:
image: ruby:2.4
stage: deploy
before_script:
......
......@@ -46,6 +46,7 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'tutorial_1',
'tutorial_2',
]
MIDDLEWARE = [
......
from django.test import TestCase
from .views import NAME
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
class Tutorial1FunctionalTest(TestCase):
def setUp(self):
chrome_options = Options()
chrome_options.add_argument('--dns-prefatch-disable')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
self.selenium = webdriver.Chrome('./chromedriver', chrome_options=chrome_options)
super(Tutorial1FunctionalTest, self).setUp()
def tearDown(self):
self.selenium.quit()
super(Tutorial1FunctionalTest, self).tearDown()
def test_find_name(self):
selenium = self.selenium
selenium.get('http://127.0.0.1:8000/tutorial-1/')
self.assertIn(NAME, selenium.page_source)
def test_find_age(self):
selenium = self.selenium
selenium.get('http://127.0.0.1:8000/tutorial-1/')
self.assertIn('21', selenium.page_source)
......@@ -3,8 +3,6 @@ from django.test import Client
from .views import index, NAME, calculate_age
from django.http import HttpRequest
from datetime import date
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# Create your tests here.
......@@ -31,29 +29,3 @@ class Tutorial1UnitTest(TestCase):
self.assertEqual(0, calculate_age(date.today().year))
self.assertEqual(19, calculate_age(2000))
self.assertEqual(29, calculate_age(1990))
class Tutorial1FunctionalTest(TestCase):
def setUp(self):
chrome_options = Options()
chrome_options.add_argument('--dns-prefatch-disable')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
self.selenium = webdriver.Chrome('./chromedriver', chrome_options=chrome_options)
super(Tutorial1FunctionalTest, self).setUp()
def tearDown(self):
self.selenium.quit()
super(Tutorial1FunctionalTest, self).tearDown()
def test_find_name(self):
selenium = self.selenium
selenium.get('http://127.0.0.1:8000/tutorial-1/')
self.assertIn(NAME, selenium.page_source)
def test_find_age(self):
selenium = self.selenium
selenium.get('http://127.0.0.1:8000/tutorial-1/')
self.assertIn('21', selenium.page_source)
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class Tutorial2Config(AppConfig):
name = 'tutorial_2'
from django.db import models
# Create your models here.
from django.test import TestCase
# Create your tests here.
class Tutorial2UnitTest(TestCase):
def test_true(self):
self.assertTrue(1 + 1, 2)
from django.shortcuts import render
# Create your views here.
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