diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 14182956e34548a0b3e7909ff5e22e26bf9dd1f2..b0274513300b5926dd7205a546c3911aa7c0a08f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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: diff --git a/tutorial/settings.py b/tutorial/settings.py index 9a6ecb9aeaf21b1cdb03058f0f34dbd39959fa41..cda58693232c7501cb293470600b3c3c525dd55d 100644 --- a/tutorial/settings.py +++ b/tutorial/settings.py @@ -46,6 +46,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'tutorial_1', + 'tutorial_2', ] MIDDLEWARE = [ diff --git a/tutorial_1/functional_tests.py b/tutorial_1/functional_tests.py new file mode 100644 index 0000000000000000000000000000000000000000..945fb43a9297d32932ed33428a472017df7a556f --- /dev/null +++ b/tutorial_1/functional_tests.py @@ -0,0 +1,30 @@ +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) diff --git a/tutorial_1/tests.py b/tutorial_1/unit_tests.py similarity index 51% rename from tutorial_1/tests.py rename to tutorial_1/unit_tests.py index 54314c6d0349f69a5c114c514fbbce2bfe11a236..c705780ab795ea0348e3dbf32971a8b93c8511a4 100644 --- a/tutorial_1/tests.py +++ b/tutorial_1/unit_tests.py @@ -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) diff --git a/tutorial_2/__init__.py b/tutorial_2/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tutorial_2/admin.py b/tutorial_2/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..8c38f3f3dad51e4585f3984282c2a4bec5349c1e --- /dev/null +++ b/tutorial_2/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/tutorial_2/apps.py b/tutorial_2/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..47563cba0c3a44e269ccd852de048e162e1f846c --- /dev/null +++ b/tutorial_2/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class Tutorial2Config(AppConfig): + name = 'tutorial_2' diff --git a/tutorial_2/migrations/__init__.py b/tutorial_2/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tutorial_2/models.py b/tutorial_2/models.py new file mode 100644 index 0000000000000000000000000000000000000000..71a836239075aa6e6e4ecb700e9c42c95c022d91 --- /dev/null +++ b/tutorial_2/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/tutorial_2/unit_tests.py b/tutorial_2/unit_tests.py new file mode 100644 index 0000000000000000000000000000000000000000..a4de0ad62de23661a74d2e2bf0314417b83bf9e7 --- /dev/null +++ b/tutorial_2/unit_tests.py @@ -0,0 +1,9 @@ +from django.test import TestCase + + +# Create your tests here. + +class Tutorial2UnitTest(TestCase): + + def test_true(self): + self.assertTrue(1 + 1, 2) diff --git a/tutorial_2/views.py b/tutorial_2/views.py new file mode 100644 index 0000000000000000000000000000000000000000..91ea44a218fbd2f408430959283f0419c921093e --- /dev/null +++ b/tutorial_2/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here.