From e1ac02bec77a08e08b3585fec2718669f07d649d Mon Sep 17 00:00:00 2001 From: Bertrand Bordage Date: Sat, 3 Oct 2015 04:30:23 +0200 Subject: [PATCH] Fixes Django 1.7 compatibility. --- cachalot/tests/__init__.py | 5 ++++- cachalot/tests/migrations/0001_initial.py | 12 +++++++++--- cachalot/tests/models.py | 13 ++++++++----- cachalot/tests/postgres.py | 5 +++-- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/cachalot/tests/__init__.py b/cachalot/tests/__init__.py index a408eef..6b4308a 100644 --- a/cachalot/tests/__init__.py +++ b/cachalot/tests/__init__.py @@ -1,3 +1,5 @@ +from django import VERSION as django_version + from .read import ReadTestCase from .write import WriteTestCase, DatabaseCommandTestCase from .transaction import AtomicTestCase @@ -6,4 +8,5 @@ from .multi_db import MultiDatabaseTestCase from .settings import SettingsTestCase from .api import APITestCase, CommandTestCase from .signals import SignalsTestCase -from .postgres import PostgresReadTest +if django_version >= (1, 8): + from .postgres import PostgresReadTest diff --git a/cachalot/tests/migrations/0001_initial.py b/cachalot/tests/migrations/0001_initial.py index b5a3490..0087931 100644 --- a/cachalot/tests/migrations/0001_initial.py +++ b/cachalot/tests/migrations/0001_initial.py @@ -2,8 +2,8 @@ from __future__ import unicode_literals +from django import VERSION as django_version from django.conf import settings -from django.contrib.postgres.fields import ArrayField, IntegerRangeField from django.db import models, migrations @@ -47,6 +47,12 @@ class Migration(migrations.Migration): ], bases=('cachalot.testparent',), ), + ] + +if django_version >= (1, 8): + from django.contrib.postgres.fields import ArrayField, IntegerRangeField + + Migration.operations.append( migrations.CreateModel( name='PostgresModel', fields=[ @@ -57,5 +63,5 @@ class Migration(migrations.Migration): null=True, blank=True)), ('int_range', IntegerRangeField(null=True, blank=True)), ], - ), - ] + ) + ) diff --git a/cachalot/tests/models.py b/cachalot/tests/models.py index e1b31d2..dcb6eea 100644 --- a/cachalot/tests/models.py +++ b/cachalot/tests/models.py @@ -2,8 +2,8 @@ from __future__ import unicode_literals +from django import VERSION as django_version from django.conf import settings -from django.contrib.postgres.fields import ArrayField, IntegerRangeField from django.db.models import ( Model, CharField, ForeignKey, BooleanField, DateField, DateTimeField, ManyToManyField, BinaryField, IntegerField) @@ -31,7 +31,10 @@ class TestChild(TestParent): permissions = ManyToManyField('auth.Permission', blank=True) -class PostgresModel(Model): - int_array = ArrayField(IntegerField(null=True, blank=True), size=3, - null=True, blank=True) - int_range = IntegerRangeField(null=True, blank=True) +if django_version >= (1, 8): + from django.contrib.postgres.fields import ArrayField, IntegerRangeField + + class PostgresModel(Model): + int_array = ArrayField(IntegerField(null=True, blank=True), size=3, + null=True, blank=True) + int_range = IntegerRangeField(null=True, blank=True) diff --git a/cachalot/tests/postgres.py b/cachalot/tests/postgres.py index 3c291ce..e704bba 100644 --- a/cachalot/tests/postgres.py +++ b/cachalot/tests/postgres.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals from unittest import skipUnless +from django import VERSION as django_version from django.db import connection from django.test import TransactionTestCase from psycopg2._range import NumericRange @@ -10,8 +11,8 @@ from psycopg2._range import NumericRange from .models import PostgresModel -@skipUnless(connection.vendor == 'postgresql', - 'This test is for PostgreSQL only') +@skipUnless(connection.vendor == 'postgresql' and django_version[:2] >= (1, 8), + 'This test is only for PostgreSQL and Django >= 1.8') class PostgresReadTest(TransactionTestCase): def setUp(self): self.obj = PostgresModel.objects.create(