예제 #1
0
 def test_detailed_duration(self):
     production = ProductionFactory()
     with patch.object(production, 'duration',
                       return_value='mock_duration') as mock_duration:
         duration = production.detailed_duration()
     mock_duration.assert_called_once_with(date_format='%B %d, %Y')
     self.assertEqual(duration, 'mock_duration')
예제 #2
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'])
예제 #3
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'])
예제 #4
0
    def test_filter_active(self):
        eight_months_ago = timezone.now() - timedelta(days=8 * 365 / 12)
        two_years_ago = timezone.now() - timedelta(days=365 * 2)

        # create company with a recent production
        active_production_company = ProductionCompanyFactory()
        ProductionFactory(production_company=active_production_company,
                          start_date=eight_months_ago)

        # create company with a recent audition
        active_audition_company = ProductionCompanyFactory()
        AuditionFactory(production_company=active_audition_company,
                        start_date=eight_months_ago)

        # create company with an old production
        inactive_production_company = ProductionCompanyFactory()
        ProductionFactory(production_company=inactive_production_company,
                          start_date=two_years_ago)

        # create_company with an old audition
        inactive_audition_company = ProductionCompanyFactory()
        AuditionFactory(production_company=inactive_audition_company,
                        start_date=two_years_ago)

        # create completely inactive company
        inactive_company = ProductionCompanyFactory()

        active_companies = ProductionCompany.objects.filter_active()
        self.assertIn(active_production_company, active_companies)
        self.assertIn(active_audition_company, active_companies)
        self.assertNotIn(inactive_production_company, active_companies)
        self.assertNotIn(inactive_audition_company, active_companies)
        self.assertNotIn(inactive_company, active_companies)
예제 #5
0
    def test_title(self):
        production = ProductionFactory()
        self.assertEqual(production.title, unicode(production.play))

        company = ProductionCompanyFactory()
        production = ProductionFactory(production_company=company)
        self.assertEqual(
            production.title,
            u'{} by {}'.format(production.play, production.production_company))
예제 #6
0
 def test_get_slug(self):
     company = ProductionCompanyFactory(name='Company Name')
     production = ProductionFactory(
         start_date=datetime(2017, 1, 3),
         play__title='Test Play Title',
         production_company=company,
     )
     self.assertEqual(production.get_slug(),
                      u'20170103-test-play-title-by-company-name')
예제 #7
0
 def test_get_queryset(self):
     self.view.model = Production
     self.view.company = self.company
     company_production = ProductionFactory(production_company=self.company)
     ProductionFactory()
     with patch.object(self.view, 'order_queryset') as mock_order_queryset:
         self.view.get_queryset()
     self.assertEqual(mock_order_queryset.call_count, 1)
     called_queryset = mock_order_queryset.call_args[0][0]
     self.assertEqual(called_queryset[0], company_production)
예제 #8
0
    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)
예제 #9
0
    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)
예제 #10
0
    def test_get_queryset(self):
        austin_venue = VenueFactory(address=AddressFactory(city='Austin'))
        bastrop_venue = VenueFactory(address=AddressFactory(city='Bastrop'))
        ProductionFactory(venue=austin_venue)
        ProductionFactory(venue=bastrop_venue)

        view = VenueListView()
        queryset = view.get_queryset()
        self.assertEqual(queryset[0][0], u'Austin')
        self.assertEqual(queryset[0][1][0], austin_venue)
        self.assertEqual(queryset[1][0], u'Bastrop')
        self.assertEqual(queryset[1][1][0], bastrop_venue)
예제 #11
0
    def test_get_performances(self):
        start = timezone.now() - timedelta(days=5)
        end = timezone.now() - timedelta(days=2)
        production_1 = ProductionFactory(
            start_date=start + timedelta(days=1)
        )
        production_2 = ProductionFactory(
            start_date=start + timedelta(days=2)
        )

        with patch.object(self.view, '_get_range', return_value=(start, end)):
            performances = self.view.get_performances()
        self.assertEqual(performances[0], production_1)
        self.assertEqual(performances[1], production_2)
예제 #12
0
    def test_filter_active(self):
        active_venue = VenueFactory()
        inactive_venue = VenueFactory()
        empty_venue = VenueFactory()

        now = timezone.now()
        two_years_ago = now - timedelta(days=364 * 2)
        ProductionFactory(start_date=two_years_ago, venue=inactive_venue)
        ProductionFactory(start_date=now, venue=active_venue)

        active_venues = Venue.objects.filter_active()
        self.assertIn(active_venue, active_venues)
        self.assertNotIn(inactive_venue, active_venues)
        self.assertNotIn(empty_venue, active_venues)
예제 #13
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)
예제 #14
0
    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)
예제 #15
0
    def test_filter_current(self):
        today = timezone.now()
        yesterday = today - timedelta(days=1)
        tomorrow = today + timedelta(days=1)

        past = ProductionFactory(start_date=yesterday)
        future = ProductionFactory(start_date=yesterday)
        current_short = ProductionFactory(start_date=today)
        current_long = ProductionFactory(start_date=yesterday,
                                         end_date=tomorrow)

        current_productions = Production.objects.filter_current()
        self.assertNotIn(past, current_productions)
        self.assertNotIn(future, current_productions)
        self.assertIn(current_short, current_productions)
        self.assertIn(current_long, current_productions)
예제 #16
0
 def test_get_context_data(self):
     self.view.company = ProductionFactory()
     with patch(
         'django.views.generic.list.ListView.get_context_data',
         return_value={}
     ):
         context = self.view.get_context_data()
     self.assertEqual(context['company'], self.view.company)
예제 #17
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)
예제 #18
0
    def test_get_queryset(self):
        venue_production_1 = ProductionFactory(
            venue=self.venue,
            start_date=timezone.now() - timedelta(days=1)
        )
        venue_production_2 = ProductionFactory(
            venue=self.venue,
            start_date=timezone.now() - timedelta(days=2)
        )
        other_production = ProductionFactory()

        view = VenueProductionListView()
        view.venue = self.venue
        queryset = view.get_queryset()
        self.assertNotIn(other_production, queryset)
        self.assertEqual(queryset[0], venue_production_1)
        self.assertEqual(queryset[1], venue_production_2)
예제 #19
0
    def test_get_queryset(self):
        view = CityPerformanceView()
        view.city = None
        self.assertEqual(view.get_queryset(), [])

        view.city = 'Austin'
        production = ProductionFactory(
            venue=VenueFactory(address=AddressFactory(city='Austin'))
        )
        self.assertEqual(view.get_queryset()[0], production)
예제 #20
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), [])
예제 #21
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'])
예제 #22
0
 def test_get_context_data(self):
     start = timezone.now() - timedelta(days=5)
     end = timezone.now() - timedelta(days=2)
     production = ProductionFactory()
     with patch.object(self.view, '_get_range', return_value=(start, end)):
         with patch.object(
             self.view,
             'get_performances',
             return_value=[production]
         ):
             context = self.view.get_context_data()
     self.assertEqual([production], context['productions'])
     self.assertEqual(start, context['start_date'])
     self.assertEqual(end, context['end_date'])
예제 #23
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'])
예제 #24
0
    def test_filter_in_range(self):
        range_start = timezone.now()
        range_end = range_start + timedelta(days=5)

        past_full = ProductionFactory(start_date=range_start -
                                      timedelta(days=5),
                                      end_date=range_start - timedelta(days=3))
        past_short = ProductionFactory(start_date=range_start -
                                       timedelta(days=2))

        future_full = ProductionFactory(start_date=range_end +
                                        timedelta(days=3),
                                        end_date=range_end + timedelta(days=5))
        future_short = ProductionFactory(start_date=range_end +
                                         timedelta(days=2))

        current_short = ProductionFactory(start_date=range_start +
                                          timedelta(days=1))
        current_within = ProductionFactory(
            start_date=range_start + timedelta(days=1),
            end_date=range_end - timedelta(days=1))
        current_cover = ProductionFactory(
            start_date=range_start - timedelta(days=1),
            end_date=range_end + timedelta(days=1))
        current_overlap_start = ProductionFactory(
            start_date=range_start - timedelta(days=1),
            end_date=range_start + timedelta(days=1))
        current_overlap_end = ProductionFactory(
            start_date=range_end - timedelta(days=1),
            end_date=range_end + timedelta(days=1))

        in_range = Production.objects.filter_in_range(range_start, range_end)
        self.assertNotIn(past_full, in_range)
        self.assertNotIn(past_short, in_range)
        self.assertNotIn(future_full, in_range)
        self.assertNotIn(future_short, in_range)
        self.assertIn(current_short, in_range)
        self.assertIn(current_within, in_range)
        self.assertIn(current_cover, in_range)
        self.assertIn(current_overlap_start, in_range)
        self.assertIn(current_overlap_end, in_range)
예제 #25
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]
        )
예제 #26
0
 def test_get_context_data(self):
     view = CityPerformanceView()
     view.city = 'Austin'
     austin_venue = VenueFactory(address=AddressFactory(city='Austin'))
     bastrop_venue = VenueFactory(address=AddressFactory(city='Bastrop'))
     ProductionFactory(venue=austin_venue)
     city_venues = {
         'Austin': [austin_venue],
         'Bastrop': [bastrop_venue],
     }
     with patch(
         'django.views.generic.list.ListView.get_context_data',
         return_value={}
     ):
         with patch.object(
             Venue.objects,
             'filter_cities',
             return_value=city_venues
         ):
             context = view.get_context_data()
     self.assertEqual(context['city'], 'Austin')
     self.assertIn('Austin', context['cities'])
     self.assertNotIn('Bastrop', context['cities'])
예제 #27
0
    def test_duration(self):
        production = ProductionFactory()
        self.assertEqual(production.duration(),
                         production.start_date.strftime('%b. %d'))
        self.assertEqual(
            production.duration(append_year=True),
            '{}, {}'.format(production.start_date.strftime('%b. %d'),
                            str(production.start_date.year)))

        production = ProductionFactory(end_date=timezone.now() +
                                       timedelta(days=1))
        self.assertEqual(
            production.duration(), '{} - {}'.format(
                production.start_date.strftime('%b. %d'),
                production.end_date.strftime('%b. %d'),
            ))
        self.assertEqual(
            production.duration(conjuction='=+='), '{} =+= {}'.format(
                production.start_date.strftime('%b. %d'),
                production.end_date.strftime('%b. %d'),
            ))

        production = ProductionFactory(
            start_date=timezone.now() - timedelta(days=365),
            end_date=timezone.now() - timedelta(days=364))
        self.assertEqual(
            production.duration(date_format='%b'),
            '{} - {}, {}'.format(production.start_date.strftime('%b'),
                                 production.end_date.strftime('%b'),
                                 str(production.start_date.year)))
        self.assertEqual(
            production.duration(date_format='%Y'), '{} - {}'.format(
                production.start_date.strftime('%Y'),
                production.end_date.strftime('%Y'),
            ))
예제 #28
0
 def test_get_absolute_url(self):
     production = ProductionFactory()
     self.assertIsInstance(production.get_absolute_url(), unicode)
예제 #29
0
 def test_unicode(self):
     production = ProductionFactory()
     self.assertEqual(production.__unicode__(), unicode(production.title))
예제 #30
0
 def setUp(self):
     self.production = ProductionFactory()