MCPcopy
hub / github.com/django/django / test_no_duplicate_managers

Method test_no_duplicate_managers

tests/migrations/test_state.py:260–289  ·  view source on GitHub ↗

When a manager is added with `use_in_migrations = True` and a parent model had a manager with the same name and `use_in_migrations = True`, the parent's manager shouldn't appear in the model state (#26881).

(self)

Source from the content-addressed store, hash-verified

258 self.assertEqual(author_state.managers, [])
259
260 def test_no_duplicate_managers(self):
261 """
262 When a manager is added with `use_in_migrations = True` and a parent
263 model had a manager with the same name and `use_in_migrations = True`,
264 the parent's manager shouldn't appear in the model state (#26881).
265 """
266 new_apps = Apps(["migrations"])
267
268 class PersonManager(models.Manager):
269 use_in_migrations = True
270
271 class Person(models.Model):
272 objects = PersonManager()
273
274 class Meta:
275 abstract = True
276
277 class BossManager(PersonManager):
278 use_in_migrations = True
279
280 class Boss(Person):
281 objects = BossManager()
282
283 class Meta:
284 app_label = "migrations"
285 apps = new_apps
286
287 project_state = ProjectState.from_apps(new_apps)
288 boss_state = project_state.models["migrations", "boss"]
289 self.assertEqual(boss_state.managers, [("objects", Boss.objects)])
290
291 def test_custom_default_manager(self):
292 new_apps = Apps(["migrations"])

Callers

nothing calls this directly

Calls 2

AppsClass · 0.90
from_appsMethod · 0.80

Tested by

no test coverage detected