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)
def test_get_title(self): audition = AuditionFactory() self.assertEqual(audition.get_title(), u'Auditions') audition = AuditionFactory(title='Test Title') self.assertEqual(audition.get_title(), u'Test Title') audition = AuditionFactory(play=PlayFactory()) self.assertEqual(audition.get_title(), u'Auditions for {}'.format(str(audition.play))) audition = AuditionFactory( production_company=ProductionCompanyFactory()) self.assertEqual( audition.get_title(), u'Auditions for {}'.format(str(audition.production_company))) audition = AuditionFactory( play=PlayFactory(), production_company=ProductionCompanyFactory(), ) self.assertEqual( audition.get_title(), u'Auditions for {play}, by {company}'.format( play=str(audition.play), company=str(audition.production_company), ))
def test_get_queryset(self): company_1 = ProductionCompanyFactory(name='A company') company_2 = ProductionCompanyFactory(name='The a different company') company_3 = ProductionCompanyFactory(name='b different company') view = LocalTheatresView() view.queryset = [company_1, company_2, company_3] ordered_companies = view.get_queryset() self.assertEqual( ordered_companies, [ ('A', [company_1, company_2]), ('B', [company_3]), ] )
def test_get_context_data(self): company = ProductionCompanyFactory() view = ProductionCompanyView() view.object = company with patch.object(company, 'get_related_news', return_value=[1, 2]): context = view.get_context_data() self.assertEqual(context['related_news'], [1, 2])
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_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)
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_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'])
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')
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))
def test_get_alt_description(self): audition = AuditionFactory() self.assertEqual( audition.get_alt_description(), 'Auditions on {}.'.format(audition.start_date.strftime('%b %d'))) audition = AuditionFactory(play=PlayFactory()) self.assertEqual( audition.get_alt_description(), 'Auditions for a role in {} on {}.'.format( str(audition.play), audition.start_date.strftime('%b %d'), )) audition = AuditionFactory( production_company=ProductionCompanyFactory()) self.assertEqual( audition.get_alt_description(), 'Auditions with {} on {}.'.format( str(audition.production_company), audition.start_date.strftime('%b %d'), )) audition = AuditionFactory(end_date=timezone.now() + timedelta(days=1)) self.assertEqual( audition.get_alt_description(), 'Auditions on {} through {}.'.format( audition.start_date.strftime('%b %d'), audition.end_date.strftime('%b %d'), )) audition = AuditionFactory( play=PlayFactory(), production_company=ProductionCompanyFactory(), end_date=timezone.now() + timedelta(days=1)) self.assertEqual( audition.get_alt_description(), 'Auditions for a role in {} with {} on {} through {}.'.format( str(audition.play), str(audition.production_company), audition.start_date.strftime('%b %d'), audition.end_date.strftime('%b %d'), ))
def test_get_queryset(self): company = ProductionCompanyFactory() company_audition = AuditionFactory(production_company=company) other_audition = AuditionFactory() view = CompanyPastAuditionListView() view.company = company with patch.object( PastAuditionListView, 'get_queryset', return_value=Audition.objects.all() ): queryset = view.get_queryset() self.assertIn(company_audition, queryset) self.assertNotIn(other_audition, queryset)
class ProductionCompanyTestCase(TestCase): def setUp(self): self.company = ProductionCompanyFactory() def test_review_set(self): production = ProductionFactory(production_company=self.company) review = ReviewFactory(production=production) self.assertIn(review, self.company.review_set) 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) 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_absolute_url(self): self.assertIsInstance(self.company.get_absolute_url(), unicode) def test_unicode(self): self.assertEqual(self.company.__unicode__(), unicode(self.company.name))
def test_get_queryset(self): company = ProductionCompanyFactory() audition_1 = AuditionFactory( production_company=company, start_date=timezone.now() + timedelta(days=1) ) audition_2 = AuditionFactory( production_company=company, start_date=timezone.now() + timedelta(days=2) ) view = CompanyAuditionListView() view.company = company queryset = view.get_queryset() self.assertEqual(queryset[0], audition_1) self.assertEqual(queryset[1], audition_2)
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 setUp(self): self.view = CompanyObjectListView() self.company = ProductionCompanyFactory()
def setUp(self): self.company = ProductionCompanyFactory()