Fakultas Ilmu Komputer UI

Verified Commit 6e6c5ec6 authored by Muhammad Ariq Basyar's avatar Muhammad Ariq Basyar
Browse files

[REFACTOR] change default databases to sqlite3 when running test

using sys.argv to check if doing test or not and change databases to default
parent b072b73e
...@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.0/ref/settings/ ...@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.0/ref/settings/
""" """
import os import os
import sys
from datetime import timedelta from datetime import timedelta
from dotenv import load_dotenv from dotenv import load_dotenv
...@@ -94,11 +95,13 @@ WSGI_APPLICATION = 'pplbackend.wsgi.application' ...@@ -94,11 +95,13 @@ WSGI_APPLICATION = 'pplbackend.wsgi.application'
# Database # Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases # 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 = { DATABASES = {
'default': { 'default': DEFAULT_DATABASE
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
} }
# custom database host, overriding the default # custom database host, overriding the default
...@@ -112,6 +115,10 @@ if os.getenv('DB_HOST') is not None: ...@@ -112,6 +115,10 @@ if os.getenv('DB_HOST') is not None:
'PORT': os.getenv('DB_PORT'), 'PORT': os.getenv('DB_PORT'),
} }
# use default database when running test
if 'test' in sys.argv:
DATABASES['default'] = DEFAULT_DATABASE
# Password validation # Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
......
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