| 141 | def test_to_field_clear_reverse(self): |
| 142 | self.driver.car_set.clear() |
| 143 | self.assertQuerysetEqual( |
| 144 | self.driver.car_set.all(),[]) |
| 145 | |
| 146 | def test_to_field_clear(self): |
| 147 | self.car.drivers.clear() |
| 148 | self.assertQuerysetEqual( |
| 149 | self.car.drivers.all(),[]) |
| 150 | |
| 151 | def test_add(self): |
| 152 | driver2 = Driver.objects.get(name="Barney Gumble") |
| 153 | self.assertQuerysetEqual( |
| 154 | self.car.drivers.all(), |
| 155 | ["<Driver: Ryan Briscoe>"] |
| 156 | ) |
| 157 | self.car.drivers._add_items('car', 'driver', driver2) |
| 158 | self.assertQuerysetEqual( |
| 159 | self.car.drivers.all(), |
| 160 | ["<Driver: Ryan Briscoe>", "<Driver: Barney Gumble>"] |
| 161 | ) |
| 162 | |
| 163 | def test_add_reverse(self): |
| 164 | car2 = Car.objects.create(make="Honda") |
| 165 | self.assertQuerysetEqual( |
| 166 | self.driver.car_set.all(), |
| 167 | ["<Car: Toyota>"] |
| 168 | ) |
| 169 | self.driver.car_set._add_items('driver', 'car', car2) |
| 170 | self.assertQuerysetEqual( |
| 171 | self.driver.car_set.all(), |
| 172 | ["<Car: Toyota>", "<Car: Honda>"] |
| 173 | ) |
| 174 | |
| 175 | def test_remove(self): |
| 176 | self.assertQuerysetEqual( |
| 177 | self.car.drivers.all(), |
| 178 | ["<Driver: Ryan Briscoe>"] |
| 179 | ) |
| 180 | self.car.drivers._remove_items('car', 'driver', self.driver) |
| 181 | self.assertQuerysetEqual( |
| 182 | self.car.drivers.all(),[]) |
| 183 | |
| 184 | |
| 185 | def test_remove_reverse(self): |
| 186 | self.assertQuerysetEqual( |
| 187 | self.driver.car_set.all(), |
| 188 | ["<Car: Toyota>"] |
| 189 | ) |
| 190 | self.driver.car_set._remove_items('driver', 'car', self.car) |
| 191 | self.assertQuerysetEqual( |
| 192 | self.driver.car_set.all(),[]) |
| 193 | |
| 194 | |