| 1 |
""" |
| 2 |
Configuration and launcher for dbbackup tests. |
| 3 |
""" |
| 4 |
|
| 5 |
import os |
| 6 |
import sys |
| 7 |
|
| 8 |
from dotenv import load_dotenv |
| 9 |
|
| 10 |
test = len(sys.argv) <= 1 or sys.argv[1] == "test" |
| 11 |
if not test: |
| 12 |
load_dotenv() |
| 13 |
|
| 14 |
DEBUG = False |
| 15 |
|
| 16 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 17 |
# Use a repository local tmp directory instead of system /tmp to improve |
| 18 |
# cross-platform compatibility (especially on Windows) and to avoid |
| 19 |
# permission or cleanup issues on shared CI runners. |
| 20 |
REPO_TMP_DIR = os.path.join(BASE_DIR, "..", "tmp") |
| 21 |
os.makedirs(REPO_TMP_DIR, exist_ok=True) |
| 22 |
TESTAPP_DIR = os.path.join(BASE_DIR, "testapp/") |
| 23 |
BLOB_DIR = os.path.join(TESTAPP_DIR, "blobs/") |
| 24 |
|
| 25 |
ADMINS = (("ham", "foo@bar"),) |
| 26 |
ALLOWED_HOSTS = ["*"] |
| 27 |
MIDDLEWARE_CLASSES = () |
| 28 |
ROOT_URLCONF = "tests.testapp.urls" |
| 29 |
SECRET_KEY = "it's a secret to everyone" |
| 30 |
SITE_ID = 1 |
| 31 |
MEDIA_ROOT = os.environ.get("MEDIA_ROOT") or os.path.join(REPO_TMP_DIR, "media") |
| 32 |
os.makedirs(MEDIA_ROOT, exist_ok=True) |
| 33 |
INSTALLED_APPS = ( |
| 34 |
"dbbackup", |
| 35 |
"tests.testapp", |
| 36 |
) |
| 37 |
DEFAULT_AUTO_FIELD = "django.db.models.AutoField" |
| 38 |
|
| 39 |
DATABASES = { |
| 40 |
"default": { |
| 41 |
"ENGINE": os.environ.get("DB_ENGINE", "django.db.backends.sqlite3"), |
| 42 |
# Default DB file stored inside repository tmp directory |
| 43 |
"NAME": os.environ.get("DB_NAME", os.path.join(REPO_TMP_DIR, "test_db.sqlite3")), |
| 44 |
"USER": os.environ.get("DB_USER"), |
| 45 |
"PASSWORD": os.environ.get("DB_PASSWORD"), |
| 46 |
"HOST": os.environ.get("DB_HOST"), |
| 47 |
"PORT": os.environ.get("DB_PORT"), |
| 48 |
} |
| 49 |
} |
| 50 |
if os.environ.get("CONNECTOR"): |
| 51 |
CONNECTOR = {"CONNECTOR": os.environ["CONNECTOR"]} |
| 52 |
DBBACKUP_CONNECTORS = {"default": CONNECTOR} |
| 53 |
|
| 54 |
CACHES = { |
| 55 |
"default": { |
| 56 |
"BACKEND": "django.core.cache.backends.locmem.LocMemCache", |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
SERVER_EMAIL = "[email protected]" |
| 61 |
EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend" |
| 62 |
|
| 63 |
DBBACKUP_GPG_RECIPIENT = "test@test" |
| 64 |
DBBACKUP_GPG_ALWAYS_TRUST = (True,) |
| 65 |
|
| 66 |
STORAGES = { |
| 67 |
"default": { |
| 68 |
"BACKEND": "django.core.files.storage.FileSystemStorage", |
| 69 |
"OPTIONS": {}, |
| 70 |
}, |
| 71 |
"dbbackup": { |
| 72 |
"BACKEND": os.environ.get("STORAGE", "tests.utils.FakeStorage"), |
| 73 |
"OPTIONS": dict([ |
| 74 |
keyvalue.split("=") for keyvalue in os.environ.get("STORAGE_OPTIONS", "").split(",") if keyvalue |
| 75 |
]), |
| 76 |
}, |
| 77 |
} |
| 78 |
|
| 79 |
LOGGING = { |
| 80 |
"version": 1, |
| 81 |
"disable_existing_loggers": False, |
| 82 |
"root": {"handlers": ["console"], "level": "DEBUG"}, |
| 83 |
"handlers": { |
| 84 |
"console": { |
| 85 |
"level": os.getenv("DJANGO_LOG_LEVEL", "INFO"), |
| 86 |
"class": "logging.StreamHandler", |
| 87 |
"formatter": "simple", |
| 88 |
} |
| 89 |
}, |
| 90 |
"formatters": { |
| 91 |
"verbose": { |
| 92 |
"format": "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s", |
| 93 |
"datefmt": "%d/%b/%Y %H:%M:%S", |
| 94 |
}, |
| 95 |
"simple": {"format": "%(levelname)s %(message)s"}, |
| 96 |
}, |
| 97 |
"loggers": { |
| 98 |
"django.db.backends": { |
| 99 |
# uncomment to see all queries |
| 100 |
# 'level': 'DEBUG', |
| 101 |
"handlers": ["console"], |
| 102 |
} |
| 103 |
}, |
| 104 |
} |
| 105 |
|
| 106 |
# let there be silence |
| 107 |
DEFAULT_AUTO_FIELD = "django.db.models.AutoField" |