Restrict the set of installed apps used by get_app_config[s]. available must be an iterable of application names. set_available_apps() must be balanced with unset_available_apps(). Primarily used for performance optimization in TransactionTestCase. This m
(self, available)
| 304 | return None |
| 305 | |
| 306 | def set_available_apps(self, available): |
| 307 | """ |
| 308 | Restrict the set of installed apps used by get_app_config[s]. |
| 309 | |
| 310 | available must be an iterable of application names. |
| 311 | |
| 312 | set_available_apps() must be balanced with unset_available_apps(). |
| 313 | |
| 314 | Primarily used for performance optimization in TransactionTestCase. |
| 315 | |
| 316 | This method is safe in the sense that it doesn't trigger any imports. |
| 317 | """ |
| 318 | available = set(available) |
| 319 | installed = {app_config.name for app_config in self.get_app_configs()} |
| 320 | if not available.issubset(installed): |
| 321 | raise ValueError( |
| 322 | "Available apps isn't a subset of installed apps, extra apps: %s" |
| 323 | % ", ".join(available - installed) |
| 324 | ) |
| 325 | |
| 326 | self.stored_app_configs.append(self.app_configs) |
| 327 | self.app_configs = { |
| 328 | label: app_config |
| 329 | for label, app_config in self.app_configs.items() |
| 330 | if app_config.name in available |
| 331 | } |
| 332 | self.clear_cache() |
| 333 | |
| 334 | def unset_available_apps(self): |
| 335 | """Cancel a previous call to set_available_apps().""" |