Drop support for Django <1.8, Python <2.7
This commit is contained in:
@@ -1,22 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import django
|
||||
import uuid
|
||||
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db import models
|
||||
from django.db.models.query import QuerySet
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
from polymorphic.managers import PolymorphicManager
|
||||
from polymorphic.models import PolymorphicModel
|
||||
from polymorphic.query import PolymorphicQuerySet
|
||||
from polymorphic.showfields import ShowFieldContent, ShowFieldType, ShowFieldTypeAndContent
|
||||
|
||||
try:
|
||||
from django.db.models import UUIDField
|
||||
except ImportError:
|
||||
# django<1.8
|
||||
from polymorphic.tools_for_tests import UUIDField
|
||||
|
||||
|
||||
class PlainA(models.Model):
|
||||
field1 = models.CharField(max_length=10)
|
||||
@@ -167,9 +161,6 @@ class MyManager(PolymorphicManager):
|
||||
def my_queryset_foo(self):
|
||||
return self.all().my_queryset_foo()
|
||||
|
||||
# Django <= 1.5 compatibility
|
||||
get_query_set = get_queryset
|
||||
|
||||
|
||||
class ModelWithMyManager(ShowFieldTypeAndContent, Model2A):
|
||||
objects = MyManager()
|
||||
@@ -188,10 +179,9 @@ class ModelWithMyManagerDefault(ShowFieldTypeAndContent, Model2A):
|
||||
field4 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
if django.VERSION >= (1, 7):
|
||||
class ModelWithMyManager2(ShowFieldTypeAndContent, Model2A):
|
||||
objects = MyManagerQuerySet.as_manager()
|
||||
field4 = models.CharField(max_length=10)
|
||||
class ModelWithMyManager2(ShowFieldTypeAndContent, Model2A):
|
||||
objects = MyManagerQuerySet.as_manager()
|
||||
field4 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class MROBase1(ShowFieldType, PolymorphicModel):
|
||||
@@ -236,9 +226,6 @@ class PlainMyManager(models.Manager):
|
||||
def get_queryset(self):
|
||||
return PlainMyManagerQuerySet(self.model, using=self._db)
|
||||
|
||||
# Django <= 1.5 compatibility
|
||||
get_query_set = get_queryset
|
||||
|
||||
|
||||
class PlainParentModelWithManager(models.Model):
|
||||
pass
|
||||
@@ -319,7 +306,7 @@ class Bottom(Middle):
|
||||
|
||||
|
||||
class UUIDProject(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
uuid_primary_key = UUIDField(primary_key=True, default=uuid.uuid1)
|
||||
uuid_primary_key = models.UUIDField(primary_key=True, default=uuid.uuid1)
|
||||
topic = models.CharField(max_length=30)
|
||||
|
||||
|
||||
@@ -332,7 +319,7 @@ class UUIDResearchProject(UUIDProject):
|
||||
|
||||
|
||||
class UUIDPlainA(models.Model):
|
||||
uuid_primary_key = UUIDField(primary_key=True, default=uuid.uuid1)
|
||||
uuid_primary_key = models.UUIDField(primary_key=True, default=uuid.uuid1)
|
||||
field1 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
|
||||
@@ -1,25 +1,15 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import django
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
from django.test import TestCase
|
||||
from django.db.models import Q
|
||||
from django.test import TestCase
|
||||
|
||||
from polymorphic.tests import * # all models
|
||||
|
||||
try:
|
||||
from unittest import skipIf
|
||||
except ImportError:
|
||||
# python<2.7
|
||||
from django.utils.unittest import skipIf
|
||||
|
||||
|
||||
|
||||
class MultipleDatabasesTests(TestCase):
|
||||
multi_db = True
|
||||
|
||||
@skipIf(django.VERSION < (1, 5,), "This test needs Django >=1.5")
|
||||
def test_save_to_non_default_database(self):
|
||||
Model2A.objects.db_manager('secondary').create(field1='A1')
|
||||
Model2C(field1='C1', field2='C2', field3='C3').save(using='secondary')
|
||||
|
||||
@@ -1,22 +1,11 @@
|
||||
from __future__ import print_function
|
||||
import re
|
||||
|
||||
import django
|
||||
from django.db.models import Case, Count, Q, When
|
||||
from django.test import TestCase
|
||||
from django.db.models import Q, Count
|
||||
from django.utils import six
|
||||
from polymorphic.tests import * # all models
|
||||
|
||||
from polymorphic.contrib.guardian import get_polymorphic_base_content_type
|
||||
|
||||
try:
|
||||
from unittest import skipIf
|
||||
except ImportError:
|
||||
# python<2.7
|
||||
from django.utils.unittest import skipIf
|
||||
|
||||
if django.VERSION >= (1, 8):
|
||||
from django.db.models import Case, When
|
||||
from polymorphic.tests import * # all models
|
||||
|
||||
|
||||
class PolymorphicTests(TestCase):
|
||||
@@ -188,11 +177,6 @@ class PolymorphicTests(TestCase):
|
||||
'<Model2D: id 4, field1 (CharField), field2 (CharField), field3 (CharField), field4 (CharField), '
|
||||
'deferred[field2,field3,field4,model2a_ptr_id,model2b_ptr_id]>')
|
||||
|
||||
# A bug in Django 1.4 prevents using defer across reverse relations
|
||||
# <https://code.djangoproject.com/ticket/14694>. Since polymorphic
|
||||
# uses reverse relations to traverse down model inheritance, deferring
|
||||
# fields in child models will not work in Django 1.4.
|
||||
@skipIf(django.VERSION < (1, 5), "Django 1.4 does not support defer on related fields")
|
||||
def test_defer_related_fields(self):
|
||||
self.create_model2abcd()
|
||||
|
||||
@@ -424,7 +408,6 @@ class PolymorphicTests(TestCase):
|
||||
self.assertEqual(repr(objects[0]), '<Model2B: id 2, field1 (CharField), field2 (CharField)>')
|
||||
self.assertEqual(repr(objects[1]), '<Model2C: id 3, field1 (CharField), field2 (CharField), field3 (CharField)>')
|
||||
|
||||
@skipIf(django.VERSION < (1, 6), "Django 1.4 and 1.5 don't support q.clone()")
|
||||
def test_query_filter_exclude_is_immutable(self):
|
||||
# given
|
||||
q_to_reuse = Q(Model2B___field2='something')
|
||||
@@ -564,7 +547,6 @@ class PolymorphicTests(TestCase):
|
||||
self.assertIs(type(ModelWithMyManagerDefault._default_manager), MyManager)
|
||||
self.assertIs(type(ModelWithMyManagerDefault.base_objects), models.Manager)
|
||||
|
||||
@skipIf(django.VERSION < (1, 7), "This test needs Django 1.7+")
|
||||
def test_user_defined_queryset_as_manager(self):
|
||||
self.create_model2abcd()
|
||||
ModelWithMyManager2.objects.create(field1='D1a', field4='D4a')
|
||||
@@ -751,7 +733,6 @@ class PolymorphicTests(TestCase):
|
||||
lambda: Model2A.objects.aggregate(Count('Model2B___field2'))
|
||||
)
|
||||
|
||||
@skipIf(django.VERSION < (1, 8,), "This test needs Django >=1.8")
|
||||
def test_polymorphic__complex_aggregate(self):
|
||||
""" test (complex expression on) aggregate (should work for annotate either) """
|
||||
|
||||
@@ -777,7 +758,6 @@ class PolymorphicTests(TestCase):
|
||||
with self.assertRaisesMessage(AssertionError, 'PolymorphicModel: annotate()/aggregate(): ___ model lookup supported for keyword arguments only'):
|
||||
Model2A.objects.aggregate(ComplexAgg('Model2B___field2'))
|
||||
|
||||
@skipIf(django.VERSION < (1, 8,), "This test needs Django >=1.8")
|
||||
def test_polymorphic__expressions(self):
|
||||
|
||||
from django.db.models.functions import Concat
|
||||
|
||||
Reference in New Issue
Block a user