def test_staged_edits_new(self): with revision: queen = Artist(name='Queen') queen.save() a_kind_of_magic = Album(artist=queen, title='A Kind of Magic') a_kind_of_magic.save() dont_lose_your_head = Song(album=a_kind_of_magic, title="Don't Lose Your Head") dont_lose_your_head.save() princes_of_the_universe = Song(album=a_kind_of_magic, title='Princes of the Universe') princes_of_the_universe.save() original_lyrics = Lyrics(song=princes_of_the_universe, text="Dont lose your head") original_lyrics.stage() first_revision = revision.latest_transactions['default'] with revision: original_lyrics.song = dont_lose_your_head original_lyrics.stage() second_revision = revision.latest_transactions['default'] # Verify that the lyrics object does not exist from the published perspective. self.assertRaises(Lyrics.DoesNotExist, Lyrics.objects.get, pk=original_lyrics.pk) # Vefify that the the published Song object does not know that the new lyrics exist. self.assertEquals(list(Song.objects.get(pk=princes_of_the_universe.pk).lyrics.all()), []) # Verify that the first staged version of the Song object knows that the lyrics exist. self.assertEquals(list(Song.objects.version(first_revision).get(pk=princes_of_the_universe.pk).lyrics.all()), [original_lyrics]) # Verify that the first staged version of the Song object knows that the lyrics exist. self.assertEquals(list(Song.objects.version(first_revision).get(pk=dont_lose_your_head.pk).lyrics.all()), []) # Verify that the second staged version of the Song object knows that the lyrics do not exist because they were altered to point to the correct song. self.assertEquals(list(Song.objects.version(second_revision).get(pk=princes_of_the_universe.pk).lyrics.all()), []) # Verify that the second staged version of the Song object knows that the lyrics do not exist because they were altered to point to the correct song. self.assertEquals(list(Song.objects.version(second_revision).get(pk=dont_lose_your_head.pk).lyrics.all()), [original_lyrics]) with revision: original_lyrics.commit() third_revision = revision.latest_transactions['default'] self.assertEquals(Lyrics.objects.get(pk=original_lyrics.pk), original_lyrics)