Ticket #14226: test.diff
File test.diff, 3.5 KB (added by , 14 years ago) |
---|
-
tests/regressiontests/fixtures_regress/models.py
diff --git a/tests/regressiontests/fixtures_regress/models.py b/tests/regressiontests/fixtures_regress/models.py index 28a4c8b..bcfb607 100644
a b class ExternalDependency(models.Model): 231 231 def natural_key(self): 232 232 return self.name 233 233 natural_key.dependencies = ['fixtures_regress.book'] 234 235 236 class Tagger(models.Model): 237 name = models.CharField(max_length=20) 238 topics = models.ManyToManyField("Tag", through="TaggerTag") 239 240 def natural_key(self): 241 return self.name 242 243 244 class Posting(models.Model): 245 tagger = models.ForeignKey(Tagger) 246 text = models.TextField() 247 time = models.DateTimeField() 248 249 def natural_key(self): 250 return (self.tagger.name, self.time) 251 natural_key.dependencies = ['fixtures_regress.tagger'] 252 253 254 class Tag(models.Model): 255 name = models.CharField(max_length=20) 256 postings = models.ManyToManyField(Posting, through="PostingTag") 257 258 def natural_key(self): 259 return self.name 260 261 262 class PostingTag(models.Model): 263 tag = models.ForeignKey(Tag) 264 posting = models.ForeignKey(Posting) 265 266 def natural_key(self): 267 return (self.tag.natural_key(), self.posting.natural_key()) 268 269 270 class TaggerTag(models.Model): 271 tagger = models.ForeignKey(Tagger) 272 tag = models.ForeignKey(Tag) 273 274 def natural_key(self): 275 return (self.tag.natural_key(), self.tagger.natural_key()) -
tests/regressiontests/fixtures_regress/tests.py
diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py index 9c10e20..a395f7a 100644
a b from models import NKChild, RefToNKChild 21 21 from models import Circle1, Circle2, Circle3 22 22 from models import ExternalDependency 23 23 from models import animal_pre_save_check 24 from models import Tagger, Posting, Tag, TaggerTag, PostingTag 24 25 25 26 26 27 class TestFixtures(TestCase): … … class TestFixtures(TestCase): 361 362 sorted_deps = sort_dependencies( 362 363 [('fixtures_regress', [Person, Circle1, Store, Book])] 363 364 ) 364 self.assertEqual( 365 sorted_deps, 366 [Circle1, Store, Person, Book] 367 ) 365 # The specific placement of Circle1 is irrelevant. 366 assert sorted_deps.index(Store) < sorted_deps.index(Person) 367 assert sorted_deps.index(Person) < sorted_deps.index(Book) 368 368 369 369 def test_dependency_sorting_tight_circular(self): 370 370 self.assertRaisesMessage( … … class TestFixtures(TestCase): 390 390 [('fixtures_regress', [Book, Circle3])], 391 391 ) 392 392 393 def test_dependency_sorting_m2m(self): 394 """ 395 Test for ticket #14226 -- ManyToMany relationships can be 396 defined on any side of the relationship. 397 """ 398 sorted_deps = sort_dependencies( 399 [('fixtures_regress', [Posting, Tagger, TaggerTag, Tag, PostingTag])], 400 ) 401 assert sorted_deps.index(Tag) < sorted_deps.index(Tagger) 402 assert sorted_deps.index(Tagger) < sorted_deps.index(Posting) 403 assert sorted_deps.index(Posting) < sorted_deps.index(PostingTag) 404 assert sorted_deps.index(Tag) < sorted_deps.index(PostingTag) 405 assert sorted_deps.index(Tagger) < sorted_deps.index(TaggerTag) 406 assert sorted_deps.index(Tag) < sorted_deps.index(TaggerTag) 407 393 408 def test_dependency_sorting_long(self): 394 409 self.assertRaisesMessage( 395 410 CommandError,