Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django 2.1+ compatibility (tests for 2.2.6) #66

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*.un~
/build
/dist
venv
47 changes: 31 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
language: python

addons:
postgresql: "9.3"
services:
- postgresql
- mysql

matrix:
include:
- python: 2.7
env: DJANGO_VERSION=1.11.12 DB=postgres
env: DJANGO_VERSION=1.11.25 DB=postgres
- python: 2.7
env: DJANGO_VERSION=1.11.12 DB=sqlite
env: DJANGO_VERSION=1.11.25 DB=sqlite
- python: 2.7
env: DJANGO_VERSION=1.11.12 DB=mysql
env: DJANGO_VERSION=1.11.25 DB=mysql

- python: 2.7
env: DJANGO_VERSION=1.7.11 DB=postgres
Expand All @@ -27,11 +28,18 @@ matrix:
env: DJANGO_VERSION=1.6.11 DB=mysql

- python: 3.5
env: DJANGO_VERSION=2.0.4 DB=postgres
env: DJANGO_VERSION=2.0.13 DB=postgres
- python: 3.5
env: DJANGO_VERSION=2.0.13 DB=mysql
- python: 3.5
env: DJANGO_VERSION=2.0.13 DB=sqlite

- python: 3.5
env: DJANGO_VERSION=2.2.6 DB=postgres
- python: 3.5
env: DJANGO_VERSION=2.0.4 DB=mysql
env: DJANGO_VERSION=2.2.6 DB=mysql
- python: 3.5
env: DJANGO_VERSION=2.0.4 DB=sqlite
env: DJANGO_VERSION=2.2.6 DB=sqlite

- python: 3.5
env: DJANGO_VERSION=1.11.12 DB=postgres
Expand All @@ -41,28 +49,35 @@ matrix:
env: DJANGO_VERSION=1.11.12 DB=mysql

- python: 3.6
env: DJANGO_VERSION=2.0.4 DB=postgres
env: DJANGO_VERSION=2.0.13 DB=postgres
- python: 3.6
env: DJANGO_VERSION=2.0.4 DB=mysql
env: DJANGO_VERSION=2.0.13 DB=mysql
- python: 3.6
env: DJANGO_VERSION=2.0.4 DB=sqlite
env: DJANGO_VERSION=2.0.13 DB=sqlite

- python: 3.6
env: DJANGO_VERSION=1.11.12 DB=postgres
env: DJANGO_VERSION=2.2.6 DB=postgres
- python: 3.6
env: DJANGO_VERSION=1.11.12 DB=sqlite
env: DJANGO_VERSION=2.2.6 DB=mysql
- python: 3.6
env: DJANGO_VERSION=1.11.12 DB=mysql
env: DJANGO_VERSION=2.2.6 DB=sqlite

- python: 3.6
env: DJANGO_VERSION=1.11.25 DB=postgres
- python: 3.6
env: DJANGO_VERSION=1.11.25 DB=sqlite
- python: 3.6
env: DJANGO_VERSION=1.11.25 DB=mysql

# command to install dependencies
install:
- "pip install -q Django==$DJANGO_VERSION"
- "if [[ $DB == mysql ]]; then pip install -q mysqlclient; fi"
- "if [[ $DB == postgres ]]; then pip install -q psycopg2; fi"
- "if [[ $DB == postgres ]]; then pip install -q psycopg2-binary; fi"

before_script:
- psql -c 'create database django_positions;' -U postgres
- mysql -e 'create database django_positions;'

# command to run tests
script: python manage.py test --settings examples.ci_settings_$DB examples
script: python manage.py test --settings examples.ci_settings examples
5 changes: 1 addition & 4 deletions examples/settings.py → examples/base_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(funcName)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
Expand All @@ -116,7 +113,7 @@
'class': 'logging.handlers.RotatingFileHandler',
'filename': 'debug.log',
'maxBytes': 1024*1024*5,
'formatter': 'verbose'
'formatter': 'simple'
},
},
'loggers': {
Expand Down
152 changes: 152 additions & 0 deletions examples/base_settings_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
"""
Django settings for local 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
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 = 'wg2_iar76ne7o@uf7op87=4tqtnwch_civ79b1j%)=#i0q1*8p'

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

TEMPLATE_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',
'examples.todo',
'examples.lists',
'examples.nodes',
'examples.photos',
'examples.restaurants',
'examples.school',
'examples.store',
'examples.migration'
)

MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'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/1.7/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydb',
}
}

# 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/'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
},
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue'
}
},
'handlers': {
'console':{
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'debug_log_file':{
'level': 'DEBUG',
'filters': ['require_debug_true'],
'class': 'logging.handlers.RotatingFileHandler',
'filename': 'debug.log',
'maxBytes': 1024*1024*5,
'formatter': 'simple'
},
},
'loggers': {
'django.request': {
'handlers': ['debug_log_file'],
'level': 'INFO',
'propagate': True,
},
'django.db.backends': {
'handlers': ['debug_log_file'],
'level': 'DEBUG',
'propagate': False,
},
'': {
'handlers': ['debug_log_file', 'console'],
'level': 'DEBUG',
'propagate': True,
},
},
}
30 changes: 30 additions & 0 deletions examples/ci_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os

db = os.environ['DB']
v = tuple(map(int, os.environ['DJANGO_VERSION'].strip().split('.')))


_DB_ENGINES = {
'mysql': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_positions',
'USER': 'root',
'PASSWORD': '',
},
'postgres': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django_positions',
'USER': 'postgres',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}

if v > (2, 0, 0):
from .base_settings_2 import *
else:
from .base_settings import *

if db in DATABASES:
DATABASES['default'] = _DB_ENGINES[db]
3 changes: 0 additions & 3 deletions examples/ci_settings_mysql.py

This file was deleted.

3 changes: 0 additions & 3 deletions examples/ci_settings_postgres.py

This file was deleted.

1 change: 0 additions & 1 deletion examples/ci_settings_sqlite.py

This file was deleted.

13 changes: 13 additions & 0 deletions examples/nodes/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.contrib import admin
from .models import Node

class NodeAdmin(admin.ModelAdmin):
'''
Test for SystemCheckError when using the position field in the Admin.
'''
list_display = ('position', 'name')
list_display_links = ('name',)
list_filter = ('parent',)
search_fields = ('name',)

admin.site.register(Node, NodeAdmin)
12 changes: 0 additions & 12 deletions examples/settings_mysql.py

This file was deleted.

12 changes: 0 additions & 12 deletions examples/settings_postgres.py

This file was deleted.

1 change: 0 additions & 1 deletion examples/settings_sqlite.py

This file was deleted.

4 changes: 2 additions & 2 deletions positions/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ def pre_save(self, model_instance, add):

def __get__(self, instance, owner):
if instance is None:
raise AttributeError("%s must be accessed via instance." % self.name)
return self
current, updated = getattr(instance, self.get_cache_name())
return current if updated is None else updated

def __set__(self, instance, value):
if instance is None:
raise AttributeError("%s must be accessed via instance." % self.name)
return self
if value is None:
value = self.default
cache_name = self.get_cache_name()
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Django==1.7.4
psycopg2==2.6
Django==2.2.2
psycopg2-binary==2.7.7