diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..c9b9bf1c1e8bfde52ec3374cc332b9d97761b89a --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,25 @@ +image: docker:latest + +stages: + - test + +test35: + stage: test + image: python:3.5 + script: + - pip install -r requirements.txt + - coverage run --source='basetheme_bootstrap' runtests.py && coverage report -m + +test36: + stage: test + image: python:3.6 + script: + - pip install -r requirements.txt + - coverage run --source='basetheme_bootstrap' runtests.py && coverage report -m + +test37: + stage: test + image: python:3.7 + script: + - pip install -r requirements.txt + - coverage run --source='basetheme_bootstrap' runtests.py && coverage report -m diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..a924cbe8f2ab3bea514ec9a747e57c0aa040f841 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +django +django-crispy-forms +coverage \ No newline at end of file diff --git a/runtests.py b/runtests.py new file mode 100755 index 0000000000000000000000000000000000000000..4daabbbe95251cb51291df32f77df24f164fd5c9 --- /dev/null +++ b/runtests.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +import os +import sys + +import django +from django.conf import settings +from django.core.cache import cache +from django.test.utils import get_runner + + +def runtests(): + test_dir = os.path.dirname(__file__) + sys.path.insert(0, test_dir) + os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' + django.setup() + TestRunner = get_runner(settings) + test_runner = TestRunner() + # failures = test_runner.run_tests(["basetheme_bootstrap.tests.SignUpTestsUserPrefDown"], verbosity=1, interactive=True) + failures = test_runner.run_tests([], verbosity=1, interactive=True) + if bool(failures): + print(failures) + sys.exit(1) + + +# def run_all_tests(): +# os.environ['BASETHEME_BOOTSTRAP_USER_PREFERENCE_MODEL_ENABLED'] = str(True) +# runtests() +# os.environ['BASETHEME_BOOTSTRAP_USER_PREFERENCE_MODEL_ENABLED'] = str(False) +# runtests() +# +# sys.exit(0) + + +if __name__ == '__main__': + runtests() diff --git a/test_app_1/__init__.py b/test_app_1/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/test_app_1/apps.py b/test_app_1/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..ebde9bdb56e079e083257fd6702ea29fa4c23605 --- /dev/null +++ b/test_app_1/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class TestApp1Config(AppConfig): + name = 'test_app_1' diff --git a/test_app_1/migrations/0001_initial.py b/test_app_1/migrations/0001_initial.py new file mode 100644 index 0000000000000000000000000000000000000000..9b2fa4d1b056d6d5038b4e6b8920a11b38bd27ac --- /dev/null +++ b/test_app_1/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# Generated by Django 2.1.7 on 2019-03-26 16:52 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='MyUserPreferences', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('hide_help', models.BooleanField(default=False, help_text='hide_help__help_text', verbose_name='hide_help__verbose_name')), + ('a_time_field', models.TimeField(blank=True, help_text='a_time_field_UTC__help_text', null=True, verbose_name='a_time_field__verbose_name')), + ('user', models.ForeignKey(blank=True, help_text='Leave blank for default user', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='user_preferences', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/test_app_1/migrations/__init__.py b/test_app_1/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/test_app_1/models.py b/test_app_1/models.py new file mode 100644 index 0000000000000000000000000000000000000000..6cbd8fe4a7e12a08cd6d7ac1aaf49fed11d8cf8d --- /dev/null +++ b/test_app_1/models.py @@ -0,0 +1,19 @@ +from django.conf import settings +from django.db import models +from django.utils.translation import gettext_lazy as _ + +from basetheme_bootstrap import user_preferences + + +class MyUserPreferences(user_preferences.UserPreferencesAbstractModel, models.Model): + hide_help = models.BooleanField( + verbose_name=_("hide_help__verbose_name"), + help_text=_("hide_help__help_text"), + default=False, + ) + a_time_field = models.TimeField( + verbose_name=_("a_time_field__verbose_name"), + help_text=_("a_time_field_%(tz)s__help_text") % dict(tz=settings.TIME_ZONE), + null=True, + blank=True, + ) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/settings.py b/tests/settings.py new file mode 100644 index 0000000000000000000000000000000000000000..afd5505734b4bef0ec2b517e00e703cf8b2fc560 --- /dev/null +++ b/tests/settings.py @@ -0,0 +1,140 @@ +""" +Django settings for test_proj project. + +Generated by 'django-admin startproject' using Django 2.1.7. + +For more information on this file, see +https://docs.djangoproject.com/en/2.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.1/ref/settings/ +""" + + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '110qzc77+t2o8cp&ijk!mpxb=*)7v*!xs2pj^t5=#=n*seo$i!' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'crispy_forms', + 'basetheme_bootstrap', + 'test_app_1', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'tests.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', + 'basetheme_bootstrap.context_processors.processors', + ], + }, + }, +] + +WSGI_APPLICATION = 'tests.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.1/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/2.1/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/2.1/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.1/howto/static-files/ + +STATIC_URL = '/static/' + +################################################################################ +# django-crispy-forms +################################################################################ +CRISPY_TEMPLATE_PACK = 'bootstrap4' + +################################################################################ +# basetheme_bootstrap +################################################################################ +BASETHEME_BOOTSTRAP_TEMPLATE_LOCATION_PROJECT = "test_app_1" +BASETHEME_BOOTSTRAP_USER_PREFERENCE_MODEL_ENABLED = True +BASETHEME_BOOTSTRAP_USER_PREFERENCE_MODEL_LOCATION_APP = "test_app_1" +BASETHEME_BOOTSTRAP_USER_PREFERENCE_MODEL_NAME = "MyUserPreferences" + +################################################################################ diff --git a/tests/urls.py b/tests/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..ba23856467f6b458dfa9ee1488b2a0146f5bfeeb --- /dev/null +++ b/tests/urls.py @@ -0,0 +1,12 @@ +from django.http import HttpResponse +from django.urls import path, include + + +def blabla(request): + return HttpResponse("ee") + + +urlpatterns = [ + path('', blabla, name='home'), + path('', include('basetheme_bootstrap.urls')), +] diff --git a/tests/wsgi.py b/tests/wsgi.py new file mode 100644 index 0000000000000000000000000000000000000000..ea84ab2fa256b83bdb3453c34a4df3afa58acf97 --- /dev/null +++ b/tests/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for time_tracking project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.settings') + +application = get_wsgi_application()