Exemplo n.º 1
0
    def test_song_view_with_authenticated_user_looking_own_songs(self):
        """
        An authenticated user should be able to see both published and
        unpublished songs sent by him.
        """
        user = create_user()
        song_pub = create_song(title='Song_Published',published=True,sender=user)
        song_unpub = create_song(title='Song_Unpublished', published=False,
                                 sender=user)

        request = RequestFactory().get(reverse('chords:song',
                                       args=(song_pub.slug,)))
        request.user = user
        response = song_view(request, song_pub.slug)
        self.assertContains(response, song_pub.title, status_code=200)

        request = RequestFactory().get(reverse('chords:song',
                                       args=(song_unpub.slug,)))
        request.user = user
        response = song_view(request, song_unpub.slug)
        self.assertContains(response, song_unpub.title, status_code=200)
Exemplo n.º 2
0
    def test_song_view_with_authenticated_user_looking_other_songs(self):
        """
        An authenticated user should be able to see only published songs from
        other users.
        """
        user_viewer = create_user(username='******')
        user_artist = create_user(username='******')
        song_pub = create_song(title='Song Published', published=True,
                               sender=user_artist)
        song_unpub = create_song(title='Song Unpublished', published=False,
                                 sender=user_artist)

        request = RequestFactory().get(reverse('chords:song',
                                       args=(song_pub.slug,)))
        request.user = user_viewer
        response = song_view(request, song_pub.slug)
        self.assertContains(response, song_pub.title, status_code=200)

        request = RequestFactory().get(reverse('chords:song',
                                       args=(song_unpub.slug,)))
        request.user = user_viewer
        with self.assertRaises(Http404):
            song_view(request, song_unpub.slug)