Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
move test models to test_app, add migrations, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Sep 2, 2022
1 parent 42aa4c7 commit aee8dee
Show file tree
Hide file tree
Showing 24 changed files with 182 additions and 9 deletions.
11 changes: 11 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python
import os
import sys


if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_app.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
Binary file added test_app/.models.py.swp
Binary file not shown.
Binary file added test_app/.settings.py.swp
Binary file not shown.
Binary file added test_app/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file added test_app/__pycache__/models.cpython-37.pyc
Binary file not shown.
Binary file added test_app/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file added test_app/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file added test_app/__pycache__/settings.cpython-310.pyc
Binary file not shown.
Binary file added test_app/__pycache__/settings.cpython-37.pyc
Binary file not shown.
Binary file added test_app/__pycache__/settings.cpython-38.pyc
Binary file not shown.
Binary file added test_app/__pycache__/settings.cpython-39.pyc
Binary file not shown.
Binary file added test_app/migrations/.0001_initial.py.swp
Binary file not shown.
48 changes: 48 additions & 0 deletions test_app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Generated by Django 4.1 on 2022-09-02 20:04

import datetime
from django.db import migrations, models
import timedelta.fields


class Migration(migrations.Migration):

initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="MinMaxTestModel",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"min",
timedelta.fields.TimedeltaField(
min_value=datetime.timedelta(days=1)
),
),
(
"max",
timedelta.fields.TimedeltaField(
max_value=datetime.timedelta(days=1)
),
),
(
"minmax",
timedelta.fields.TimedeltaField(
max_value=datetime.timedelta(days=7),
min_value=datetime.timedelta(days=1),
),
),
],
),
]
Empty file added test_app/migrations/__init__.py
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions test_app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

from django.db import models
from timedelta.fields import TimedeltaField
import datetime


class MinMaxTestModel(models.Model):
min = TimedeltaField(min_value=datetime.timedelta(1))
max = TimedeltaField(max_value=datetime.timedelta(1))
minmax = TimedeltaField(min_value=datetime.timedelta(1), max_value=datetime.timedelta(7))
108 changes: 108 additions & 0 deletions test_app/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
"""
Django settings for test_project project.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
from typing import List


BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "f8fkupu8pa%%u$wgk6c!os39el41v7i7^u*8xf#g5p@+c&)b#^"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": True,
"OPTIONS": {
"debug": True,
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.template.context_processors.request",
"django.contrib.messages.context_processors.messages",
],
},
},
]

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",
"timedelta",
"test_app",
)

MIDDLEWARE = (
"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",
)
MIDDLEWARE_CLASSES = MIDDLEWARE

# ROOT_URLCONF = "test_project.urls"

# WSGI_APPLICATION = "test_project.wsgi.application"

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"


# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}

# Internationalization
# https://docs.djangoproject.com/en/1.7/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/1.7/howto/static-files/

STATIC_URL = "/static/"
2 changes: 1 addition & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def main(db_engine='sqlite3'):
You can play with a django model without a complete django app installation.
http://www.djangosnippets.org/snippets/1044/
"""
os.environ["DJANGO_SETTINGS_MODULE"] = "django.conf.global_settings"
os.environ["DJANGO_SETTINGS_MODULE"] = "test_app.settings"
from django.conf import global_settings

global_settings.INSTALLED_APPS = (
Expand Down
12 changes: 4 additions & 8 deletions timedelta/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@
import doctest

from django.core.exceptions import ValidationError
from django.db import models
from django.utils import six

from .fields import TimedeltaField
import timedelta.helpers
import timedelta.forms
import timedelta.widgets

class MinMaxTestModel(models.Model):
min = TimedeltaField(min_value=datetime.timedelta(1))
max = TimedeltaField(max_value=datetime.timedelta(1))
minmax = TimedeltaField(min_value=datetime.timedelta(1), max_value=datetime.timedelta(7))
from test_app.models import MinMaxTestModel

class TimedeltaModelFieldTest(TestCase):
def test_validate(self):
Expand Down Expand Up @@ -55,6 +48,9 @@ def test_load_from_db(self):
self.assertEquals(datetime.timedelta(0, 120), obj.max)
self.assertEquals(datetime.timedelta(3), obj.minmax)

def tearDown(self):
MinMaxTestModel.objects.all().delete()

def load_tests(loader, tests, ignore):
tests.addTests(doctest.DocTestSuite(timedelta.helpers))
tests.addTests(doctest.DocTestSuite(timedelta.forms))
Expand Down

0 comments on commit aee8dee

Please sign in to comment.