summaryrefslogtreecommitdiff
path: root/tests/modeltests/multiple_databases
diff options
context:
space:
mode:
authorJason Pellerin <jpellerin@gmail.com>2006-09-17 19:12:04 +0000
committerJason Pellerin <jpellerin@gmail.com>2006-09-17 19:12:04 +0000
commit27bcc64ac57356ddd08643f4bfb7e43effafc281 (patch)
treedee5466977cba90e125f45d9285f44db0f574108 /tests/modeltests/multiple_databases
parentecb5b81e0d3f0a50f33dcf1d4adfb11d34608a2c (diff)
[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
Diffstat (limited to 'tests/modeltests/multiple_databases')
-rw-r--r--tests/modeltests/multiple_databases/models.py27
1 files changed, 19 insertions, 8 deletions
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
+# Let's see what connections are available. The default connection is always
+# included in connections as well, and may be accessed as connections[_default].
->>> non_default = connections.keys()
->>> non_default.remove(_default)
->>> non_default.sort()
->>> non_default
-['_a', '_b']
+>>> connection_names = connections.keys()
+>>> connection_names.sort()
+>>> connection_names
+[<default>, '_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)
[<Artist: Paul Klee>]
+# 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.