Cleanup tests by removing spurious errors and unnecessary noise
- Remove diamond inheritance tests since these test a bug in Django, not in django_polymorphic. - Fix spurious print message in test_primary_key_custom_field_problem(), where uuid instances are for some reason being compared to uuid.UUID classes. Replaced with a test that checks that the primary key values are valid UUIDs. - Remove Django > 1.6 conditionals wrapping the multiple inheritance tests and model definitions, in favor of using the definitions for Django 1.7. Django 1.7 requires a custom primary key when using concrete model inheritance because failing to do so is potentially ambiguous. Adding the custom primary key does not break tests in older Django versions.fix_request_path_info
parent
bf0d37a91c
commit
fd24863db5
|
|
@ -67,45 +67,13 @@ class ModelX(Base):
|
|||
class ModelY(Base):
|
||||
field_y = models.CharField(max_length=10)
|
||||
|
||||
if django.VERSION[:2] > (1, 6):
|
||||
class Enhance_Plain(models.Model):
|
||||
field_p = models.CharField(max_length=10)
|
||||
class Enhance_Base(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
base_id = models.AutoField(primary_key=True)
|
||||
field_b = models.CharField(max_length=10)
|
||||
class Enhance_Inherit(Enhance_Base, Enhance_Plain):
|
||||
field_i = models.CharField(max_length=10)
|
||||
|
||||
class DiamondBase(models.Model):
|
||||
field_b = models.CharField(max_length=10)
|
||||
class DiamondX(DiamondBase):
|
||||
x_id = models.AutoField(primary_key=True)
|
||||
field_x = models.CharField(max_length=10)
|
||||
class DiamondY(DiamondBase):
|
||||
y_id = models.AutoField(primary_key=True)
|
||||
field_y = models.CharField(max_length=10)
|
||||
class DiamondXY(DiamondBase):
|
||||
xy_id = models.AutoField(primary_key=True)
|
||||
field_x = models.CharField(max_length=10)
|
||||
field_y = models.CharField(max_length=10)
|
||||
else:
|
||||
class Enhance_Plain(models.Model):
|
||||
field_p = models.CharField(max_length=10)
|
||||
class Enhance_Base(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
field_b = models.CharField(max_length=10)
|
||||
class Enhance_Inherit(Enhance_Base, Enhance_Plain):
|
||||
field_i = models.CharField(max_length=10)
|
||||
|
||||
class DiamondBase(models.Model):
|
||||
field_b = models.CharField(max_length=10)
|
||||
class DiamondX(DiamondBase):
|
||||
x_id = models.AutoField(primary_key=True)
|
||||
field_x = models.CharField(max_length=10)
|
||||
class DiamondY(DiamondBase):
|
||||
y_id = models.AutoField(primary_key=True)
|
||||
field_y = models.CharField(max_length=10)
|
||||
class DiamondXY(DiamondX, DiamondY):
|
||||
xy_id = models.AutoField(primary_key=True)
|
||||
class Enhance_Plain(models.Model):
|
||||
field_p = models.CharField(max_length=10)
|
||||
class Enhance_Base(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
base_id = models.AutoField(primary_key=True)
|
||||
field_b = models.CharField(max_length=10)
|
||||
class Enhance_Inherit(Enhance_Base, Enhance_Plain):
|
||||
field_i = models.CharField(max_length=10)
|
||||
|
||||
class RelationBase(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
field_base = models.CharField(max_length=10)
|
||||
|
|
@ -288,22 +256,6 @@ class PolymorphicTests(TestCase):
|
|||
"""
|
||||
The test suite
|
||||
"""
|
||||
def test_diamond_inheritance(self):
|
||||
if django.VERSION[:2] > (1, 6):
|
||||
print('')
|
||||
print("# Django 1.7 doesn't allow multiple inheritance when two id fields exist. https://docs.djangoproject.com/en/dev/topics/db/models/#multiple-inheritance")
|
||||
|
||||
# Django diamond problem
|
||||
# https://code.djangoproject.com/ticket/10808
|
||||
o1 = DiamondXY.objects.create(field_b='b', field_x='x', field_y='y')
|
||||
o2 = DiamondXY.objects.get()
|
||||
|
||||
if o2.field_b != 'b':
|
||||
print('')
|
||||
print('# known django model inheritance diamond problem detected')
|
||||
print('DiamondXY fields 1: field_b "{0}", field_x "{1}", field_y "{2}"'.format(o1.field_b, o1.field_x, o1.field_y))
|
||||
print('DiamondXY fields 2: field_b "{0}", field_x "{1}", field_y "{2}"'.format(o2.field_b, o2.field_x, o2.field_y))
|
||||
|
||||
|
||||
def test_annotate_aggregate_order(self):
|
||||
# create a blog of type BlogA
|
||||
|
|
@ -408,18 +360,14 @@ class PolymorphicTests(TestCase):
|
|||
<UUIDArtProject: uuid_primary_key (UUIDField/pk), topic (CharField) "Sculpting with Tim", artist (CharField) "T. Turner">,
|
||||
<UUIDResearchProject: uuid_primary_key (UUIDField/pk), topic (CharField) "Swallow Aerodynamics", supervisor (CharField) "Dr. Winter"> ]"""
|
||||
self.assertEqual(res, res_exp)
|
||||
#if (a.pk!= uuid.UUID or c.pk!= uuid.UUID):
|
||||
# print()
|
||||
# print('# known inconstency with custom primary key field detected (django problem?)')
|
||||
|
||||
a = UUIDPlainA.objects.create(field1='A1')
|
||||
b = UUIDPlainB.objects.create(field1='B1', field2='B2')
|
||||
c = UUIDPlainC.objects.create(field1='C1', field2='C2', field3='C3')
|
||||
qs = UUIDPlainA.objects.all()
|
||||
if a.pk!= uuid.UUID or c.pk!= uuid.UUID:
|
||||
print('')
|
||||
print('# known type inconstency with custom primary key field detected (django problem?)')
|
||||
|
||||
# Test that primary key values are valid UUIDs
|
||||
self.assertEqual(uuid.UUID("urn:uuid:%s" % a.pk, version=1), a.pk)
|
||||
self.assertEqual(uuid.UUID("urn:uuid:%s" % c.pk, version=1), c.pk)
|
||||
|
||||
def create_model2abcd(self):
|
||||
"""
|
||||
|
|
@ -655,13 +603,9 @@ class PolymorphicTests(TestCase):
|
|||
Enhance_Inherit.objects.create(field_b='b-inherit', field_p='p', field_i='i')
|
||||
|
||||
qs = Enhance_Base.objects.all()
|
||||
if django.VERSION[:2] > (1, 6):
|
||||
self.assertEqual(repr(qs[0]), '<Enhance_Base: base_id (AutoField/pk) 1, field_b (CharField) "b-base">')
|
||||
self.assertEqual(repr(qs[1]), '<Enhance_Inherit: base_id (AutoField/pk) 2, field_b (CharField) "b-inherit", id 1, field_p (CharField) "p", field_i (CharField) "i">')
|
||||
else:
|
||||
self.assertEqual(repr(qs[0]), '<Enhance_Base: id 1, field_b (CharField) "b-base">')
|
||||
self.assertEqual(repr(qs[1]), '<Enhance_Inherit: id 2, field_b (CharField) "b-inherit", field_p (CharField) "p", field_i (CharField) "i">')
|
||||
self.assertEqual(len(qs), 2)
|
||||
self.assertEqual(repr(qs[0]), '<Enhance_Base: base_id (AutoField/pk) 1, field_b (CharField) "b-base">')
|
||||
self.assertEqual(repr(qs[1]), '<Enhance_Inherit: base_id (AutoField/pk) 2, field_b (CharField) "b-inherit", id 1, field_p (CharField) "p", field_i (CharField) "i">')
|
||||
|
||||
def test_relation_base(self):
|
||||
# ForeignKey, ManyToManyField
|
||||
|
|
|
|||
Loading…
Reference in New Issue