Ticket #16173: patch16173.diff

File patch16173.diff, 1.9 KB (added by fhahn, 12 years ago)

updated patch to r17591

  • tests/modeltests/many_to_one/tests.py

     
    66from django.core.exceptions import MultipleObjectsReturned
    77from django.test import TestCase
    88
    9 from .models import Article, Reporter
     9from .models import (Article, Reporter, RelatedModel, SomeModel,
     10        SuccessfulExecutedException)
    1011
    1112
    1213class ManyToOneTests(TestCase):
     
    412413
    413414        # Same as each other
    414415        self.assertTrue(r1.article_set.__class__ is r2.article_set.__class__)
     416
     417    def test_reverse_single_related_manager(self):
     418        # This unit test prooves if the dummy managers get methode will be
     419        # executed. Related to the ticket #16173.
     420        related_obj = RelatedModel.default_manager.create(name='bar')
     421        obj = SomeModel.objects.create(related=related_obj)
     422
     423        # reload obj to make sure the
     424        obj = SomeModel.objects.all()[0]
     425
     426        # the get method of the dummy manager must be used
     427        with self.assertRaises(SuccessfulExecutedException):
     428            obj.related
  • tests/modeltests/many_to_one/models.py

     
    2525
    2626    class Meta:
    2727        ordering = ('headline',)
     28
     29class SuccessfulExecutedException(Exception):
     30    pass
     31
     32
     33class DummyManager(models.Manager):
     34    use_for_related_fields = True
     35    def get(self, **kwargs):
     36        raise SuccessfulExecutedException
     37
     38
     39class RelatedModel(models.Model):
     40    name = models.CharField(max_length=32)
     41
     42    default_manager = DummyManager()
     43
     44
     45class SomeModel(models.Model):
     46    related = models.ForeignKey(RelatedModel)
Back to Top