summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsk Solem <ask@celeryproject.org>2012-07-09 07:30:29 +0100
committerAsk Solem <ask@celeryproject.org>2012-07-09 07:30:29 +0100
commitc151155a33f26b7c2a940aa86f7b517035744995 (patch)
tree8daaccdbfb822cafeddcd9f3cf73b2d8036a895b
parentc24ee01e90c4cf3849d3a3fae85cd107a00d0d79 (diff)
parent7d5d99a80f8f09391e22c91c8a108586acd2dc07 (diff)
downloadkombu-c151155a33f26b7c2a940aa86f7b517035744995.tar.gz
Merge branch 'master' of github.com:celery/kombu
-rw-r--r--kombu/tests/transport/test_mongodb.py22
-rw-r--r--kombu/transport/mongodb.py9
2 files changed, 25 insertions, 6 deletions
diff --git a/kombu/tests/transport/test_mongodb.py b/kombu/tests/transport/test_mongodb.py
index b4aa7618..97afa7ff 100644
--- a/kombu/tests/transport/test_mongodb.py
+++ b/kombu/tests/transport/test_mongodb.py
@@ -60,10 +60,28 @@ class test_mongodb(TestCase):
c = Connection(url, transport=Transport).connect()
client = c.channels[0].client
- url = 'mongodb://username:password@localhost/dbname'
+ # Login to admin db since there's no db specified
+ url = "mongodb://adminusername:adminpassword@localhost"
c = Connection(url, transport=Transport).connect()
- # Assuming there's no user 'username' with password 'password'
+ client = c.channels[0].client
+ self.assertEquals(client.name, "kombu_default")
+
+ # Lets make sure that using admin db doesn't break anything
+ # when no user is specified
+ url = "mongodb://localhost"
+ c = Connection(url, transport=Transport).connect()
+ client = c.channels[0].client
+
+ # Assuming there's user 'username' with password 'password'
# configured in mongodb
+ url = "mongodb://username:password@localhost/dbname"
+ c = Connection(url, transport=Transport).connect()
+ client = c.channels[0].client
+
+ # Assuming there's no user 'nousername' with password 'nopassword'
+ # configured in mongodb
+ url = "mongodb://nousername:nopassword@localhost/dbname"
+ c = Connection(url, transport=Transport).connect()
# Needed, otherwise the error would be rose before
# the assertRaises is called
diff --git a/kombu/transport/mongodb.py b/kombu/transport/mongodb.py
index e8342425..3f6ef8e4 100644
--- a/kombu/transport/mongodb.py
+++ b/kombu/transport/mongodb.py
@@ -120,6 +120,11 @@ class Channel(virtual.Channel):
dbname, options = part.split('?')
hostname += '/?' + options
+ hostname = "%s/%s" % (hostname, dbname in [None, "/"] and "admin" \
+ or dbname)
+ if not dbname or dbname == "/":
+ dbname = "kombu_default"
+
# At this point we expect the hostname to be something like
# (considering replica set form too):
#
@@ -132,15 +137,11 @@ class Channel(virtual.Channel):
'Kombu requires MongoDB version 1.3+, but connected to %s' % (
version, ))
- if not dbname or dbname == '/':
- dbname = 'kombu_default'
-
database = getattr(mongoconn, dbname)
# This is done by the connection uri
# if conninfo.userid:
# database.authenticate(conninfo.userid, conninfo.password)
-
self.db = database
col = database.messages
col.ensure_index([('queue', 1)])