Ejemplo n.º 1
0
    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'])
Ejemplo n.º 2
0
    def test_get_queryset(self):
        company = ProductionCompanyFactory()
        company_production = ProductionFactory(production_company=company)
        company_news = ArtsNewsFactory(related_company=company)
        production_news = ArtsNewsFactory(
            related_production=company_production
        )
        company_and_production_news = ArtsNewsFactory(
            related_company=company,
            related_production=company_production,
        )
        other_news = ArtsNewsFactory()

        view = CompanyNewsListView()
        view.company = company
        with patch.object(
            NewsListView,
            'get_queryset',
            return_value=ArtsNews.objects.all()
        ):
            queryset = view.get_queryset()
        self.assertIn(company_news, queryset)
        self.assertIn(production_news, queryset)
        self.assertIn(company_and_production_news, queryset)
        self.assertNotIn(other_news, queryset)
        self.assertEqual(len(queryset), 3)
Ejemplo n.º 3
0
    def test_get_related_news(self):
        production = ProductionFactory(production_company=self.company)
        production_news = ArtsNewsFactory(related_production=production)
        company_news = ArtsNewsFactory(related_company=self.company)

        related_news = self.company.get_related_news()
        self.assertIn(production_news, related_news)
        self.assertIn(company_news, related_news)
Ejemplo n.º 4
0
    def test_filter_media(self):
        video_news = ArtsNewsFactory(video_embed='<iframe />')
        slideshow_news = NewsSlideshowImageFactory().news
        basic_news = ArtsNewsFactory()

        media_news = ArtsNews.objects.filter_media()
        self.assertIn(video_news, media_news)
        self.assertIn(slideshow_news, media_news)
        self.assertNotIn(basic_news, media_news)
Ejemplo n.º 5
0
    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'])
Ejemplo n.º 6
0
    def test_get_context_data(self):
        news = ArtsNewsFactory()
        request = HttpRequest()
        view = NewsListView(request=request)
        view.object_list = [news]

        request.GET = {'page': 2}
        with patch.object(Paginator, 'page', return_value='page') as mock_page:
            with patch.object(view, 'get_queryset', return_value=[news]):
                context = view.get_context_data()
        self.assertEqual(context['page'], 'page')
        mock_page.assert_called_once_with(2)

        with patch.object(
            Paginator,
            'page',
            side_effect=PageNotAnInteger()
        ) as mock_page:
            with patch.object(view, 'get_queryset', return_value=[news]):
                try:
                    context = view.get_context_data()
                except PageNotAnInteger:
                    pass
        mock_page.has_call(1)

        with patch.object(Paginator, 'page', side_effect=EmptyPage()) as mock:
            with patch.object(view, 'get_queryset', return_value=[news]):
                try:
                    context = view.get_context_data()
                except EmptyPage:
                    pass
        mock.has_call(1)
Ejemplo n.º 7
0
    def test_get_context_data(self):
        production = ProductionFactory()
        other_production = ProductionFactory()
        news = ArtsNewsFactory()

        view = ProductionDetailView()
        view.object = production
        with patch.object(
            ProductionDetailView,
            'get_object',
            return_value=production
        ):
            context = view.get_context_data()
        self.assertIn(other_production, context['current_productions'])
        self.assertNotIn(production, context['current_productions'])
        self.assertEqual(context['company_productions'], [])
        self.assertIn(news, context['recent_news'])

        company = ProductionCompanyFactory()
        company_production = ProductionFactory(production_company=company)
        production.production_company = company
        with patch.object(
            ProductionDetailView,
            'get_object',
            return_value=production
        ):
            context = view.get_context_data()
        self.assertIn(company_production, context['company_productions'])
Ejemplo n.º 8
0
 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))
Ejemplo n.º 9
0
    def test_has_media(self):
        news = ArtsNewsFactory()
        self.assertFalse(news.has_media())

        NewsSlideshowImageFactory(news=news)
        self.assertTrue(news.has_media())

        news = ArtsNewsFactory(video_embed='<iframe src="" />')
        self.assertTrue(news.has_media())
Ejemplo n.º 10
0
    def test_get_queryset(self):
        external_news = ArtsNewsFactory(external_url='http://www.google.com/')
        video_news = ArtsNewsFactory(video_embed='<iframe />')
        slideshow_news = ArtsNewsFactory()
        NewsSlideshowImageFactory(news=slideshow_news)
        job_news = ArtsNewsFactory(is_job_opportunity=True)

        request = HttpRequest()
        view = NewsListView(request=request)
        news = view.get_queryset()
        self.assertIn(external_news, news)
        self.assertIn(video_news, news)
        self.assertIn(slideshow_news, news)
        self.assertIn(job_news, news)

        request.GET = {'category': 'external'}
        news = view.get_queryset()
        self.assertIn(external_news, news)
        self.assertNotIn(video_news, news)
        self.assertNotIn(slideshow_news, news)
        self.assertNotIn(job_news, news)

        request.GET = {'category': 'videos'}
        news = view.get_queryset()
        self.assertNotIn(external_news, news)
        self.assertIn(video_news, news)
        self.assertNotIn(slideshow_news, news)
        self.assertNotIn(job_news, news)

        request.GET = {'category': 'slideshows'}
        news = view.get_queryset()
        self.assertNotIn(external_news, news)
        self.assertNotIn(video_news, news)
        self.assertIn(slideshow_news, news)
        self.assertNotIn(job_news, news)

        request.GET = {'category': 'opportunities'}
        news = view.get_queryset()
        self.assertNotIn(external_news, news)
        self.assertNotIn(video_news, news)
        self.assertNotIn(slideshow_news, news)
        self.assertIn(job_news, news)
Ejemplo n.º 11
0
 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), [])
Ejemplo n.º 12
0
    def test_unicode(self):
        news = ArtsNewsFactory(title='Short Title')
        self.assertEqual(
            news.__unicode__(),
            u'{}: {}'.format(news.created_on.strftime('%m/%d/%y'), news.title))

        news = ArtsNewsFactory(title='This is a very long news title')
        self.assertEqual(
            news.__unicode__(),
            u'{}: {}...'.format(news.created_on.strftime('%m/%d/%y'),
                                news.title[:20]))
Ejemplo n.º 13
0
    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]
        )
Ejemplo n.º 14
0
    def test_get_context_data(self):
        news = ArtsNewsFactory()
        audition = AuditionFactory()
        upcoming_audition = AuditionFactory(
            start_date=timezone.now() + timedelta(days=1)
        )

        view = AuditionDetailView()
        view.object = audition
        with patch.object(
            AuditionDetailView,
            'get_object',
            return_value=audition
        ):
            context = view.get_context_data()
        self.assertIn(upcoming_audition, context['upcoming_auditions'])
        self.assertIn(news, context['recent_news'])
        self.assertEqual(context['company_productions'], [])
Ejemplo n.º 15
0
    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'])
Ejemplo n.º 16
0
 def test_get_absolute_url(self):
     news = ArtsNewsFactory(external_url='http://www.google.com/')
     self.assertEqual(news.get_absolute_url(), news.external_url)
     news = ArtsNewsFactory(external_url=None)
     self.assertIsInstance(news.get_absolute_url(), unicode)
Ejemplo n.º 17
0
 def test_item_description(self):
     news = ArtsNewsFactory(content='This is the news content.')
     self.assertEqual(self.feed.item_description(news), news.content)
     prod = ProductionFactory(description='This is a production.')
     self.assertEqual(self.feed.item_description(prod), prod.description)
Ejemplo n.º 18
0
 def test_get_slug(self):
     news = ArtsNewsFactory(title='Arts News Title')
     self.assertEqual(
         news.get_slug(),
         u'{}-arts-news-title'.format(timezone.now().strftime('%Y%m%d')))
Ejemplo n.º 19
0
 def test_save(self):
     news = ArtsNewsFactory(pk=None, slug=None)
     with patch('django.db.models.Model.save') as mock_save:
         news.save()
     self.assertEqual(news.slug, news.get_slug())
     mock_save.assert_called_once_with()
Ejemplo n.º 20
0
 def test_item_title(self):
     news = ArtsNewsFactory()
     self.assertEqual(self.feed.item_title(news), news.title)