Loading tests/generic_relations_regress/tests.py +15 −12 Original line number Diff line number Diff line Loading @@ -2,7 +2,8 @@ from django.db.models import Q from django.db.utils import IntegrityError from django.test import TestCase, skipIfDBFeature from .models import (Address, Place, Restaurant, Link, CharLink, TextLink, from .models import ( Address, Place, Restaurant, Link, CharLink, TextLink, Person, Contact, Note, Organization, OddRelation1, OddRelation2, Company, Developer, Team, Guild, Tag, Board, HasLinkThing) Loading @@ -28,7 +29,7 @@ class GenericRelationTests(TestCase): originating model of a query. See #12664. """ p = Person.objects.create(account=23, name='Chef') a = Address.objects.create(street='123 Anywhere Place', Address.objects.create(street='123 Anywhere Place', city='Conifer', state='CO', zipcode='80433', content_object=p) Loading @@ -38,12 +39,12 @@ class GenericRelationTests(TestCase): def test_charlink_delete(self): oddrel = OddRelation1.objects.create(name='clink') cl = CharLink.objects.create(content_object=oddrel) CharLink.objects.create(content_object=oddrel) oddrel.delete() def test_textlink_delete(self): oddrel = OddRelation2.objects.create(name='tlink') tl = TextLink.objects.create(content_object=oddrel) TextLink.objects.create(content_object=oddrel) oddrel.delete() def test_q_object_or(self): Loading @@ -61,7 +62,7 @@ class GenericRelationTests(TestCase): """ note_contact = Contact.objects.create() org_contact = Contact.objects.create() note = Note.objects.create(note='note', content_object=note_contact) Note.objects.create(note='note', content_object=note_contact) org = Organization.objects.create(name='org name') org.contacts.add(org_contact) # search with a non-matching note and a matching org name Loading Loading @@ -90,8 +91,8 @@ class GenericRelationTests(TestCase): p1 = Place.objects.create(name="South Park") p2 = Place.objects.create(name="The City") c = Company.objects.create(name="Chubby's Intl.") l1 = Link.objects.create(content_object=p1) l2 = Link.objects.create(content_object=c) Link.objects.create(content_object=p1) Link.objects.create(content_object=c) places = list(Place.objects.order_by('links__id')) def count_places(place): Loading @@ -114,8 +115,10 @@ class GenericRelationTests(TestCase): try: note = Note(note='Deserve a bonus', content_object=team1) except Exception as e: if issubclass(type(e), Exception) and str(e) == 'Impossible arguments to GFK.get_content_type!': self.fail("Saving model with GenericForeignKey to model instance whose __len__ method returns 0 shouldn't fail.") if (issubclass(type(e), Exception) and str(e) == 'Impossible arguments to GFK.get_content_type!'): self.fail("Saving model with GenericForeignKey to model instance whose " "__len__ method returns 0 shouldn't fail.") raise e note.save() Loading Loading
tests/generic_relations_regress/tests.py +15 −12 Original line number Diff line number Diff line Loading @@ -2,7 +2,8 @@ from django.db.models import Q from django.db.utils import IntegrityError from django.test import TestCase, skipIfDBFeature from .models import (Address, Place, Restaurant, Link, CharLink, TextLink, from .models import ( Address, Place, Restaurant, Link, CharLink, TextLink, Person, Contact, Note, Organization, OddRelation1, OddRelation2, Company, Developer, Team, Guild, Tag, Board, HasLinkThing) Loading @@ -28,7 +29,7 @@ class GenericRelationTests(TestCase): originating model of a query. See #12664. """ p = Person.objects.create(account=23, name='Chef') a = Address.objects.create(street='123 Anywhere Place', Address.objects.create(street='123 Anywhere Place', city='Conifer', state='CO', zipcode='80433', content_object=p) Loading @@ -38,12 +39,12 @@ class GenericRelationTests(TestCase): def test_charlink_delete(self): oddrel = OddRelation1.objects.create(name='clink') cl = CharLink.objects.create(content_object=oddrel) CharLink.objects.create(content_object=oddrel) oddrel.delete() def test_textlink_delete(self): oddrel = OddRelation2.objects.create(name='tlink') tl = TextLink.objects.create(content_object=oddrel) TextLink.objects.create(content_object=oddrel) oddrel.delete() def test_q_object_or(self): Loading @@ -61,7 +62,7 @@ class GenericRelationTests(TestCase): """ note_contact = Contact.objects.create() org_contact = Contact.objects.create() note = Note.objects.create(note='note', content_object=note_contact) Note.objects.create(note='note', content_object=note_contact) org = Organization.objects.create(name='org name') org.contacts.add(org_contact) # search with a non-matching note and a matching org name Loading Loading @@ -90,8 +91,8 @@ class GenericRelationTests(TestCase): p1 = Place.objects.create(name="South Park") p2 = Place.objects.create(name="The City") c = Company.objects.create(name="Chubby's Intl.") l1 = Link.objects.create(content_object=p1) l2 = Link.objects.create(content_object=c) Link.objects.create(content_object=p1) Link.objects.create(content_object=c) places = list(Place.objects.order_by('links__id')) def count_places(place): Loading @@ -114,8 +115,10 @@ class GenericRelationTests(TestCase): try: note = Note(note='Deserve a bonus', content_object=team1) except Exception as e: if issubclass(type(e), Exception) and str(e) == 'Impossible arguments to GFK.get_content_type!': self.fail("Saving model with GenericForeignKey to model instance whose __len__ method returns 0 shouldn't fail.") if (issubclass(type(e), Exception) and str(e) == 'Impossible arguments to GFK.get_content_type!'): self.fail("Saving model with GenericForeignKey to model instance whose " "__len__ method returns 0 shouldn't fail.") raise e note.save() Loading