Add tests
This commit is contained in:
parent
7c95dcc654
commit
d41e1da419
|
|
@ -16,6 +16,7 @@ pipelines:
|
|||
- pip3 install -r server/requirements/requirements-dev.txt
|
||||
- git-crypt status -e | sort > git-crypt-encrypted-files-check.txt && diff git-crypt-encrypted-files.txt git-crypt-encrypted-files-check.txt
|
||||
- trufflehog --exclude_paths trufflehog-exclude-patterns.txt --allow trufflehog-allow.json --entropy=True --max_depth=100 .
|
||||
- ./server/run_tests.sh
|
||||
# - ./src/run_pylint.sh
|
||||
# - ./src/run_unittests_coverage.sh
|
||||
- step:
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from pathlib import Path
|
|||
import structlog
|
||||
from environs import Env
|
||||
|
||||
from core.utils import add_app_info
|
||||
from vbv_lernwelt.core.utils import add_app_info
|
||||
|
||||
SERVER_ROOT_DIR = Path(__file__).resolve(strict=True).parent.parent.parent
|
||||
# vbv_lernwelt/
|
||||
|
|
@ -46,7 +46,12 @@ LOCALE_PATHS = [str(SERVER_ROOT_DIR / "locale")]
|
|||
# DATABASES
|
||||
# ------------------------------------------------------------------------------
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
|
||||
DATABASES = {"default": env.dj_db_url("VBV_DATABASE_URL", default="postgres://vbv_lernwelt@localhost:5432/vbv_lernwelt")}
|
||||
DATABASES = {
|
||||
"default": env.dj_db_url(
|
||||
"VBV_DATABASE_URL",
|
||||
default="postgres://vbv_lernwelt@localhost:5432/vbv_lernwelt",
|
||||
)
|
||||
}
|
||||
DATABASES["default"]["ATOMIC_REQUESTS"] = True # noqa F405
|
||||
DATABASES["default"]["CONN_MAX_AGE"] = env.int("CONN_MAX_AGE", default=60) # noqa F405
|
||||
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
|
||||
|
|
@ -303,7 +308,7 @@ else:
|
|||
"handlers": {
|
||||
"file": {
|
||||
"class": "concurrent_log_handler.ConcurrentRotatingFileHandler",
|
||||
"filename": f"{SERVER_ROOT_DIR}/myservice.log",
|
||||
"filename": f"{SERVER_ROOT_DIR}/log/myservice.log",
|
||||
"maxBytes": 1024 * 1024 * 100,
|
||||
"backupCount": 50,
|
||||
"formatter": "json",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
# pylint: disable=unused-wildcard-import,wildcard-import,wrong-import-position
|
||||
import getpass
|
||||
import os
|
||||
|
||||
from .base import * # noqa
|
||||
from .base import env
|
||||
|
|
@ -23,5 +25,27 @@ PASSWORD_HASHERS = ["django.contrib.auth.hashers.MD5PasswordHasher"]
|
|||
# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
|
||||
EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"
|
||||
|
||||
|
||||
class DisableMigrations(dict):
|
||||
def __contains__(self, item):
|
||||
return True
|
||||
|
||||
def __getitem__(self, item):
|
||||
return None
|
||||
|
||||
|
||||
MIGRATION_MODULES = DisableMigrations()
|
||||
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.postgresql_psycopg2",
|
||||
"NAME": "vbv_lernwelt",
|
||||
"USER": os.environ.get("PG_USER", getpass.getuser()),
|
||||
"PASSWORD": os.environ.get("PG_PASSWORD"),
|
||||
"HOST": "localhost",
|
||||
"PORT": os.environ.get("PG_PORT", ""),
|
||||
}
|
||||
}
|
||||
|
||||
# Your stuff...
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
[pytest]
|
||||
addopts = --ds=config.settings.test --reuse-db
|
||||
addopts = --ds=config.settings.test --no-migrations
|
||||
python_files = tests.py test_*.py
|
||||
norecursedirs = node_modules
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
pytest --junitxml=../test-reports/coverage.xml
|
||||
|
|
@ -1 +0,0 @@
|
|||
# Create your tests here.
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import factory
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.hashers import make_password
|
||||
|
||||
|
||||
class SimpleUserFactory(factory.django.DjangoModelFactory):
|
||||
class Meta:
|
||||
model = get_user_model()
|
||||
django_get_or_create = ("username",)
|
||||
|
||||
username = factory.Sequence(lambda n: "user%d" % n)
|
||||
email = factory.LazyAttribute(lambda obj: "%s@example.com" % obj.username)
|
||||
password = make_password("pw")
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
from unittest import skip
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class SimpleTestCase(TestCase):
|
||||
def test_simple(self):
|
||||
self.assertEqual(1, 1)
|
||||
|
||||
@skip("Do not fail in pipelines")
|
||||
def test_fail(self):
|
||||
self.assertEqual(1, 2)
|
||||
Loading…
Reference in New Issue