def test_entity_index(self): author = testing.create_user() jack_white = Entity.create_for_testing() 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']))
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()
def test_song_mentions(self): article = Article.create_for_testing(self.user) self.assertEqual(self.get_song_mentions_count(), 0) # Mentions should not be added until the article is public. song_a = Song.create_for_testing(self.user) link_a = '[song_a](https://example.com/opracowanie/%s)' % song_a.slug article.main_text_trevor = put_text_in_trevor(link_a) article.full_clean() article.save() self.assertEqual(self.get_song_mentions_count(), 0) article.reviewed = True article.full_clean() article.save() self.assertEqual(self.get_song_mentions_count(), 1) article.main_text_trevor = put_text_in_trevor(link_a + ' ' + link_a) article.full_clean() article.save() self.assertEqual(self.get_song_mentions_count(), 1) song_b = Song.create_for_testing(self.user) link_b = '[song_a](https://example.com/opracowanie/%s)' % song_b.slug article.main_text_trevor = put_text_in_trevor(link_a + ' ' + link_b) article.save() self.assertEqual(self.get_song_mentions_count(), 2) song_c = Song.create_for_testing(self.user) # This time with a trailing slash. link_c = '[song_a](https://example.com/opracowanie/%s/)' % song_c.slug article.main_text_trevor = put_text_in_trevor(link_a + ' ' + link_c) article.save() self.assertEqual(self.get_song_mentions_count(), 2) article.main_text_trevor = put_text_in_trevor('nothing') article.save() self.assertEqual(self.get_song_mentions_count(), 0)
def setUp(self): author = testing.create_user() song = Song.create_for_testing(author) entity = Entity.create_for_testing() contribution = EntityContribution() contribution.song = song contribution.entity = entity contribution.texted = True contribution.save() song.old_slug = "some-old-slug" song.reviewed = True song.save() self.song = song self.entity = entity
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)
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)