def test_staged_edits(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() princes_of_the_universe = Song(album=a_kind_of_magic, title='Princes of the Universe') princes_of_the_universe.save() dont_lose_your_head = Song(album=a_kind_of_magic, title="Don't Lose Your Head") dont_lose_your_head.save() original_lyrics = Lyrics(song=dont_lose_your_head, text="Dont lose your head") original_lyrics.save() first_revision = revision.latest_transactions['default'] with revision: queen.stage() a_kind_of_magic.stage() princes_of_the_universe.stage() dont_lose_your_head.stage() new_lyrics = """Dont lose your head Dont lose your head Dont lose your head No dont lose you head """ staged_edits_lyrics = Lyrics.objects.version('tip').get(pk=original_lyrics.pk) staged_edits_lyrics.text = new_lyrics staged_edits_lyrics.stage() princes_of_the_universe.delete() second_revision = revision.latest_transactions['default'] # Ensure the database version still points to the old lyrics. self.assertEquals(Lyrics.objects.get(pk=original_lyrics.pk).text, "Dont lose your head") self.assertEquals(list(Album.objects.get(pk=a_kind_of_magic.pk).songs.all()), [princes_of_the_universe, dont_lose_your_head]) # Ensure that the versions contain the correct information. self.assertEquals(Lyrics.objects.version(first_revision).get(pk=original_lyrics.pk).text, "Dont lose your head") self.assertEquals(Lyrics.objects.version(second_revision).get(pk=original_lyrics.pk).text, new_lyrics) with revision: queen.commit() a_kind_of_magic.commit() Album.objects.version('tip').get(pk=a_kind_of_magic.pk).songs.commit() new_lyrics = """Dont lose your head Dont lose your head Dont lose your head Dont lose your head No dont lose you head Dont lose you head Hear what I say Dont lose your way - yeah Remember loves stronger remember love walks tall """ published_lyrics = Lyrics.objects.version('tip').get(pk=original_lyrics.pk) published_lyrics.text = new_lyrics published_lyrics.commit() third_revision = revision.latest_transactions['default'] # Ensure the database version points to the new lyrics. self.assertEquals(Lyrics.objects.get(pk=original_lyrics.pk).text, new_lyrics) # Ensure the database version only has on song. Princess of the universe has been deleted. self.assertEquals(list(Album.objects.get(pk=a_kind_of_magic.pk).songs.all()), [dont_lose_your_head]) # Ensure that the versions contain the correct information. self.assertEquals(Lyrics.objects.version(third_revision).get(pk=original_lyrics.pk).text, new_lyrics)