예제 #1
0
    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))
예제 #2
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)
예제 #3
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)
예제 #4
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)
예제 #5
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'])
예제 #6
0
 def setUp(self):
     self.venue = VenueFactory()
예제 #7
0
 def test_unicode(self):
     venue = VenueFactory()
     self.assertEqual(venue.__unicode__(), unicode(venue.name))