From 25821cd4dab06d3d771f77fdb8fd266edb24db90 Mon Sep 17 00:00:00 2001 From: Ben Konrath Date: Sun, 17 Mar 2013 16:23:00 +0100 Subject: [PATCH 1/5] Add tox configuration file. Note: The tests do not currently pass. --- tox.ini | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tox.ini diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..681be81 --- /dev/null +++ b/tox.ini @@ -0,0 +1,33 @@ +[tox] +envlist= + py26-django15, + py27-django15, + py26-django14, + py27-django14, + +[testenv] +commands= + python manage.py test + +# Build configurations + +[testenv:py26-django15] +basepython=python2.6 +deps= + django==1.5 + +[testenv:py27-django15] +basepython=python2.7 +deps= + django==1.5 + +[testenv:py26-django14] +basepython=python2.6 +deps= + django==1.4.5 + +[testenv:py27-django14] +basepython=python2.7 +deps= + django==1.4.5 + From 102817e54ca079cd638569955c69a95d02cdc1e8 Mon Sep 17 00:00:00 2001 From: Ben Konrath Date: Sun, 17 Mar 2013 16:23:00 +0100 Subject: [PATCH 2/5] Update DB settings for Django >= 1.4. --- settings.py | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/settings.py b/settings.py index 4439e8f..f95cfe7 100644 --- a/settings.py +++ b/settings.py @@ -9,28 +9,12 @@ ADMINS = ( MANAGERS = ADMINS -import django -import os - -if os.path.ismount('/ram'): - SQLITE_DB_PATH = '/ram/django-polymorphic-test-db.sqlite3' -else: - SQLITE_DB_PATH = '/var/tmp/django-polymorphic-test-db.sqlite3' - -if django.VERSION[:2][0]>=1 and django.VERSION[:2][1]>=3: - DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': SQLITE_DB_PATH - } +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:' } -else: - DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. - DATABASE_NAME = SQLITE_DB_PATH # Or path to database file if using sqlite3. - DATABASE_USER = '' # Not used with sqlite3. - DATABASE_PASSWORD = '' # Not used with sqlite3. - DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. - DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. +} # Local time zone for this installation. Choices can be found here: # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name From 1ef9e068dfe3d898bb3b6a6fa0e0fcd2cb5ba96c Mon Sep 17 00:00:00 2001 From: Ben Konrath Date: Sun, 17 Mar 2013 16:23:00 +0100 Subject: [PATCH 3/5] Import settings in tests from django.conf. --- polymorphic/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polymorphic/tests.py b/polymorphic/tests.py index 7005799..5ecef1b 100644 --- a/polymorphic/tests.py +++ b/polymorphic/tests.py @@ -3,7 +3,7 @@ Please see README.rst or DOCS.rst or http://bserve.webhop.org/wiki/django_polymorphic """ -import settings +from django.conf import settings import sys from pprint import pprint From b718acf00589131fca0ee5cfa91df412b351bc48 Mon Sep 17 00:00:00 2001 From: Ben Konrath Date: Sun, 17 Mar 2013 16:23:01 +0100 Subject: [PATCH 4/5] Update db_type method for Django >= 1.4 DB settings format. --- polymorphic/tools_for_tests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/polymorphic/tools_for_tests.py b/polymorphic/tools_for_tests.py index 1646a4a..9c75bb8 100644 --- a/polymorphic/tools_for_tests.py +++ b/polymorphic/tools_for_tests.py @@ -84,7 +84,9 @@ class UUIDField(models.CharField): def db_type(self, connection): from django.conf import settings - return UUIDField._CREATE_COLUMN_TYPES.get(settings.DATABASE_ENGINE, "char(%s)" % self.max_length) + full_database_type = settings.DATABASES['default']['ENGINE'] + database_type = full_database_type.split('.')[-1] + return UUIDField._CREATE_COLUMN_TYPES.get(database_type, "char(%s)" % self.max_length) def to_python(self, value): """Return a uuid.UUID instance from the value returned by the database.""" From 318dd3d67a4a50b53861b2e15e619935445d0d73 Mon Sep 17 00:00:00 2001 From: Ben Konrath Date: Sun, 17 Mar 2013 16:23:01 +0100 Subject: [PATCH 5/5] Fixed the default manager test failures. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to the django docs (1.4 / 1.5), the default manager for subclasses of PolymorphicModel should be PolymorphicManager: 3. The default manager on a class is either the first manager declared on the class, if that exists, or the default manager of the first abstract base class in the parent hierarchy, if that exists. If no default manager is explicitly declared, Django’s normal default manager is used. https://docs.djangoproject.com/en/1.4/topics/db/managers/#custom-managers-and-model-inheritance https://docs.djangoproject.com/en/1.5/topics/db/managers/#custom-managers-and-model-inheritance --- polymorphic/tests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/polymorphic/tests.py b/polymorphic/tests.py index 5ecef1b..b485722 100644 --- a/polymorphic/tests.py +++ b/polymorphic/tests.py @@ -582,7 +582,7 @@ __test__ = {"doctest": """ >>> type(ModelWithMyManager.objects) >>> type(ModelWithMyManager._default_manager) - + ### Manager Inheritance @@ -592,11 +592,11 @@ __test__ = {"doctest": """ # check for correct default manager >>> type(MROBase1._default_manager) - + # Django vanilla inheritance does not inherit MyManager as _default_manager here >>> type(MROBase2._default_manager) - + ### fixed issue in PolymorphicModel.__getattribute__: field name same as model name