From 27bcc64ac57356ddd08643f4bfb7e43effafc281 Mon Sep 17 00:00:00 2001 From: Jason Pellerin Date: Sun, 17 Sep 2006 19:12:04 +0000 Subject: [multi-db] Fixed bugs in connection handling and test database setup. All tests now pass for postgres backend. Still failures for mysql and sqlite3, others unknown. git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@3768 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/multiple_databases/models.py | 29 ++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'tests/modeltests/multiple_databases/models.py') diff --git a/tests/modeltests/multiple_databases/models.py b/tests/modeltests/multiple_databases/models.py index 97e91b429c..a0fa492631 100644 --- a/tests/modeltests/multiple_databases/models.py +++ b/tests/modeltests/multiple_databases/models.py @@ -84,22 +84,24 @@ Connection: ... >>> connections['_b'] Connection: ... -# Let's see what connections are available.The default connection is -# in there, but let's ignore it - ->>> non_default = connections.keys() ->>> non_default.remove(_default) ->>> non_default.sort() ->>> non_default -['_a', '_b'] +# Let's see what connections are available. The default connection is always +# included in connections as well, and may be accessed as connections[_default]. + +>>> connection_names = connections.keys() +>>> connection_names.sort() +>>> connection_names +[, '_a', '_b'] # Invalid connection names raise ImproperlyConfigured + >>> connections['bad'] Traceback (most recent call last): ... ImproperlyConfigured: No database connection 'bad' has been configured -# Models can access their connections through their managers +# The model_connection_name() function will tell you the name of the +# connection that a model is configured to use. + >>> model_connection_name(Artist) '_a' >>> model_connection_name(Widget) @@ -116,6 +118,15 @@ True >>> list(artists) [] +# Models can access their connections through the db property of their +# default manager. + +>>> paul = _[0] +>>> Artist.objects.db +Connection: ... (ENGINE=... NAME=...) +>>> paul._default_manager.db +Connection: ... (ENGINE=... NAME=...) + # When transactions are not managed, model save will commit only # for the model's connection. -- cgit v1.3