{"action":"created","comment":{"url":"https://api.github.com/repos/numenta/numenta-apps/pulls/comments/31961958","id":31961958,"diff_hunk":"@@ -0,0 +1,870 @@\n+#!/usr/bin/env python\n+# ----------------------------------------------------------------------\n+# Copyright (C) 2015 Numenta Inc. All rights reserved.\n+#\n+# The information and source code contained herein is the\n+# exclusive property of Numenta Inc. No part of this software\n+# may be used, reproduced, stored or distributed in any form,\n+# without explicit written authorization from Numenta Inc.\n+# ----------------------------------------------------------------------\n+\n+\"\"\"\n+Integration tests for the nta.utils.amqp.SynchronousAmqpClient module\n+\"\"\"\n+\n+import logging\n+import requests\n+import unittest\n+from random import randint\n+\n+from nta.utils.error_handling import retry\n+from nta.utils.amqp import (\n+    AmqpChannelError,\n+    Consumer,\n+    Message,\n+    QueueDeclarationResult,\n+    UnroutableError)\n+from nta.utils.amqp import (\n+    getRabbitmqConnectionParameters,\n+    RabbitmqManagementConnectionParams)\n+from nta.utils.amqp import SynchronousAmqpClient\n+from nta.utils.logging_support_raw import LoggingSupport\n+from nta.utils.test_utils import amqp_test_utils\n+\n+\n+_LOGGER = logging.getLogger(__name__)\n+\n+\n+def setUpModule():\n+  LoggingSupport.initTestApp()\n+\n+\n+\n+_RETRY_ON_ASSERTION_ERROR = retry(timeoutSec=10, initialRetryDelaySec=0.5,\n+                                  maxRetryDelaySec=2,\n+                                  retryExceptions=(AssertionError,),\n+                                  logger=_LOGGER)\n+\n+\n+\n+@amqp_test_utils.RabbitmqVirtualHostPatch(\n+    clientLabel=\"testingAmqpClient\",\n+    logger=_LOGGER)\n+class SynchronousAmqpClientTest(unittest.TestCase):\n+  \"\"\" Test for nta.utils.amqp.SynchronousAmqpClient \"\"\"\n+\n+  def __init__(self, *args, **kwargs):\n+    super(SynchronousAmqpClientTest, self).__init__(*args, **kwargs)\n+    self.connParams = None\n+    self.client = None\n+\n+\n+  def _connectToClient(self):\n+    \"\"\"\n+    Setup method to run at beginning of test. Since tests are wrapped with the\n+    amqp_test_utils.RabbitmqVirtualHostPatch, connection parameters for the\n+    SynchronousAmqpClient MUST be checked during the test AND NOT during the\n+    usual setUp() method of unittest.TestCase, since the patch only applies to\n+    functions with the prefix specified in\n+    amqp_test_utils.RabbitmqVirtualHostPatch (test).\n+    \"\"\"\n+    self.connParams = RabbitmqManagementConnectionParams()\n+    self.client = SynchronousAmqpClient(getRabbitmqConnectionParameters())\n+    self.addCleanup(self.client.close)\n+    self.assertTrue(self.client.isOpen())\n+\n+\n+  def assertRaisesCode(self, excClass, excCode, callableObj=None,\n+                       *args, **kwargs):\n+    \"\"\"\n+    Asserts that an Exception with a particular \"code\" is raised.\n+\n+    :param Exception excClass: class of Exception to be raised\n+    :param int excCode: Exception.code to assert the exception contains\n+    \"\"\"\n+    try:\n+      callableObj(*args, **kwargs)\n+    except excClass, e:\n+      self.assertEqual(type(e), excClass)\n+      self.assertEqual(e.code, excCode)\n+      return\n+\n+    raise self.failureException(\"%s not raised\" % (excClass.__name__,))\n+\n+\n+  @_RETRY_ON_ASSERTION_ERROR\n+  def _verifyDeletedExchange(self, exchangeName):\n+    \"\"\"\n+    Verifies that a given exchange does not exist.\n+\n+    :param str exchangeName: Exchange name\n+    \"\"\"\n+    response = requests.get(\n+        url=\"http://%s:%s/api/exchanges/%s/%s\" % (\n+            self.connParams.host,\n+            self.connParams.port,\n+            self.connParams.vhost,\n+            exchangeName),\n+        auth=(self.connParams.username,\n+              self.connParams.password))\n+    self.assertEqual(response.status_code, 404,\n+                     \"Exchange didn't properly delete\")\n+\n+\n+  @_RETRY_ON_ASSERTION_ERROR\n+  def _verifyQueue(self, testQueueName, testConsumerCount=0,\n+                   testMessageCount=0):\n+    \"\"\"\n+    Verifies that a given queue exists, with optional verification of message\n+    and consumer counts.\n+\n+    :param str testQueueName: Queue name\n+    :param int testConsumerCount: (optional)\n+    :param int testMessageCount: (optional)\n+    \"\"\"\n+    queue = requests.get(\n+        url=\"http://%s:%s/api/queues/%s/%s\" % (\n+            self.connParams.host,\n+            self.connParams.port,\n+            self.connParams.vhost,\n+            testQueueName),\n+        auth=(self.connParams.username,\n+              self.connParams.password)\n+    ).json()\n+    self.assertEqual(queue[\"name\"], testQueueName)\n+    self.assertEqual(queue[\"consumers\"], testConsumerCount)\n+    self.assertEqual(queue[\"messages\"], testMessageCount)\n+\n+\n+  @_RETRY_ON_ASSERTION_ERROR\n+  def _verifyDeletedQueue(self, queueName):\n+    \"\"\"\n+    Verifies that a given queue does not exist.\n+\n+    :param queueName: Queue name\n+    \"\"\"\n+    response = requests.get(\n+        url=\"http://%s:%s/api/queues/%s/%s\" % (\n+            self.connParams.host,\n+            self.connParams.port,\n+            self.connParams.vhost,\n+            queueName),\n+        auth=(self.connParams.username,\n+              self.connParams.password))\n+    self.assertEqual(response.status_code, 404, \"Queue didn't properly delete\")\n+\n+\n+  def testDeclareAndDeleteDirectExchange(self):\n+    \"\"\"  Test creating and deleting a new exchange (type = direct) \"\"\"\n+    self._connectToClient()\n+    exchangeName = \"testExchange\"\n+    exchangeType = \"direct\"\n+\n+    self.assertRaisesCode(AmqpChannelError,\n+                          404,\n+                          self.client.declareExchange,\n+                          exchangeName,\n+                          exchangeType,\n+                          passive=True)\n+\n+\n+    self.client.declareExchange(exchangeName, exchangeType)\n+    exchange = requests.get(\n+        url=\"http://%s:%s/api/exchanges/%s/%s\" % (\n+            self.connParams.host,\n+            self.connParams.port,\n+            self.connParams.vhost,\n+            exchangeName),\n+        auth=(self.connParams.username,\n+              self.connParams.password)\n+    ).json()\n+    self.assertEqual(exchange[\"name\"], exchangeName)\n+    self.assertEqual(exchange[\"type\"], exchangeType)\n+\n+    try:\n+      self.client.declareExchange(exchangeName, exchangeType, passive=True)","path":"nta.utils/tests/integration/synchronous_amqp_client_test.py","position":185,"original_position":185,"commit_id":"866942c366f35de39eaaf70a8f12684ad1aa97b2","original_commit_id":"866942c366f35de39eaaf70a8f12684ad1aa97b2","user":{"login":"vitaly-krugl","id":1441066,"avatar_url":"https://avatars.githubusercontent.com/u/1441066?v=3","gravatar_id":"","url":"https://api.github.com/users/vitaly-krugl","html_url":"https://github.com/vitaly-krugl","followers_url":"https://api.github.com/users/vitaly-krugl/followers","following_url":"https://api.github.com/users/vitaly-krugl/following{/other_user}","gists_url":"https://api.github.com/users/vitaly-krugl/gists{/gist_id}","starred_url":"https://api.github.com/users/vitaly-krugl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vitaly-krugl/subscriptions","organizations_url":"https://api.github.com/users/vitaly-krugl/orgs","repos_url":"https://api.github.com/users/vitaly-krugl/repos","events_url":"https://api.github.com/users/vitaly-krugl/events{/privacy}","received_events_url":"https://api.github.com/users/vitaly-krugl/received_events","type":"User","site_admin":false},"body":"Verify that all attributes of the return value match expectations.","created_at":"2015-06-08T21:31:45Z","updated_at":"2015-06-08T21:31:45Z","html_url":"https://github.com/numenta/numenta-apps/pull/6#discussion_r31961958","pull_request_url":"https://api.github.com/repos/numenta/numenta-apps/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/numenta/numenta-apps/pulls/comments/31961958"},"html":{"href":"https://github.com/numenta/numenta-apps/pull/6#discussion_r31961958"},"pull_request":{"href":"https://api.github.com/repos/numenta/numenta-apps/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/numenta/numenta-apps/pulls/6","id":37060521,"html_url":"https://github.com/numenta/numenta-apps/pull/6","diff_url":"https://github.com/numenta/numenta-apps/pull/6.diff","patch_url":"https://github.com/numenta/numenta-apps/pull/6.patch","issue_url":"https://api.github.com/repos/numenta/numenta-apps/issues/6","number":6,"state":"open","locked":false,"title":"TAUR-1200: synchronous amqp client integration test","user":{"login":"jaredweiss","id":1041441,"avatar_url":"https://avatars.githubusercontent.com/u/1041441?v=3","gravatar_id":"","url":"https://api.github.com/users/jaredweiss","html_url":"https://github.com/jaredweiss","followers_url":"https://api.github.com/users/jaredweiss/followers","following_url":"https://api.github.com/users/jaredweiss/following{/other_user}","gists_url":"https://api.github.com/users/jaredweiss/gists{/gist_id}","starred_url":"https://api.github.com/users/jaredweiss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaredweiss/subscriptions","organizations_url":"https://api.github.com/users/jaredweiss/orgs","repos_url":"https://api.github.com/users/jaredweiss/repos","events_url":"https://api.github.com/users/jaredweiss/events{/privacy}","received_events_url":"https://api.github.com/users/jaredweiss/received_events","type":"User","site_admin":false},"body":"Creates integration tests for the nta.utils.amqp.SynchronousAmqpClient\r\n\r\nhttps://jira.numenta.com/browse/TAUR-1200\r\n\r\n@scottpurdy  @vitaly-krugl please review","created_at":"2015-06-05T19:05:03Z","updated_at":"2015-06-08T21:31:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5369f90324a188671c20dec373bfc0d45c51a787","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/numenta/numenta-apps/pulls/6/commits","review_comments_url":"https://api.github.com/repos/numenta/numenta-apps/pulls/6/comments","review_comment_url":"https://api.github.com/repos/numenta/numenta-apps/pulls/comments{/number}","comments_url":"https://api.github.com/repos/numenta/numenta-apps/issues/6/comments","statuses_url":"https://api.github.com/repos/numenta/numenta-apps/statuses/866942c366f35de39eaaf70a8f12684ad1aa97b2","head":{"label":"jaredweiss:TAUR-1200-synchronous-amqp-client-integration-test","ref":"TAUR-1200-synchronous-amqp-client-integration-test","sha":"866942c366f35de39eaaf70a8f12684ad1aa97b2","user":{"login":"jaredweiss","id":1041441,"avatar_url":"https://avatars.githubusercontent.com/u/1041441?v=3","gravatar_id":"","url":"https://api.github.com/users/jaredweiss","html_url":"https://github.com/jaredweiss","followers_url":"https://api.github.com/users/jaredweiss/followers","following_url":"https://api.github.com/users/jaredweiss/following{/other_user}","gists_url":"https://api.github.com/users/jaredweiss/gists{/gist_id}","starred_url":"https://api.github.com/users/jaredweiss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaredweiss/subscriptions","organizations_url":"https://api.github.com/users/jaredweiss/orgs","repos_url":"https://api.github.com/users/jaredweiss/repos","events_url":"https://api.github.com/users/jaredweiss/events{/privacy}","received_events_url":"https://api.github.com/users/jaredweiss/received_events","type":"User","site_admin":false},"repo":{"id":36945185,"name":"numenta-apps","full_name":"jaredweiss/numenta-apps","owner":{"login":"jaredweiss","id":1041441,"avatar_url":"https://avatars.githubusercontent.com/u/1041441?v=3","gravatar_id":"","url":"https://api.github.com/users/jaredweiss","html_url":"https://github.com/jaredweiss","followers_url":"https://api.github.com/users/jaredweiss/followers","following_url":"https://api.github.com/users/jaredweiss/following{/other_user}","gists_url":"https://api.github.com/users/jaredweiss/gists{/gist_id}","starred_url":"https://api.github.com/users/jaredweiss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaredweiss/subscriptions","organizations_url":"https://api.github.com/users/jaredweiss/orgs","repos_url":"https://api.github.com/users/jaredweiss/repos","events_url":"https://api.github.com/users/jaredweiss/events{/privacy}","received_events_url":"https://api.github.com/users/jaredweiss/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jaredweiss/numenta-apps","description":"","fork":true,"url":"https://api.github.com/repos/jaredweiss/numenta-apps","forks_url":"https://api.github.com/repos/jaredweiss/numenta-apps/forks","keys_url":"https://api.github.com/repos/jaredweiss/numenta-apps/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jaredweiss/numenta-apps/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jaredweiss/numenta-apps/teams","hooks_url":"https://api.github.com/repos/jaredweiss/numenta-apps/hooks","issue_events_url":"https://api.github.com/repos/jaredweiss/numenta-apps/issues/events{/number}","events_url":"https://api.github.com/repos/jaredweiss/numenta-apps/events","assignees_url":"https://api.github.com/repos/jaredweiss/numenta-apps/assignees{/user}","branches_url":"https://api.github.com/repos/jaredweiss/numenta-apps/branches{/branch}","tags_url":"https://api.github.com/repos/jaredweiss/numenta-apps/tags","blobs_url":"https://api.github.com/repos/jaredweiss/numenta-apps/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jaredweiss/numenta-apps/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jaredweiss/numenta-apps/git/refs{/sha}","trees_url":"https://api.github.com/repos/jaredweiss/numenta-apps/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jaredweiss/numenta-apps/statuses/{sha}","languages_url":"https://api.github.com/repos/jaredweiss/numenta-apps/languages","stargazers_url":"https://api.github.com/repos/jaredweiss/numenta-apps/stargazers","contributors_url":"https://api.github.com/repos/jaredweiss/numenta-apps/contributors","subscribers_url":"https://api.github.com/repos/jaredweiss/numenta-apps/subscribers","subscription_url":"https://api.github.com/repos/jaredweiss/numenta-apps/subscription","commits_url":"https://api.github.com/repos/jaredweiss/numenta-apps/commits{/sha}","git_commits_url":"https://api.github.com/repos/jaredweiss/numenta-apps/git/commits{/sha}","comments_url":"https://api.github.com/repos/jaredweiss/numenta-apps/comments{/number}","issue_comment_url":"https://api.github.com/repos/jaredweiss/numenta-apps/issues/comments{/number}","contents_url":"https://api.github.com/repos/jaredweiss/numenta-apps/contents/{+path}","compare_url":"https://api.github.com/repos/jaredweiss/numenta-apps/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jaredweiss/numenta-apps/merges","archive_url":"https://api.github.com/repos/jaredweiss/numenta-apps/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jaredweiss/numenta-apps/downloads","issues_url":"https://api.github.com/repos/jaredweiss/numenta-apps/issues{/number}","pulls_url":"https://api.github.com/repos/jaredweiss/numenta-apps/pulls{/number}","milestones_url":"https://api.github.com/repos/jaredweiss/numenta-apps/milestones{/number}","notifications_url":"https://api.github.com/repos/jaredweiss/numenta-apps/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jaredweiss/numenta-apps/labels{/name}","releases_url":"https://api.github.com/repos/jaredweiss/numenta-apps/releases{/id}","created_at":"2015-06-05T17:14:33Z","updated_at":"2015-06-05T17:14:37Z","pushed_at":"2015-06-08T20:48:59Z","git_url":"git://github.com/jaredweiss/numenta-apps.git","ssh_url":"git@github.com:jaredweiss/numenta-apps.git","clone_url":"https://github.com/jaredweiss/numenta-apps.git","svn_url":"https://github.com/jaredweiss/numenta-apps","homepage":null,"size":43363,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"numenta:master","ref":"master","sha":"3f0c05159bb9c076b521c9a1822a86d3323e81c0","user":{"login":"numenta","id":1039191,"avatar_url":"https://avatars.githubusercontent.com/u/1039191?v=3","gravatar_id":"","url":"https://api.github.com/users/numenta","html_url":"https://github.com/numenta","followers_url":"https://api.github.com/users/numenta/followers","following_url":"https://api.github.com/users/numenta/following{/other_user}","gists_url":"https://api.github.com/users/numenta/gists{/gist_id}","starred_url":"https://api.github.com/users/numenta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numenta/subscriptions","organizations_url":"https://api.github.com/users/numenta/orgs","repos_url":"https://api.github.com/users/numenta/repos","events_url":"https://api.github.com/users/numenta/events{/privacy}","received_events_url":"https://api.github.com/users/numenta/received_events","type":"Organization","site_admin":false},"repo":{"id":36754402,"name":"numenta-apps","full_name":"numenta/numenta-apps","owner":{"login":"numenta","id":1039191,"avatar_url":"https://avatars.githubusercontent.com/u/1039191?v=3","gravatar_id":"","url":"https://api.github.com/users/numenta","html_url":"https://github.com/numenta","followers_url":"https://api.github.com/users/numenta/followers","following_url":"https://api.github.com/users/numenta/following{/other_user}","gists_url":"https://api.github.com/users/numenta/gists{/gist_id}","starred_url":"https://api.github.com/users/numenta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numenta/subscriptions","organizations_url":"https://api.github.com/users/numenta/orgs","repos_url":"https://api.github.com/users/numenta/repos","events_url":"https://api.github.com/users/numenta/events{/privacy}","received_events_url":"https://api.github.com/users/numenta/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/numenta/numenta-apps","description":"HTM based applications and support libraries. Includes Grok for IT Analytics and Grok for Stocks.","fork":false,"url":"https://api.github.com/repos/numenta/numenta-apps","forks_url":"https://api.github.com/repos/numenta/numenta-apps/forks","keys_url":"https://api.github.com/repos/numenta/numenta-apps/keys{/key_id}","collaborators_url":"https://api.github.com/repos/numenta/numenta-apps/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/numenta/numenta-apps/teams","hooks_url":"https://api.github.com/repos/numenta/numenta-apps/hooks","issue_events_url":"https://api.github.com/repos/numenta/numenta-apps/issues/events{/number}","events_url":"https://api.github.com/repos/numenta/numenta-apps/events","assignees_url":"https://api.github.com/repos/numenta/numenta-apps/assignees{/user}","branches_url":"https://api.github.com/repos/numenta/numenta-apps/branches{/branch}","tags_url":"https://api.github.com/repos/numenta/numenta-apps/tags","blobs_url":"https://api.github.com/repos/numenta/numenta-apps/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/numenta/numenta-apps/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/numenta/numenta-apps/git/refs{/sha}","trees_url":"https://api.github.com/repos/numenta/numenta-apps/git/trees{/sha}","statuses_url":"https://api.github.com/repos/numenta/numenta-apps/statuses/{sha}","languages_url":"https://api.github.com/repos/numenta/numenta-apps/languages","stargazers_url":"https://api.github.com/repos/numenta/numenta-apps/stargazers","contributors_url":"https://api.github.com/repos/numenta/numenta-apps/contributors","subscribers_url":"https://api.github.com/repos/numenta/numenta-apps/subscribers","subscription_url":"https://api.github.com/repos/numenta/numenta-apps/subscription","commits_url":"https://api.github.com/repos/numenta/numenta-apps/commits{/sha}","git_commits_url":"https://api.github.com/repos/numenta/numenta-apps/git/commits{/sha}","comments_url":"https://api.github.com/repos/numenta/numenta-apps/comments{/number}","issue_comment_url":"https://api.github.com/repos/numenta/numenta-apps/issues/comments{/number}","contents_url":"https://api.github.com/repos/numenta/numenta-apps/contents/{+path}","compare_url":"https://api.github.com/repos/numenta/numenta-apps/compare/{base}...{head}","merges_url":"https://api.github.com/repos/numenta/numenta-apps/merges","archive_url":"https://api.github.com/repos/numenta/numenta-apps/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/numenta/numenta-apps/downloads","issues_url":"https://api.github.com/repos/numenta/numenta-apps/issues{/number}","pulls_url":"https://api.github.com/repos/numenta/numenta-apps/pulls{/number}","milestones_url":"https://api.github.com/repos/numenta/numenta-apps/milestones{/number}","notifications_url":"https://api.github.com/repos/numenta/numenta-apps/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/numenta/numenta-apps/labels{/name}","releases_url":"https://api.github.com/repos/numenta/numenta-apps/releases{/id}","created_at":"2015-06-02T18:49:30Z","updated_at":"2015-06-08T08:13:05Z","pushed_at":"2015-06-08T21:13:16Z","git_url":"git://github.com/numenta/numenta-apps.git","ssh_url":"git@github.com:numenta/numenta-apps.git","clone_url":"https://github.com/numenta/numenta-apps.git","svn_url":"https://github.com/numenta/numenta-apps","homepage":"http://numenta.com","size":44493,"stargazers_count":5,"watchers_count":5,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":14,"mirror_url":null,"open_issues_count":6,"forks":14,"open_issues":6,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/numenta/numenta-apps/pulls/6"},"html":{"href":"https://github.com/numenta/numenta-apps/pull/6"},"issue":{"href":"https://api.github.com/repos/numenta/numenta-apps/issues/6"},"comments":{"href":"https://api.github.com/repos/numenta/numenta-apps/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/numenta/numenta-apps/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/numenta/numenta-apps/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/numenta/numenta-apps/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/numenta/numenta-apps/statuses/866942c366f35de39eaaf70a8f12684ad1aa97b2"}}}}