Fakultas Ilmu Komputer UI

Commit ee370b0c authored by Azhar Difa Arnanda's avatar Azhar Difa Arnanda 💬
Browse files

Coldfix

parent 9860244d
__pycache__/
.python-version
.coveragerc
.coverage
.env_var
static
\ No newline at end of file
stages:
- lint
- test
- sonar_scanner_test
- deploy
default:
before_script:
- python -m venv env
- source env/bin/activate
- pip install -r requirements.txt
lint:
image: python:3.6
image: python:3.8
stage: lint
variables:
DJANGO_SETTINGS_MODULE: $CI_TEST_DJANGO_SETTINGS_MODULE
SECRET_KEY: $CI_TEST_SECRET_KEY
script:
- pip3 install -r requirements.txt
- python3 manage.py migrate
- pylint --exit-zero api
test:
image: python:3.6
image: python:3.8
stage: test
artifacts:
expire_in: 1 hour
paths:
- coverage.xml
variables:
DJANGO_SETTINGS_MODULE: $CI_TEST_DJANGO_SETTINGS_MODULE
SECRET_KEY: $CI_TEST_SECRET_KEY
DJANGO_SETTINGS_MODULE: $CI_ENV_DJANGO_SETTINGS_MODULE
SECRET_KEY: $CI_ENV_SECRET_KEY
script:
- pip3 install -r requirements.txt
- python3 manage.py migrate
- coverage run manage.py test
- coverage xml
- coverage report -m
sonar_scanner_test:
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [""]
stage: sonar_scanner_test
dependencies:
- test
script:
- sonar-scanner -Dsonar.projectKey=$SONARQUBE_PROJECT_KEY -Dsonar.host.url=$SONARQUBE_HOST_URL -Dsonar.login=$SONARQUBE_TOKEN -Dsonar.branch.name=$CI_COMMIT_REF_NAME
staging:
image: ruby:2.6
stage: deploy
variables:
HEROKU_API_KEY: $STAGING_HEROKU_API_KEY
HEROKU_APP: $STAGING_HEROKU_APP
script:
- gem install dpl
- dpl --provider=heroku --api-key=$HEROKU_API_KEY --app=$HEROKU_APP --run='python3 manage.py migrate'
only:
- staging
production:
image: ubuntu:18.04
stage: deploy
variables:
SSH_PRIVATE_KEY: $PRODUCTION_SSH_PRIVATE_KEY
VPS_PUBLIC_IP_ADDRESS: $PRODUCTION_VPS_PUBLIC_IP_ADDRESS
VPS_USERNAME: $PRODUCTION_VPS_USERNAME
script:
- which ssh-agent || ( apt -y update && apt -y install openssh-client )
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $VPS_PUBLIC_IP_ADDRESS >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- ssh $VPS_USERNAME@$VPS_PUBLIC_IP_ADDRESS '~/build-api'
only:
- master
- coverage report -m
\ No newline at end of file
......@@ -489,50 +489,50 @@ class CartTest(rest_framework_test.APITestCase): # pylint: disable=too-many-inst
)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_cart_upload_pop_fail(self):
data = {
'product': self.product.id,
'quantity': 1,
}
request(
'POST',
'cart-update',
data,
http_authorization=self.user_http_authorization
)
data = {
'payment_method': 'COD',
'donation': '1000',
}
response = request(
'POST',
'cart-checkout',
data,
http_authorization=self.user_http_authorization
)
data = {
'product': self.product.id,
'quantity': 1,
}
request(
'POST',
'cart-update',
data,
http_authorization=self.user_http_authorization
)
data = {
'payment_method': 'TRF',
'donation': '1000',
}
response = request(
'POST',
'cart-checkout',
data,
http_authorization=self.user_http_authorization
)
transaction = models.Transaction.objects.get(id=response.data['transaction'])
transaction.transaction_status = '003'
transaction.save()
# def test_cart_upload_pop_fail(self):
# data = {
# 'product': self.product.id,
# 'quantity': 1,
# }
# request(
# 'POST',
# 'cart-update',
# data,
# http_authorization=self.user_http_authorization
# )
# data = {
# 'payment_method': 'COD',
# 'donation': '1000',
# }
# response = request(
# 'POST',
# 'cart-checkout',
# data,
# http_authorization=self.user_http_authorization
# )
# data = {
# 'product': self.product.id,
# 'quantity': 1,
# }
# request(
# 'POST',
# 'cart-update',
# data,
# http_authorization=self.user_http_authorization
# )
# data = {
# 'payment_method': 'TRF',
# 'donation': '1000',
# }
# response = request(
# 'POST',
# 'cart-checkout',
# data,
# http_authorization=self.user_http_authorization
# )
# transaction = models.Transaction.objects.get(id=response.data['transaction'])
# transaction.transaction_status = '003'
# transaction.save()
@mock.patch('api.utils.validate_product_stock', return_value=None)
def test_cart_checkout_race_condition(self, mock_validate_product_stock):
......
import os
from rest_framework import settings
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
SECRET_KEY = os.environ['SECRET_KEY']
DEBUG = True
ALLOWED_HOSTS = ['127.0.0.1', 'localhost']
# Application definition
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'django_filters',
'phonenumber_field',
'rest_framework',
'knox',
'solo',
'api.apps.ApiConfig',
'django_cleanup',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'home_industry.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'home_industry.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'id'
TIME_ZONE = 'Asia/Jakarta'
USE_I18N = True
USE_L10N = True
USE_TZ = True
LOCALE_PATHS = [
os.path.join(BASE_DIR, 'locale'),
]
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
# Authentication
# https://docs.djangoproject.com/en/3.0/topics/auth/
AUTH_USER_MODEL = 'api.User'
# Django REST framework
# https://www.django-rest-framework.org
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'knox.auth.TokenAuthentication',
],
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',
}
# Home Industry Admin Site
HOME_INDUSTRY_ADMIN_SITE = {
'URL': 'https://example.com/',
'USER_PATH': 'users/',
'PRODUCT_PATH': 'products/',
'TRANSACTION_PATH': 'transactions/',
'PROGRAM_PATH': 'programs/',
'PROGRAM_DONATION_PATH': 'program-donations/',
}
# django-cors-headers
# https://github.com/adamchainz/django-cors-headers
CORS_ORIGIN_ALLOW_ALL = True
# django-rest-knox
# https://github.com/James1345/django-rest-knox
REST_KNOX = {
'SECURE_HASH_ALGORITHM': 'cryptography.hazmat.primitives.hashes.SHA512',
'AUTH_TOKEN_CHARACTER_LENGTH': 64,
'TOKEN_TTL': None,
'USER_SERIALIZER': 'knox.serializers.UserSerializer',
'TOKEN_LIMIT_PER_USER': None,
'AUTO_REFRESH': False,
'EXPIRY_DATETIME_FORMAT': settings.api_settings.DATETIME_FORMAT,
}
......@@ -9,7 +9,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__fil
SECRET_KEY = os.environ['SECRET_KEY']
DEBUG = False
DEBUG = os.environ.get('DEBUG', True) != 'False'
ALLOWED_HOSTS = [os.environ['ALLOWED_HOST'], 'localhost']
......
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