def test_new_to_review_mails(self): author = testing.create_user() reviewer_a = testing.create_user(perms=['content.review']) testing.create_user(perms=['content.review']) # There are two reviewers, both should receive an email about the new # article added by Alice. article = Article.create_for_testing(author) send_new_to_review_mails(article) self.assertEqual(len(mail.outbox), 2) # Only one email should be sent when an approver adds a new article - # only the other one can review it. article = Article.create_for_testing(reviewer_a) send_new_to_review_mails(article) self.assertEqual(len(mail.outbox), 3) # https://github.com/ppiet/piosenka/issues/8 # Set the first reviewers's email to empty - they should now be skipped, # but the other reviewer should be notified. reviewer_a.email = '' reviewer_a.save() article = Article.create_for_testing(author) send_new_to_review_mails(article) self.assertEqual(len(mail.outbox), 4)
def test_item_approved_mail(self): author = testing.create_user() reviewer = testing.create_user(perms=['content.review']) self.assertEqual(len(mail.outbox), 0) article = Article.create_for_testing(author) send_item_approved_mail(article, reviewer) self.assertEqual(len(mail.outbox), 1)
def test_article_index(self): response = testing.get_public_client().get(reverse('articles')) self.assertEqual(200, response.status_code) author = testing.create_user() article_a = Article.create_for_testing(author) article_a.reviewed = True article_a.save() article_b = Article.create_for_testing(author) article_b.reviewed = False article_b.save() response = testing.get_public_client().get(reverse('articles')) self.assertEqual(200, response.status_code) self.assertEqual(1, len(response.context['articles'])) response = testing.get_user_client(author).get(reverse('articles')) self.assertEqual(200, response.status_code) self.assertEqual(2, len(response.context['articles'])) response = testing.get_user_client().get(reverse('articles')) self.assertEqual(200, response.status_code) self.assertEqual(2, len(response.context['articles']))
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)