Example #1
0
    def test_entity_index(self):
        author = testing.create_user()
        jack_white = Artist.create_for_testing(author)
        jack_white.featured = True
        jack_white.save()

        seven_nations_army = Song.create_for_testing(author)
        self.add_contribution(seven_nations_army, jack_white, True)
        jolene = Song.create_for_testing(author)
        self.add_contribution(jolene, jack_white, True)

        # Approve only Jolene.
        seven_nations_army.reviewed = False
        seven_nations_army.save()
        jolene.reviewed = True
        jolene.save()

        # General public should see only Jolene.
        response = testing.get_public_client().get(
            jack_white.get_absolute_url())
        self.assertEqual(200, response.status_code)
        self.assertEqual(1, len(response.context['songs']))

        # The author should see both.
        response = testing.get_user_client(author).get(
            jack_white.get_absolute_url())
        self.assertEqual(200, response.status_code)
        self.assertEqual(2, len(response.context['songs']))

        # Any logged-in user should see both, too.
        response = testing.get_user_client().get(jack_white.get_absolute_url())
        self.assertEqual(200, response.status_code)
        self.assertEqual(2, len(response.context['songs']))
Example #2
0
 def get_add_url(self):
     author = testing.create_user()
     artist = Artist.create_for_testing(author)
     artist.reviewed = True
     artist.save()
     song = Song.create_for_testing(author)
     song.reviewed = True
     song.full_clean()
     song.save()
     return song.get_add_note_url()
Example #3
0
    def test_add_song_note(self):
        user = testing.create_user()
        artist = Artist.create_for_testing(user)
        artist.reviewed = True
        artist.full_clean()
        artist.save()

        song = Song.create_for_testing(user)
        song.reviewed = True
        song.full_clean()
        song.save()

        data = {
            'title': 'dalsze losy kotka',
            'text_trevor': put_text_in_trevor('Abc')
        }
        self.assertEqual(len(SongNote.objects.all()), 0)
        response = testing.get_user_client(user=user).post(
            song.get_add_note_url(), data=data)
        self.assertEqual(302, response.status_code)
        self.assertRedirects(response, song.get_absolute_url())
        self.assertEqual(len(SongNote.objects.all()), 1)
Example #4
0
    def test_add_song(self):
        user = testing.create_user()
        artist = Artist.create_for_testing(user)
        artist.reviewed = True
        artist.save()

        data = {
            'title': 'wlazlkotek',
            'capo_fret': 0,
            'lyrics': 'wlazl kotek na plotek',
            'entitycontribution_set-TOTAL_FORMS': 1,
            'entitycontribution_set-INITIAL_FORMS': 0,
            'entitycontribution_set-MIN_NUM_FORMS': 1,
            'entitycontribution_set-MAX_NUM_FORMS': 1000,
            'entitycontribution_set-0-artist': artist.pk,
            'entitycontribution_set-0-texted': True,
        }
        response = testing.get_user_client(user=user).post(
            reverse('add_song'), data=data)
        self.assertRedirects(response,
                             '/opracowanie/' + artist.name + '-wlazlkotek/')
        song = Song.objects.get(title='wlazlkotek')
        self.assertEqual('wlazl kotek na plotek', song.lyrics)
Example #5
0
    def test_cannot_add_song_note_if_song_not_reviewed(self):
        user = testing.create_user()
        artist = Artist.create_for_testing(user)
        artist.reviewed = True
        artist.full_clean()
        artist.save()

        song = Song.create_for_testing(user)
        song.reviewed = True
        song.full_clean()
        song.save()

        url = song.get_add_note_url()
        song.reviewed = False
        song.full_clean()
        song.save()

        data = {
            'title': 'dalsze losy kotka',
            'text_trevor': put_text_in_trevor('Abc')
        }
        response = testing.get_user_client(user=user).post(url, data=data)
        self.assertEqual(404, response.status_code)
        self.assertEqual(len(SongNote.objects.all()), 0)