def test_filter_cities(self): city1 = 'Austin' city2 = 'San Antonio' venue1 = VenueFactory(address=AddressFactory(city=city1)) venue2 = VenueFactory(address=AddressFactory(city=city2)) by_city = Venue.objects.filter_cities() self.assertIn(city1, by_city) self.assertIn(city2, by_city) self.assertIn(venue1, by_city.get(city1)) self.assertIn(venue2, by_city.get(city2))
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)
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)
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)
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'])
def setUp(self): self.venue = VenueFactory()
def test_unicode(self): venue = VenueFactory() self.assertEqual(venue.__unicode__(), unicode(venue.name))