Ticket #15146: tests.2.diff

File tests.2.diff, 1.6 KB (added by elbarto, 13 years ago)

New tests added.

  • tests/modeltests/reverse_lookup/tests.py

     
    11from django.test import TestCase
    22from django.core.exceptions import FieldError
    33
    4 from models import User, Poll, Choice
     4from models import User, Poll, Choice, Person
    55
    66class ReverseLookupTests(TestCase):
    77
     
    4141            related_choice__name__exact="This is the answer.")
    4242        self.assertEqual(p2.question, "What's the second question?")
    4343
     44    def test_reverse_by_related_name_without_saving(self):
     45        p1 = Person()
     46        p1.save()
     47        p2 = Person()
     48        self.assertEqual(unicode(p2.children.all()), unicode([]))
     49       
     50        p2.save()
     51        self.assertEqual(unicode(p2.children.all()), unicode([]))
     52
    4453    def test_reverse_field_name_disallowed(self):
    4554        """
    4655        If a related_name is given you can't use the field name instead
    4756        """
    4857        self.assertRaises(FieldError, Poll.objects.get,
    4958            choice__name__exact="This is the answer")
     59
  • tests/modeltests/reverse_lookup/models.py

     
    2626
    2727    def __unicode__(self):
    2828        return self.name
     29
     30class Person(models.Model):
     31    parent = models.ForeignKey('self', blank=True, null=True, related_name='children')
     32
Back to Top