From 597a5374dc3a241841750ffa1d5a13b3c6417e36 Mon Sep 17 00:00:00 2001 From: Mike <22396211+Dresdn@users.noreply.github.com> Date: Thu, 17 Jun 2021 16:38:06 -0700 Subject: [PATCH] tests: add new django_test_app to use for testing --- django_test_app/django_test_app/__init__.py | 0 django_test_app/django_test_app/settings.py | 111 ++++++++++++++++ django_test_app/django_test_app/urls.py | 21 +++ django_test_app/django_test_app/wsgi.py | 16 +++ django_test_app/main_app/__init__.py | 0 django_test_app/main_app/admin.py | 3 + django_test_app/main_app/apps.py | 5 + .../main_app/migrations/0001_initial.py | 120 ++++++++++++++++++ .../main_app/migrations/__init__.py | 0 django_test_app/main_app/models.py | 58 +++++++++ django_test_app/main_app/tests.py | 3 + django_test_app/main_app/views.py | 3 + django_test_app/manage.py | 10 ++ manage.py | 13 -- 14 files changed, 350 insertions(+), 13 deletions(-) create mode 100644 django_test_app/django_test_app/__init__.py create mode 100644 django_test_app/django_test_app/settings.py create mode 100644 django_test_app/django_test_app/urls.py create mode 100644 django_test_app/django_test_app/wsgi.py create mode 100644 django_test_app/main_app/__init__.py create mode 100644 django_test_app/main_app/admin.py create mode 100644 django_test_app/main_app/apps.py create mode 100644 django_test_app/main_app/migrations/0001_initial.py create mode 100644 django_test_app/main_app/migrations/__init__.py create mode 100644 django_test_app/main_app/models.py create mode 100644 django_test_app/main_app/tests.py create mode 100644 django_test_app/main_app/views.py create mode 100755 django_test_app/manage.py delete mode 100755 manage.py diff --git a/django_test_app/django_test_app/__init__.py b/django_test_app/django_test_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_test_app/django_test_app/settings.py b/django_test_app/django_test_app/settings.py new file mode 100644 index 0000000..0f46484 --- /dev/null +++ b/django_test_app/django_test_app/settings.py @@ -0,0 +1,111 @@ +""" +Django settings for django_test_app project. + +Generated by 'django-admin startproject' using Django 3.1.5. + +For more information on this file, see +https://docs.djangoproject.com/en/3.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.1/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().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 = '$s149z%i@q3941y3g8^7k@@v%4-hn-$zhk&9$y&w9kbis9n&w3' + +# 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', + # Custom: + 'main_app', + # 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', +] + +ROOT_URLCONF = 'django_test_app.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', + ], + }, + }, +] + +WSGI_APPLICATION = 'django_test_app.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.1/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# 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/' diff --git a/django_test_app/django_test_app/urls.py b/django_test_app/django_test_app/urls.py new file mode 100644 index 0000000..e68e57c --- /dev/null +++ b/django_test_app/django_test_app/urls.py @@ -0,0 +1,21 @@ +"""django_test_app URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.1/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/django_test_app/django_test_app/wsgi.py b/django_test_app/django_test_app/wsgi.py new file mode 100644 index 0000000..8d6c2ae --- /dev/null +++ b/django_test_app/django_test_app/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for django_test_app 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/3.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_test_app.settings') + +application = get_wsgi_application() diff --git a/django_test_app/main_app/__init__.py b/django_test_app/main_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_test_app/main_app/admin.py b/django_test_app/main_app/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/django_test_app/main_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/django_test_app/main_app/apps.py b/django_test_app/main_app/apps.py new file mode 100644 index 0000000..2e344d9 --- /dev/null +++ b/django_test_app/main_app/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class MyAppConfig(AppConfig): + name = 'main_app' diff --git a/django_test_app/main_app/migrations/0001_initial.py b/django_test_app/main_app/migrations/0001_initial.py new file mode 100644 index 0000000..5747d7a --- /dev/null +++ b/django_test_app/main_app/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='main_app.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='main_app.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='main_app.patient', + ), + ), + ], + ), + ] diff --git a/django_test_app/main_app/migrations/__init__.py b/django_test_app/main_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_test_app/main_app/models.py b/django_test_app/main_app/models.py new file mode 100644 index 0000000..7a0950f --- /dev/null +++ b/django_test_app/main_app/models.py @@ -0,0 +1,58 @@ +from django.db import models + +from eav.decorators import register_eav +from eav.models import EAVModelMeta + + +class Patient(models.Model): + 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(models.Model): + 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(models.Model): + name = models.CharField(max_length=12) + + def __unicode__(self): + return self.name + + +@register_eav() +class M2MModel(models.Model): + name = models.CharField(max_length=12) + models = models.ManyToManyField(ExampleModel) + + def __unicode__(self): + return self.name + + +class ExampleMetaclassModel(models.Model, metaclass=EAVModelMeta): + name = models.CharField(max_length=12) + + def __str__(self): + return self.name + + +class RegisterTestModel(models.Model, metaclass=EAVModelMeta): + name = models.CharField(max_length=12) + + def __str__(self): + return self.name diff --git a/django_test_app/main_app/tests.py b/django_test_app/main_app/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/django_test_app/main_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/django_test_app/main_app/views.py b/django_test_app/main_app/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/django_test_app/main_app/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/django_test_app/manage.py b/django_test_app/manage.py new file mode 100755 index 0000000..f078ec0 --- /dev/null +++ b/django_test_app/manage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + +from django.core.management import execute_from_command_line + +if __name__ == '__main__': + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_test_app.settings') + execute_from_command_line(sys.argv) diff --git a/manage.py b/manage.py deleted file mode 100755 index e0bd3c9..0000000 --- a/manage.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import os -import sys - - -if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.test_settings") - - from django.core.management import execute_from_command_line - - execute_from_command_line(sys.argv)