| 243 | if 'TEST_DEPENDENCIES' in connection.settings_dict: |
| 244 | db_dependencies[alias] = connection.settings_dict['TEST_DEPENDENCIES'] |
| 245 | else: |
| 246 | if alias != 'default': |
| 247 | db_dependencies[alias] = connection.settings_dict.get('TEST_DEPENDENCIES', ['default']) |
| 248 | |
| 249 | # Ensure that the order in which the test databases are created |
| 250 | # satisfies any dependencies between databases. |
| 251 | ordered_test_databases = [] |
| 252 | resolved_databases = set() |
| 253 | test_databases = test_databases.items() |
| 254 | while test_databases: |
| 255 | changed = False |
| 256 | deferred = [] |
| 257 | |
| 258 | while test_databases: |
| 259 | signature, aliases = test_databases.pop() |
| 260 | |
| 261 | dependencies_satisfied = True |
| 262 | for alias in aliases: |
| 263 | if alias in db_dependencies: |
| 264 | if all(a in resolved_databases for a in db_dependencies[alias]): |
| 265 | # all dependencies for this alias are satisfied |
| 266 | db_dependencies.pop(alias) |
| 267 | resolved_databases.add(alias) |
| 268 | else: |
| 269 | resolved_databases.add(alias) |
| 270 | |
| 271 | if dependencies_satisfied: |
| 272 | ordered_test_databases.append((signature, aliases)) |
| 273 | changed = True |
| 274 | else: |
| 275 | deferred.append((signature, aliases)) |
| 276 | |
| 277 | if not changed: |
| 278 | raise Exception("Circular dependency in TEST_DEPENDENCIES") |
| 279 | test_databases = deferred |
| 280 | |