From 478b429a24cd4efb2ee9107ea9922dda27111c36 Mon Sep 17 00:00:00 2001
From: Bryan Brancotte <bryan.brancotte@pasteur.fr>
Date: Wed, 27 Mar 2019 12:51:38 +0100
Subject: [PATCH] Testing app in CI

---
 .gitlab-ci.yml                        |  25 +++++
 requirements.txt                      |   3 +
 runtests.py                           |  35 +++++++
 test_app_1/__init__.py                |   0
 test_app_1/apps.py                    |   5 +
 test_app_1/migrations/0001_initial.py |  29 ++++++
 test_app_1/migrations/__init__.py     |   0
 test_app_1/models.py                  |  19 ++++
 tests/__init__.py                     |   0
 tests/settings.py                     | 140 ++++++++++++++++++++++++++
 tests/urls.py                         |  12 +++
 tests/wsgi.py                         |  16 +++
 12 files changed, 284 insertions(+)
 create mode 100644 .gitlab-ci.yml
 create mode 100644 requirements.txt
 create mode 100755 runtests.py
 create mode 100644 test_app_1/__init__.py
 create mode 100644 test_app_1/apps.py
 create mode 100644 test_app_1/migrations/0001_initial.py
 create mode 100644 test_app_1/migrations/__init__.py
 create mode 100644 test_app_1/models.py
 create mode 100644 tests/__init__.py
 create mode 100644 tests/settings.py
 create mode 100644 tests/urls.py
 create mode 100644 tests/wsgi.py

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..c9b9bf1
--- /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 0000000..a924cbe
--- /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 0000000..4daabbb
--- /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 0000000..e69de29
diff --git a/test_app_1/apps.py b/test_app_1/apps.py
new file mode 100644
index 0000000..ebde9bd
--- /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 0000000..9b2fa4d
--- /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 0000000..e69de29
diff --git a/test_app_1/models.py b/test_app_1/models.py
new file mode 100644
index 0000000..6cbd8fe
--- /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 0000000..e69de29
diff --git a/tests/settings.py b/tests/settings.py
new file mode 100644
index 0000000..afd5505
--- /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 0000000..ba23856
--- /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 0000000..ea84ab2
--- /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()
-- 
GitLab