Permalink
Browse files

Merge pull request #477 from reywood/master

Use default username and password if not specified in URLParameters
  • Loading branch information...
2 parents 54f48df + 01710ad commit d1876b0cb5ad9cacb67d0579c49ef1e8a97c0afb @gmr gmr committed Jun 29, 2014
Showing with 28 additions and 4 deletions.
  1. +4 −2 pika/connection.py
  2. +24 −2 tests/unit/parameter_tests.py
View
6 pika/connection.py
@@ -461,8 +461,10 @@ def _process_url(self, url):
self.ssl else self.DEFAULT_PORT
elif self._validate_port(parts.port):
self.port = parts.port
- self.credentials = pika_credentials.PlainCredentials(parts.username,
- parts.password)
+
+ if parts.username is not None:
+ self.credentials = pika_credentials.PlainCredentials(parts.username,
+ parts.password)
# Get the Virtual Host
if len(parts.path) <= 1:
View
26 tests/unit/parameter_tests.py
@@ -2,7 +2,7 @@
import pika
-class ConnectionTests(unittest.TestCase):
+class ParameterTests(unittest.TestCase):
def test_parameters_accepts_plain_string_virtualhost(self):
parameters = pika.ConnectionParameters(virtual_host="prtfqpeo")
@@ -34,4 +34,26 @@ def test_urlparameters_accepts_unicode_string(self):
self.assertEqual(parameters.virtual_host, "prtfqpeo")
self.assertEqual(parameters.credentials.password, "oihdglkhcp0")
self.assertEqual(parameters.credentials.username, "prtfqpeo")
- self.assertEqual(parameters.locale, "en_US")
+ self.assertEqual(parameters.locale, "en_US")
+
+ def test_urlparameters_uses_default_port_if_not_specified(self):
+ parameters = pika.URLParameters("amqp://myserver.mycompany.com")
+ self.assertEqual(parameters.port, pika.URLParameters.DEFAULT_PORT)
+
+ def test_urlparameters_uses_default_virtual_host_if_not_specified(self):
+ parameters = pika.URLParameters("amqp://myserver.mycompany.com")
+ self.assertEqual(parameters.virtual_host, pika.URLParameters.DEFAULT_VIRTUAL_HOST)
+
+ def test_urlparameters_uses_default_virtual_host_if_only_slash_is_specified(self):
+ parameters = pika.URLParameters("amqp://myserver.mycompany.com/")
+ self.assertEqual(parameters.virtual_host, pika.URLParameters.DEFAULT_VIRTUAL_HOST)
+
+ def test_urlparameters_uses_default_username_and_password_if_not_specified(self):
+ parameters = pika.URLParameters("amqp://myserver.mycompany.com")
+ self.assertEqual(parameters.credentials.username, pika.URLParameters.DEFAULT_USERNAME)
+ self.assertEqual(parameters.credentials.password, pika.URLParameters.DEFAULT_PASSWORD)
+
+ def test_urlparameters_accepts_blank_username_and_password(self):
+ parameters = pika.URLParameters("amqp://:@myserver.mycompany.com")
+ self.assertEqual(parameters.credentials.username, "")
+ self.assertEqual(parameters.credentials.password, "")

0 comments on commit d1876b0

Please sign in to comment.