def test_publish(self): review = ReviewFactory(is_published=False, published_on=None) with patch.object(review, 'save') as mock_save: review.publish() mock_save.assert_called_once_with() self.assertTrue(review.is_published) self.assertIsNotNone(review.published_on)
def test_get_context_data(self): production = ProductionFactory(poster=FileObject('poster')) no_poster_production = ProductionFactory() review = ReviewFactory( is_published=True, cover_image=FileObject('image') ) unpublished_review = ReviewFactory( is_published=False, cover_image=FileObject('x') ) no_image_review = ReviewFactory(is_published=True) context = self.view.get_context_data() self.assertIn(production, context['productions']) self.assertNotIn(no_poster_production, context['productions']) self.assertIn(review, context['reviews']) self.assertNotIn(unpublished_review, context['reviews']) self.assertNotIn(no_image_review, context['reviews']) self.assertIsNone(context['audition_groups']) self.assertIsNone(context['media_news']) self.assertIsNone(context['news_groups']) audition = AuditionFactory() media_news = ArtsNewsFactory(video_embed='<iframe />') news = ArtsNewsFactory() context = self.view.get_context_data() self.assertIn([audition], context['audition_groups']) self.assertEqual(context['media_news'], media_news) self.assertIn([news], context['news_groups'])
def test_get_queryset(self): company = ProductionCompanyFactory() production = ProductionFactory(production_company=company) published_review = ReviewFactory( is_published=True, production=production, ) unpublished_review = ReviewFactory( is_published=False, production=production, ) other_review = ReviewFactory(is_published=True) view = CompanyReviewListView() view.company = company with patch.object( view, 'order_queryset', return_value='foobar' ) as mock_order_queryset: queryset = view.get_queryset() self.assertEqual(queryset, 'foobar') self.assertEqual(mock_order_queryset.call_count, 1) mocked_queryset = mock_order_queryset.call_args[0][0] self.assertIn(published_review, mocked_queryset) self.assertNotIn(unpublished_review, mocked_queryset) self.assertNotIn(other_review, mocked_queryset)
def test_get_absolute_url(self): review = ReviewFactory() try: absolute_url = review.get_absolute_url() except Exception as e: self.fail('Review.get_absolute_url() unexpectedly raised error: ' '{}'.format(str(e))) self.assertIsInstance(absolute_url, unicode)
def test_published_reviews(self): production = ProductionFactory() published_review = ReviewFactory(production=production, is_published=True) unpublished_review = ReviewFactory(production=production, is_published=False) published_reviews = production.published_reviews() self.assertIn(published_review, published_reviews) self.assertNotIn(unpublished_review, published_reviews)
def setUp(self): self.active_reviewer = ReviewerFactory() self.inactive_reviewer = ReviewerFactory() six_months_ago = timezone.now() - timedelta(days=6 * 365 / 12) ReviewFactory(is_published=True, reviewer=self.active_reviewer, published_on=six_months_ago + timedelta(days=40)) ReviewFactory(is_published=True, reviewer=self.inactive_reviewer, published_on=six_months_ago - timedelta(days=40))
def test_published_reviews(self): production_1 = ProductionFactory(production_company=self.company) production_2 = ProductionFactory(production_company=self.company) published_review = ReviewFactory(production=production_1, is_published=True) unpublished_review = ReviewFactory(production=production_2, is_published=False) published_reviews = self.company.published_reviews() self.assertIn(published_review, published_reviews) self.assertNotIn(unpublished_review, published_reviews)
def test_get_slug(self): review = ReviewFactory(title='Test Review Title') self.assertEqual( review.get_slug(), u'unpublished-test-review-title', ) review.published_on = datetime(2017, 1, 3) self.assertEqual( review.get_slug(), u'20170103-test-review-title', )
def test_get_context_data(self): request = HttpRequest() request.GET = {'page': 2} view = ReviewListView(request=request) view.object_list = [ReviewFactory()] with patch.object(Paginator, 'page') as mock_page: view.get_context_data() mock_page.assert_called_once_with(2) with patch.object( Paginator, 'page', side_effect=PageNotAnInteger() ) as mock_page: try: view.get_context_data() except PageNotAnInteger: pass mock_page.has_call(1) with patch.object(Paginator, 'page', side_effect=EmptyPage()) as mock: try: view.get_context_data() except EmptyPage: pass mock.has_call(1)
def test_item_pubdate(self): news = ArtsNewsFactory(created_on=timezone.now() - timedelta(days=1)) self.assertEqual(self.feed.item_pubdate(news), news.created_on) review = ReviewFactory(published_on=timezone.now() - timedelta(days=2)) self.assertEqual(self.feed.item_pubdate(review), review.published_on) company = ProductionCompanyFactory() self.assertIsNotNone(self.feed.item_pubdate(company))
def test_unpublish_reviews(self): review = ReviewFactory(is_published=True) request = HttpRequest() with patch.object(self.review_admin, 'message_user') as mock_message: self.review_admin.unpublish_reviews(request, Review.objects.all()) review = Review.objects.get(pk=review.pk) self.assertFalse(review.is_published) mock_message.assert_called_once_with(request, '1 review unpublished.')
def test_get_context_data(self): reviewer_1 = ReviewerFactory() ReviewFactory(reviewer=reviewer_1, published_on=timezone.now()) ReviewFactory(reviewer=reviewer_1, published_on=timezone.now()) reviewer_2 = ReviewerFactory() ReviewFactory(reviewer=reviewer_2, published_on=timezone.now()) inactive_reviewer = ReviewerFactory() view = ReviewerListView() with patch( 'django.views.generic.list.ListView.get_context_data', return_value={} ): context = view.get_context_data() self.assertIn(reviewer_1, context['active_reviewers']) self.assertIn(reviewer_2, context['active_reviewers']) self.assertEqual(context['inactive_reviewers'][0], inactive_reviewer)
def test_item_categories(self): prod = ProductionFactory() self.assertEqual(self.feed.item_categories(prod), ['Productions']) review = ReviewFactory() self.assertEqual(self.feed.item_categories(review), ['Reviews']) audition = AuditionFactory() self.assertEqual(self.feed.item_categories(audition), ['Auditions']) news = ArtsNewsFactory() self.assertEqual(self.feed.item_categories(news), ['News']) reviewer = ReviewerFactory() self.assertEqual(self.feed.item_categories(reviewer), [])
def test_get_title(self): review = ReviewFactory(title='Some Title') self.assertEqual(review.get_title(), review.title) review = ReviewFactory() self.assertEqual(review.get_title(), 'Review: {}'.format(review.production))
def test_save(self): review = ReviewFactory(pk=None, title=None, slug=None) with patch('django.db.models.Model.save') as mock_save: review.save() self.assertEqual(review.title, review.get_title()) self.assertEqual(review.slug, review.get_slug()) mock_save.assert_called_once_with()
def test_get_context_data(self): company = ProductionCompanyFactory() production = ProductionFactory(production_company=company) other_production = ProductionFactory() review = ReviewFactory(is_published=True, production=production) unpublished_review = ReviewFactory(is_published=False) news = ArtsNewsFactory() view = ReviewDetailView() view.object = review with patch.object(view, 'get_object', return_value=review): context = view.get_context_data() self.assertIn(review, context['recent_reviews']) self.assertNotIn(unpublished_review, context['recent_reviews']) self.assertNotIn(production, context['company_productions']) self.assertNotIn(other_production, context['company_productions']) self.assertIn(news, context['recent_news']) company_production_2 = ProductionFactory(production_company=company) with patch.object(view, 'get_object', return_value=review): context = view.get_context_data() self.assertIn(company_production_2, context['company_productions'])
def test_get_context_data(self): news = ArtsNewsFactory() other_news = ArtsNewsFactory() review = ReviewFactory() production = ProductionFactory() view = NewsDetailView() view.object = news with patch.object(view, 'get_object', return_value=news): context = view.get_context_data() self.assertIn(review, context['recent_reviews']) self.assertIn(other_news, context['recent_news']) self.assertNotIn(news, context['recent_news']) self.assertIn(production, context['current_productions'])
def test_items(self): now = timezone.now() one_day_ago = now - timedelta(days=1) news = ArtsNewsFactory() audition = AuditionFactory() production = ProductionFactory() review = ReviewFactory( is_published=True, published_on=one_day_ago, production=production, ) self.assertEqual( self.feed.items(), [production, audition, news, review] )
def test_review_set(self): production = ProductionFactory(production_company=self.company) review = ReviewFactory(production=production) self.assertIn(review, self.company.review_set)
def test_index_queryset(self): published_review = ReviewFactory(is_published=True) unpublished_review = ReviewFactory(is_published=False) indexed = self.review_index.index_queryset() self.assertIn(published_review, indexed) self.assertNotIn(unpublished_review, indexed)
def test_unicode(self): review = ReviewFactory() self.assertEqual(review.__unicode__(), unicode(review.get_title()))
def test_unpublish(self): review = ReviewFactory(is_published=True, published_on=timezone.now()) with patch.object(review, 'save') as mock_save: review.unpublish() mock_save.assert_called_once_with() self.assertFalse(review.is_published)
def test_review_account(self): reviewer = ReviewerFactory() self.assertEqual(reviewer.review_count, 0) ReviewFactory(reviewer=reviewer) self.assertEqual(reviewer.review_count, 1)
def test_save_published_review(self): review = ReviewFactory(is_published=True, published_on=None) with patch('django.db.models.Model.save') as mock_save: review.save() self.assertIsNotNone(review.published_on) mock_save.assert_called_once_with()