From 86ccff34e9e8df35929f572cabde05ee12b6c457 Mon Sep 17 00:00:00 2001 From: Mike <22396211+Dresdn@users.noreply.github.com> Date: Sun, 4 Jul 2021 08:58:33 -0700 Subject: [PATCH] test: flatten test project --- manage.py | 31 ++++++ test_project/__init__.py | 0 test_project/apps.py | 5 + test_project/migrations/0001_initial.py | 120 ++++++++++++++++++++++++ test_project/migrations/__init__.py | 0 test_project/models.py | 69 ++++++++++++++ test_project/settings.py | 99 +++++++++++++++++++ 7 files changed, 324 insertions(+) create mode 100755 manage.py create mode 100644 test_project/__init__.py create mode 100644 test_project/apps.py create mode 100644 test_project/migrations/0001_initial.py create mode 100644 test_project/migrations/__init__.py create mode 100644 test_project/models.py create mode 100644 test_project/settings.py diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..b0b78e0 --- /dev/null +++ b/manage.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +import os +import sys + + +def main() -> None: + """ + Main function. + + It does several things: + 1. Sets default settings module, if it is not set + 2. Warns if Django is not installed + 3. Executes any given command + """ + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_project.settings') + + try: + from django.core import management # noqa: WPS433 + except ImportError: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + + 'available on your PYTHONPATH environment variable? Did you ' + + 'forget to activate a virtual environment?', + ) + + management.execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/test_project/__init__.py b/test_project/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test_project/apps.py b/test_project/apps.py new file mode 100644 index 0000000..a43bc97 --- /dev/null +++ b/test_project/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class TestAppConfig(AppConfig): + name = 'test_project' diff --git a/test_project/migrations/0001_initial.py b/test_project/migrations/0001_initial.py new file mode 100644 index 0000000..e6c14eb --- /dev/null +++ b/test_project/migrations/0001_initial.py @@ -0,0 +1,120 @@ +# Generated by Django 3.2.4 on 2021-06-17 22:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name='ExampleMetaclassModel', + fields=[ + ( + 'id', + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name='ID', + ), + ), + ('name', models.CharField(max_length=12)), + ], + ), + migrations.CreateModel( + name='ExampleModel', + fields=[ + ( + 'id', + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name='ID', + ), + ), + ('name', models.CharField(max_length=12)), + ], + ), + migrations.CreateModel( + name='RegisterTestModel', + fields=[ + ( + 'id', + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name='ID', + ), + ), + ('name', models.CharField(max_length=12)), + ], + ), + migrations.CreateModel( + name='Patient', + fields=[ + ( + 'id', + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name='ID', + ), + ), + ('name', models.CharField(max_length=12)), + ( + 'example', + models.ForeignKey( + blank=True, + null=True, + on_delete=models.deletion.PROTECT, + to='examplemodel', + ), + ), + ], + ), + migrations.CreateModel( + name='M2MModel', + fields=[ + ( + 'id', + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name='ID', + ), + ), + ('name', models.CharField(max_length=12)), + ('models', models.ManyToManyField(to='ExampleModel')), + ], + ), + migrations.CreateModel( + name='Encounter', + fields=[ + ( + 'id', + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name='ID', + ), + ), + ('num', models.PositiveSmallIntegerField()), + ( + 'patient', + models.ForeignKey( + on_delete=models.deletion.PROTECT, + to='patient', + ), + ), + ], + ), + ] diff --git a/test_project/migrations/__init__.py b/test_project/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test_project/models.py b/test_project/models.py new file mode 100644 index 0000000..a8104a1 --- /dev/null +++ b/test_project/models.py @@ -0,0 +1,69 @@ +from django.db import models + +from eav.decorators import register_eav +from eav.models import EAVModelMeta + + +class TestBase(models.Model): + """Base class for test models.""" + + class Meta(object): + """Define common options.""" + + app_label = 'test_project' + abstract = True + + +class Patient(TestBase): + name = models.CharField(max_length=12) + example = models.ForeignKey( + 'ExampleModel', null=True, blank=True, on_delete=models.PROTECT + ) + + def __str__(self): + return self.name + + def __repr__(self): + return self.name + + +class Encounter(TestBase): + num = models.PositiveSmallIntegerField() + patient = models.ForeignKey(Patient, on_delete=models.PROTECT) + + def __str__(self): + return '%s: encounter num %d' % (self.patient, self.num) + + def __repr__(self): + return self.name + + +@register_eav() +class ExampleModel(TestBase): + name = models.CharField(max_length=12) + + def __unicode__(self): + return self.name + + +@register_eav() +class M2MModel(TestBase): + name = models.CharField(max_length=12) + models = models.ManyToManyField(ExampleModel) + + def __unicode__(self): + return self.name + + +class ExampleMetaclassModel(TestBase, metaclass=EAVModelMeta): + name = models.CharField(max_length=12) + + def __str__(self): + return self.name + + +class RegisterTestModel(TestBase, metaclass=EAVModelMeta): + name = models.CharField(max_length=12) + + def __str__(self): + return self.name diff --git a/test_project/settings.py b/test_project/settings.py new file mode 100644 index 0000000..d62a2ea --- /dev/null +++ b/test_project/settings.py @@ -0,0 +1,99 @@ +from pathlib import Path +from typing import List + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'secret!' # noqa: S105 + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS: List[str] = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'django.contrib.postgres', + # Test Project: + 'test_project.apps.TestAppConfig', + # Our app: + 'eav', +] + +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', +] + +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', + ], + }, + }, +] + + +# Database +# https://docs.djangoproject.com/en/3.1/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:', + }, +} + +DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' + + +# Password validation +# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [] + + +# Internationalization +# https://docs.djangoproject.com/en/3.1/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = False + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.1/howto/static-files/ + +STATIC_URL = '/static/'