Permalink
Browse files

Updated tests and fixed protocol/port mismatch. Fixes #2

  • Loading branch information...
1 parent 19d0a9d commit c435643c2b563cf8a0add91aeb4f7ba0f7815406 Paddy Foran committed Mar 2, 2012
Showing with 21 additions and 17 deletions.
  1. +2 −2 iron_mq.py
  2. +19 −15 test.py
View
@@ -43,7 +43,7 @@ class IronMQ:
DEFAULT_HOST = "mq-aws-us-east-1.iron.io"
USER_AGENT = "IronMQ Python v0.3"
- def __init__(self, token=None, project_id=None, host=DEFAULT_HOST, port=80,
+ def __init__(self, token=None, project_id=None, host=DEFAULT_HOST, port=443,
version=1, protocol='https', config=None, app_engine=False):
"""Prepare a configured instance of the API wrapper and return it.
@@ -52,7 +52,7 @@ def __init__(self, token=None, project_id=None, host=DEFAULT_HOST, port=80,
project_id -- The ID for the project, found on http://hud.iron.io
host -- The hostname of the API server.
Defaults to mq-aws-us-east-1.iron.io.
- port -- The port of the API server. Defaults to 80.
+ port -- The port of the API server. Defaults to 443.
version -- The API version to use. Defaults to 1.
protocol -- The protocol to use. Defaults to https.
config -- The config file to draw config values from. Defaults to None.
View
34 test.py
@@ -10,13 +10,9 @@ def setUp(self):
config = ConfigParser.RawConfigParser()
config.read('config.ini')
self.token = config.get("IronMQ", "token")
- self.host = config.get("IronMQ", "host")
- self.port = config.get("IronMQ", "port")
- self.version = config.get("IronMQ", "version")
self.project_id = config.get("IronMQ", "project_id")
- self.mq = IronMQ(token=self.token, host=self.host,
- port=self.port, version=self.version, project_id=self.project_id)
+ self.mq = IronMQ(token=self.token, project_id=self.project_id)
def test_headers(self):
self.assertEqual(self.mq.headers['Accept'], "application/json")
@@ -25,25 +21,33 @@ def test_headers(self):
self.assertEqual(self.mq.headers['User-Agent'],
"IronMQ Python v0.3")
+ def test_protocols(self):
+ mq = IronMQ(token=self.token, project_id=self.project_id)
+ if mq.protocol == "http":
+ self.assertEqual(mq.port, 80)
+ elif mq.protocol == "https":
+ self.assertEqual(mq.port, 443)
+ self.assertTrue(mq.protocol in ["http", "https"])
+
def test_postMessage(self):
- queue = self.mq.getQueueDetails("test_q")
- self.mq.postMessage("test_q", ["test message"])
- queue2 = self.mq.getQueueDetails("test_q")
+ queue = self.mq.getQueueDetails("test_queue")
+ self.mq.postMessage("test_queue", ["test message"])
+ queue2 = self.mq.getQueueDetails("test_queue")
self.assertEqual(queue["size"], (queue2["size"] - 1))
def test_getMessage(self):
msg = "%s" % time.time()
- self.mq.postMessage(msg, [msg])
- message = self.mq.getMessage(msg)
+ self.mq.postMessage("test_queue", [msg])
+ message = self.mq.getMessage("test_queue")
message = "%s" % message["messages"][0]["body"]
self.assertEqual(msg, message)
def test_deleteMessage(self):
- queue = self.mq.getQueueDetails("test_q")
- msg = self.mq.postMessage("test_q", ["test"])
- queue2 = self.mq.getQueueDetails("test_q")
- self.mq.deleteMessage("test_q", msg["ids"][0])
- queue3 = self.mq.getQueueDetails("test_q")
+ queue = self.mq.getQueueDetails("test_queue")
+ msg = self.mq.postMessage("test_queue", ["test"])
+ queue2 = self.mq.getQueueDetails("test_queue")
+ self.mq.deleteMessage("test_queue", msg["ids"][0])
+ queue3 = self.mq.getQueueDetails("test_queue")
self.assertEqual(queue["size"], (queue2["size"] - 1))
self.assertEqual(queue["size"], queue3["size"])

0 comments on commit c435643

Please sign in to comment.