Fixes Django 1.7 compatibility.

This commit is contained in:
Bertrand Bordage 2015-10-03 04:30:23 +02:00
parent 6b2fdb6da1
commit e1ac02bec7
4 changed files with 24 additions and 11 deletions

View file

@ -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

View file

@ -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)),
],
),
]
)
)

View file

@ -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)

View file

@ -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(