def test_many_to_many_mapping_cache_with_add(self):
        """
        Cache for both models in this many-to-many relationship should
        be updated when calling 'add' on related objects
        """
        new_cars = CarFactory.create_batch(size=3)
        initial_count = len(Driver.objects.get(id=self.driver.id).cars.all())
        self.driver.cars.add(*new_cars)
        reset_queries()

        # Cache for both models should be invalidated as add is an m2m change
        new_count = len(Driver.objects.get(id=self.driver.id).cars.all())
        self.assertEqual(len(connection.queries), 2)
        self.assertEqual(initial_count + 3, new_count)
    def test_many_to_many_mapping_cache_with_add(self):
        """
        Cache for both models in this many-to-many relationship should
        be updated when calling 'add' on related objects
        """
        new_cars = CarFactory.create_batch(size=3)
        initial_count = len(Driver.objects.get(id=self.driver.id).cars.all())
        self.driver.cars.add(*new_cars)
        reset_queries()

        # Cache for both models should be invalidated as add is an m2m change
        new_count = len(Driver.objects.get(id=self.driver.id).cars.all())
        self.assertEqual(len(connection.queries), 2)
        self.assertEqual(initial_count + 3, new_count)
 def setUp(self):
     self.manufacturers = ManufacturerFactory.create_batch(size=5)
     self.cars = CarFactory.create_batch(size=5, make=self.manufacturers[0])
     self.drivers = DriverFactory.create_batch(size=5, cars=[self.cars[0]])
 def setUp(self):
     self.manufacturers = ManufacturerFactory.create_batch(size=5)
     self.cars = CarFactory.create_batch(size=5, make=self.manufacturers[0])
     self.drivers = DriverFactory.create_batch(size=5, cars=[self.cars[0]])