Fakultas Ilmu Komputer UI

Commit 817060dd authored by Muhammad Ariq Basyar's avatar Muhammad Ariq Basyar
Browse files

Merge branch 'dev-ariq' into 'PBI-2-deployment'

CI/CD

See merge request !6
parents 82130f33 2298e07c
Pipeline #64623 passed with stages
in 16 minutes and 31 seconds
variables:
POSTGRES_DB: $DB_NAME
POSTGRES_USER: $DB_USER
POSTGRES_PASSWORD: $DB_PASSWORD
POSTGRES_HOST_AUTH_METHOD: $DB_HOST_AUTH_METHOD
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_STORAGE_BUCKET_NAME: $AWS_STORAGE_BUCKET_NAME
services:
- postgres:12.2-alpine
stages:
- test
- linter
- sonarqube
- staging
- production
- deployment
UnitTest:
image: python:3.7
......@@ -43,13 +30,15 @@ Pylint:
- pip install -r requirements.txt
when: on_success
script:
- pylint --load-plugins pylint_django --rcfile=./.pylintrc informasi_fasilitas layanan_khusus new_rest_api oauth registrasi
- pylint --load-plugins pylint_django --rcfile=./.pylintrc \
informasi_fasilitas layanan_khusus new_rest_api oauth registrasi
SonarScanner:
image:
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [""]
stage: sonarqube
allow_failure: true
script:
- sonar-scanner
-Dsonar.host.url=https://pmpl.cs.ui.ac.id/sonarqube-advprog
......@@ -57,30 +46,13 @@ SonarScanner:
-Dsonar.branch.name=$CI_COMMIT_REF_NAME
-Dsonar.projectKey=$SONARQUBE_PROJECT_KEY
Staging:
image: ruby:2.4
stage: staging
only:
refs:
- staging
before_script:
- gem install dpl
- wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh
script:
- dpl --provider=heroku --app=$HEROKU_APPNAME_STAGING --api-key=$HEROKU_APIKEY
- export HEROKU_API_KEY=$HEROKU_APIKEY
- heroku run --app $HEROKU_APPNAME_STAGING migrate
environment:
name: staging
url: $HEROKU_APP_HOST_STAGING
Deployment:
image: ruby:2.4
stage: production
stage: deployment
only:
refs:
- master
- staging
- development
before_script:
- apt-get update -qq
- apt-get install -qq git
......@@ -88,16 +60,10 @@ Deployment:
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY" | base64 -d)
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
script:
- >
ssh $TARGET_USER_AT_HOST
"cd bisago-be &&
git checkout master &&
git pull origin master &&
bash stop.sh &&
bash start.sh &&
exit"
- result=$(ssh $TARGET "bash deployment/reload.sh $CI_COMMIT_REF_NAME")
- echo "$result"
- if [ '$(echo "$result" | tail -n 1)' != "success" ]; then exit 1; fi
environment:
name: production
url: $HEROKU_APP_HOST
\ No newline at end of file
name: deployment
......@@ -6,7 +6,7 @@ from django.urls import reverse, path, include
from .models import Lokasi, Fasilitas, Komentar, KURSI_RODA, Likes, Dislikes
NOT_NULL_CONSTRAINT_FAILED_MESSAGE = 'null'
NOT_NULL_CONSTRAINT_FAILED_MESSAGE = 'NOT NULL constraint failed'
REGISTER = '/api/register/'
TOKEN_AUTH = '/api-token-auth/'
......@@ -37,7 +37,7 @@ class InformasiFasilitasTest(TestCase):
'phone_number': 000000000,
'password': "hahagotim"}
lokasi_test_1 = {'id': '1',
lokasi_test_1 = {'id': 1,
'name': 'Ma Homie',
'latitude': 0.1,
'longitude': 0.1,
......
......@@ -3,7 +3,7 @@ from django.db.utils import IntegrityError
from .test_base import InformasiFasilitasTest
from .models import Lokasi, Fasilitas, Komentar, Likes, Dislikes
NOT_NULL_CONSTRAINT_FAILED_MESSAGE = 'null'
NOT_NULL_CONSTRAINT_FAILED_MESSAGE = 'NOT NULL constraint failed'
class InformasiFasilitasModelTest(InformasiFasilitasTest):
......
......@@ -28,7 +28,6 @@ class LokasiRelatedViewTest(InformasiFasilitasViewTest):
response = Client().get(reverse('lokasi-list'))
content = json.loads(response.content.decode('utf-8'))
expected_first_entry = copy.deepcopy(self.lokasi_test_1)
expected_first_entry["id"] = 45
expected_first_entry["image"] = None
expected_json = [expected_first_entry]
self.assertEqual(content, expected_json)
......@@ -48,7 +47,7 @@ class LokasiRelatedViewTest(InformasiFasilitasViewTest):
content = json.loads(response.content.decode('utf-8'))
expected_json = copy.deepcopy(self.lokasi_test_1)
expected_json["image"] = None
expected_json["id"] = 35
# expected_json["id"] = 35
self.assertEqual(content, expected_json)
def test_cannot_post_lokasi_details(self):
......@@ -68,7 +67,13 @@ class LokasiRelatedViewTest(InformasiFasilitasViewTest):
def test_can_post_add_lokasi(self):
client = self.client_user_token()
Lokasi.objects.all().delete()
response = client.post(reverse('add-lokasi'), self.lokasi_test_1)
response_json = json.loads(response.content.decode("utf-8"))
expected_json = copy.deepcopy(self.lokasi_test_1)
expected_json['id'] = 2
expected_json['image'] = None
self.assertEqual(response_json, expected_json)
self.assertEqual(response.status_code, HTTPStatus.CREATED)
def test_post_add_lokasi_missing_key(self):
......@@ -87,17 +92,6 @@ class LokasiRelatedViewTest(InformasiFasilitasViewTest):
expected_json = {"name": ["This field is required."]}
self.assertEqual(response_json, expected_json)
def test_can_post_add_lokasi_json(self):
client = self.client_user_token()
response = client.post(reverse('add-lokasi'),
self.lokasi_test_1)
response_json = json.loads(response.content.decode("utf-8"))
expected_json = copy.deepcopy(self.lokasi_test_1)
expected_json["id"] = 40
expected_json["image"] = None
self.assertEqual(response_json, expected_json)
def test_put_update_detail_lokasi_success(self):
client = self.client_user_token()
urls = reverse('update-lokasi',
......
......@@ -7,7 +7,7 @@ from django.urls import path, include, reverse
from .models import Sekolah, Penyandang, Komunitas
from .serializers import SekolahSerializer, KomunitasSerializer
NOT_NULL_CONSTRAINT_FAILED_MESSAGE = 'null'
NOT_NULL_CONSTRAINT_FAILED_MESSAGE = 'NOT NULL constraint failed'
ID = 'id'
NAME = 'name'
......@@ -247,7 +247,6 @@ class LayananKhususViewsTest(TestCase):
MOCK_PENYANDANG)
content = json.loads(response.content.decode("utf-8"))
expected_json = MOCK_PENYANDANG
expected_json[ID] = 3
self.assertEqual(content, expected_json)
def test_cannot_get_register_penyandang(self):
......@@ -285,12 +284,12 @@ class LayananKhususViewsTest(TestCase):
content = json.loads(response.content.decode('utf-8'))
expected_json = MOCK_KOMUNITAS
self.assertEqual(content, expected_json)
def test_cannot_post_detail_komunitas(self):
response = Client().post(
reverse('detail-komunitas', kwargs={'id_komunitas': 1}))
self.assertEqual(response.status_code, HTTPStatus.METHOD_NOT_ALLOWED)
def test_get_details_komuniras_not_found(self):
response = Client().get(
reverse('detail-komunitas', kwargs={'id_komunitas': 1}))
......
......@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import os
import sys
from datetime import timedelta
from dotenv import load_dotenv
......@@ -94,11 +95,13 @@ WSGI_APPLICATION = 'pplbackend.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DEFAULT_DATABASE = {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
'default': DEFAULT_DATABASE
}
# custom database host, overriding the default
......@@ -112,6 +115,10 @@ if os.getenv('DB_HOST') is not None:
'PORT': os.getenv('DB_PORT'),
}
# use default database when running test
if 'test' in sys.argv:
DATABASES['default'] = DEFAULT_DATABASE
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
......
......@@ -17,4 +17,4 @@ class RegistrationTest(TestCase):
with self.assertRaises(IntegrityError) as error:
obj = BisaGoUser(user=None)
obj.save()
self.assertFalse(str(error.exception).startswith('NOT NULL constraint failed'))
self.assertTrue(str(error.exception).startswith('NOT NULL constraint failed'))
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