Ticket #16173: patch16173.diff
File patch16173.diff, 1.9 KB (added by , 13 years ago) |
---|
-
tests/modeltests/many_to_one/tests.py
6 6 from django.core.exceptions import MultipleObjectsReturned 7 7 from django.test import TestCase 8 8 9 from .models import Article, Reporter 9 from .models import (Article, Reporter, RelatedModel, SomeModel, 10 SuccessfulExecutedException) 10 11 11 12 12 13 class ManyToOneTests(TestCase): … … 412 413 413 414 # Same as each other 414 415 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
25 25 26 26 class Meta: 27 27 ordering = ('headline',) 28 29 class SuccessfulExecutedException(Exception): 30 pass 31 32 33 class DummyManager(models.Manager): 34 use_for_related_fields = True 35 def get(self, **kwargs): 36 raise SuccessfulExecutedException 37 38 39 class RelatedModel(models.Model): 40 name = models.CharField(max_length=32) 41 42 default_manager = DummyManager() 43 44 45 class SomeModel(models.Model): 46 related = models.ForeignKey(RelatedModel)