MCPcopy
hub / github.com/django/django / get_unique_databases_and_mirrors

Function get_unique_databases_and_mirrors

django/test/utils.py:327–380  ·  view source on GitHub ↗

Figure out which databases actually need to be created. Deduplicate entries in DATABASES that correspond the same database or are configured as test mirrors. Return two values: - test_databases: ordered mapping of signatures to (name, list of aliases) whe

(aliases=None)

Source from the content-addressed store, hash-verified

325
326
327def get_unique_databases_and_mirrors(aliases=None):
328 """
329 Figure out which databases actually need to be created.
330
331 Deduplicate entries in DATABASES that correspond the same database or are
332 configured as test mirrors.
333
334 Return two values:
335 - test_databases: ordered mapping of signatures to (name, list of aliases)
336 where all aliases share the same underlying database.
337 - mirrored_aliases: mapping of mirror aliases to original aliases.
338 """
339 if aliases is None:
340 aliases = connections
341 mirrored_aliases = {}
342 test_databases = {}
343 dependencies = {}
344 default_sig = connections[DEFAULT_DB_ALIAS].creation.test_db_signature()
345
346 for alias in connections:
347 connection = connections[alias]
348 test_settings = connection.settings_dict["TEST"]
349
350 if test_settings["MIRROR"]:
351 # If the database is marked as a test mirror, save the alias.
352 mirrored_aliases[alias] = test_settings["MIRROR"]
353 elif alias in aliases:
354 # Store a tuple with DB parameters that uniquely identify it.
355 # If we have two aliases with the same values for that tuple,
356 # we only need to create the test database once.
357 item = test_databases.setdefault(
358 connection.creation.test_db_signature(),
359 (connection.settings_dict["NAME"], []),
360 )
361 # The default database must be the first because data migrations
362 # use the default alias by default.
363 if alias == DEFAULT_DB_ALIAS:
364 item[1].insert(0, alias)
365 else:
366 item[1].append(alias)
367
368 if "DEPENDENCIES" in test_settings:
369 dependencies[alias] = test_settings["DEPENDENCIES"]
370 else:
371 if (
372 alias != DEFAULT_DB_ALIAS
373 and connection.creation.test_db_signature() != default_sig
374 ):
375 dependencies[alias] = test_settings.get(
376 "DEPENDENCIES", [DEFAULT_DB_ALIAS]
377 )
378
379 test_databases = dict(dependency_ordered(test_databases.items(), dependencies))
380 return test_databases, mirrored_aliases
381
382
383def teardown_databases(old_config, verbosity, parallel=0, keepdb=False):

Callers 2

setup_databasesFunction · 0.85

Calls 7

dependency_orderedFunction · 0.85
insertMethod · 0.80
test_db_signatureMethod · 0.45
setdefaultMethod · 0.45
appendMethod · 0.45
getMethod · 0.45
itemsMethod · 0.45

Tested by 1