Skip to content

Commit

Permalink
Added tests for multi-table inheritance #31
Browse files Browse the repository at this point in the history
  • Loading branch information
Suor committed Feb 3, 2013
1 parent 8630a33 commit 11c47a1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ class Video(models.Model):
class VideoProxy(Video):
class Meta:
proxy = True


# Multi-table inheritance
class Media(models.Model):
name = models.CharField(max_length=128)

class Movie(Media):
year = models.IntegerField()
20 changes: 20 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,23 @@ def test_interchange(self):

with self.assertNumQueries(0):
list(VideoProxy.objects.cache())


class MultitableInheritanceTests(BaseTestCase):
def test_sub_added(self):
media_count = Media.objects.cache().count()
Movie.objects.create(name="Matrix", year=1999)

with self.assertNumQueries(1):
self.assertEqual(Media.objects.cache().count(), media_count + 1)

def test_base_changed(self):
matrix = Movie.objects.create(name="Matrix", year=1999)
list(Movie.objects.cache())

media = Media.objects.get(pk=matrix.pk)
media.name = "Matrix (original)"
media.save()

with self.assertNumQueries(1):
list(Movie.objects.cache())

0 comments on commit 11c47a1

Please sign in to comment.