MCPcopy
hub / github.com/django/django / test_dynamic_load

Method test_dynamic_load

tests/apps/tests.py:295–315  ·  view source on GitHub ↗

Makes a new model at runtime and ensures it goes into the right place.

(self)

Source from the content-addressed store, hash-verified

293 apps.models_ready = True
294
295 def test_dynamic_load(self):
296 """
297 Makes a new model at runtime and ensures it goes into the right place.
298 """
299 old_models = list(apps.get_app_config("apps").get_models())
300 # Construct a new model in a new app registry
301 body = {}
302 new_apps = Apps(["apps"])
303 meta_contents = {
304 "app_label": "apps",
305 "apps": new_apps,
306 }
307 meta = type("Meta", (), meta_contents)
308 body["Meta"] = meta
309 body["__module__"] = TotallyNormal.__module__
310 temp_model = type("SouthPonies", (models.Model,), body)
311 # Make sure it appeared in the right place!
312 self.assertEqual(list(apps.get_app_config("apps").get_models()), old_models)
313 with self.assertRaises(LookupError):
314 apps.get_model("apps", "SouthPonies")
315 self.assertEqual(new_apps.get_model("apps", "SouthPonies"), temp_model)
316
317 def test_model_clash(self):
318 """

Callers

nothing calls this directly

Calls 4

get_modelMethod · 0.95
AppsClass · 0.90
get_app_configMethod · 0.80
get_modelsMethod · 0.45

Tested by

no test coverage detected