diff options
-rw-r--r-- | kombu/tests/transport/test_mongodb.py | 22 | ||||
-rw-r--r-- | kombu/transport/mongodb.py | 9 |
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)]) |