test: flatten test project

This commit is contained in:
Mike 2021-07-04 08:58:33 -07:00
parent f1c4328327
commit 86ccff34e9
7 changed files with 324 additions and 0 deletions

31
manage.py Executable file
View file

@ -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()

0
test_project/__init__.py Normal file
View file

5
test_project/apps.py Normal file
View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class TestAppConfig(AppConfig):
name = 'test_project'

View file

@ -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',
),
),
],
),
]

View file

69
test_project/models.py Normal file
View file

@ -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

99
test_project/settings.py Normal file
View file

@ -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/'