Exemple #1
0
    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)
Exemple #2
0
    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)