{"action":"created","comment":{"url":"https://api.github.com/repos/zulip/zulip/pulls/comments/78329767","id":78329767,"diff_hunk":"@@ -1988,3 +1988,56 @@ def test_wiki_page_edited_event_message(self):\n             expected_message,\n             HTTP_X_GITLAB_EVENT=\"Wiki Page Hook\"\n         )\n+\n+class LibratoHookTests(WebhookTestCase):\n+    STREAM_NAME = 'librato'\n+    URL_TEMPLATE = u\"/api/v1/external/librato?api_key={api_key}&stream=librato\"\n+    FIXTURE_DIR_NAME = 'librato'\n+    IS_ATTACHMENT = False\n+\n+    def get_body(self, fixture_name):\n+        # type: (text_type) -> text_type\n+        if self.IS_ATTACHMENT:\n+            return self.fixture_data(\"librato\", fixture_name, file_type='json')\n+        return urllib.parse.urlencode({'payload': self.fixture_data(\"librato\", fixture_name, file_type='json')})\n+\n+    def build_webhook_url(self, topic=None):\n+        # type: (Optional[text_type]) -> text_type\n+        api_key = self.get_api_key(self.TEST_USER_EMAIL)\n+        url = self.URL_TEMPLATE.format(stream=self.STREAM_NAME, api_key=api_key)\n+        if topic:\n+            url = u\"{}&topic={}\".format(url, topic)\n+        return url\n+\n+    def test_alert_message_with_default_topic(self):\n+        # type: () -> None\n+        expected_subject = 'Alert alert.name'\n+        expected_message = \"Alert [alert_name](https://metrics.librato.com/alerts#/6294535) has triggered! [Reaction steps](http://www.google.pl)\\n>Metric `librato.cpu.percent.idle`, sum was below 44 by 300s, recorded at 2016-03-31 05:11:42\\n>Metric `librato.swap.swap.cached`, average was absent  by 300s, recorded at 2016-03-31 05:11:42\\n>Metric `librato.swap.swap.cached`, derivative was above 9 by 300s, recorded at 2016-03-31 05:11:42\"\n+        self.send_and_test_stream_message('alert', expected_subject, expected_message, content_type=\"application/x-www-form-urlencoded\")\n+\n+    def test_alert_message_with_custom_topic(self):\n+        # type: () -> None\n+        custom_topic = 'custom_name'\n+        self.url = self.build_webhook_url(custom_topic)\n+        expected_message = \"Alert [alert_name](https://metrics.librato.com/alerts#/6294535) has triggered! [Reaction steps](http://www.google.pl)\\n>Metric `librato.cpu.percent.idle`, sum was below 44 by 300s, recorded at 2016-03-31 05:11:42\\n>Metric `librato.swap.swap.cached`, average was absent  by 300s, recorded at 2016-03-31 05:11:42\\n>Metric `librato.swap.swap.cached`, derivative was above 9 by 300s, recorded at 2016-03-31 05:11:42\"\n+        self.send_and_test_stream_message('alert', custom_topic, expected_message, content_type=\"application/x-www-form-urlencoded\")\n+\n+    def test_three_conditions_alert_message(self):\n+        # type: () -> None\n+        expected_message = \"Alert [alert_name](https://metrics.librato.com/alerts#/6294535) has triggered! [Reaction steps](http://www.use.water.pl)\\n>Metric `collectd.interface.eth0.if_octets.tx`, absolute_value was above 4 by 300s, recorded at 2016-04-11 16:40:14\\n>Metric `collectd.load.load.longterm`, max was above 99, recorded at 2016-04-11 16:40:14\\n>Metric `librato.swap.swap.cached`, average was absent  by 60s, recorded at 2016-04-11 16:40:14\"\n+        expected_subject = 'Alert ToHighTemeprature'\n+        self.send_and_test_stream_message('three_conditions_alert', expected_subject, expected_message, content_type=\"application/x-www-form-urlencoded\")\n+\n+    def test_alert_clear(self):\n+        # type: () -> None\n+        expected_subject = 'Alert Alert_name'\n+        expected_message = \"Alert [alert_name](https://metrics.librato.com/alerts#/6309313) has cleared at 2016-04-12 09:11:44!\"\n+        self.send_and_test_stream_message('alert_cleared', expected_subject, expected_message, content_type=\"application/x-www-form-urlencoded\")\n+\n+    def test_snapshot(self):\n+        # type: () -> None\n+        self.IS_ATTACHMENT = True\n+        expected_subject = 'Snapshots'\n+        expected_message = \"**Hamlet** send a [snapshot](http://snapshots.librato.com/chart/nr5l3n0c-82162.png) of [metric](https://metrics.librato.com/s/spaces/167315/explore/1731491?duration=72039&end_time=1460569409)\"\n+        self.send_and_test_stream_message('snapshot', expected_subject, expected_message, content_type=\"application/x-www-form-urlencoded\")\n+        self.IS_ATTACHMENT = False","path":"zerver/tests/test_hooks.py","position":56,"original_position":56,"commit_id":"7c9b6fc0cfe160c5124a3a5a0e549f4748316643","original_commit_id":"44da91b1fb36982db0459d5881a4046294db8502","user":{"login":"TomaszKolek","id":5993758,"avatar_url":"https://avatars.githubusercontent.com/u/5993758?v=3","gravatar_id":"","url":"https://api.github.com/users/TomaszKolek","html_url":"https://github.com/TomaszKolek","followers_url":"https://api.github.com/users/TomaszKolek/followers","following_url":"https://api.github.com/users/TomaszKolek/following{/other_user}","gists_url":"https://api.github.com/users/TomaszKolek/gists{/gist_id}","starred_url":"https://api.github.com/users/TomaszKolek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomaszKolek/subscriptions","organizations_url":"https://api.github.com/users/TomaszKolek/orgs","repos_url":"https://api.github.com/users/TomaszKolek/repos","events_url":"https://api.github.com/users/TomaszKolek/events{/privacy}","received_events_url":"https://api.github.com/users/TomaszKolek/received_events","type":"User","site_admin":false},"body":"Not exactly in one place - I mean it repeats in a few test classes - it covers one or two special cases per hook lets say.","created_at":"2016-09-12T08:11:18Z","updated_at":"2016-09-12T08:11:18Z","html_url":"https://github.com/zulip/zulip/pull/1749#discussion_r78329767","pull_request_url":"https://api.github.com/repos/zulip/zulip/pulls/1749","_links":{"self":{"href":"https://api.github.com/repos/zulip/zulip/pulls/comments/78329767"},"html":{"href":"https://github.com/zulip/zulip/pull/1749#discussion_r78329767"},"pull_request":{"href":"https://api.github.com/repos/zulip/zulip/pulls/1749"}}},"pull_request":{"url":"https://api.github.com/repos/zulip/zulip/pulls/1749","id":83676950,"html_url":"https://github.com/zulip/zulip/pull/1749","diff_url":"https://github.com/zulip/zulip/pull/1749.diff","patch_url":"https://github.com/zulip/zulip/pull/1749.patch","issue_url":"https://api.github.com/repos/zulip/zulip/issues/1749","number":1749,"state":"open","locked":false,"title":"Add Librato integration","user":{"login":"TomaszKolek","id":5993758,"avatar_url":"https://avatars.githubusercontent.com/u/5993758?v=3","gravatar_id":"","url":"https://api.github.com/users/TomaszKolek","html_url":"https://github.com/TomaszKolek","followers_url":"https://api.github.com/users/TomaszKolek/followers","following_url":"https://api.github.com/users/TomaszKolek/following{/other_user}","gists_url":"https://api.github.com/users/TomaszKolek/gists{/gist_id}","starred_url":"https://api.github.com/users/TomaszKolek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomaszKolek/subscriptions","organizations_url":"https://api.github.com/users/TomaszKolek/orgs","repos_url":"https://api.github.com/users/TomaszKolek/repos","events_url":"https://api.github.com/users/TomaszKolek/events{/privacy}","received_events_url":"https://api.github.com/users/TomaszKolek/received_events","type":"User","site_admin":false},"body":"Because #648 was created really long ago. I copied some code and adjust to new standards","created_at":"2016-09-01T17:49:31Z","updated_at":"2016-09-12T08:11:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"84c3dcefbb92b1fb28b22b1c94613ea59e510818","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/zulip/zulip/pulls/1749/commits","review_comments_url":"https://api.github.com/repos/zulip/zulip/pulls/1749/comments","review_comment_url":"https://api.github.com/repos/zulip/zulip/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zulip/zulip/issues/1749/comments","statuses_url":"https://api.github.com/repos/zulip/zulip/statuses/7c9b6fc0cfe160c5124a3a5a0e549f4748316643","head":{"label":"TomaszKolek:librato-integration","ref":"librato-integration","sha":"7c9b6fc0cfe160c5124a3a5a0e549f4748316643","user":{"login":"TomaszKolek","id":5993758,"avatar_url":"https://avatars.githubusercontent.com/u/5993758?v=3","gravatar_id":"","url":"https://api.github.com/users/TomaszKolek","html_url":"https://github.com/TomaszKolek","followers_url":"https://api.github.com/users/TomaszKolek/followers","following_url":"https://api.github.com/users/TomaszKolek/following{/other_user}","gists_url":"https://api.github.com/users/TomaszKolek/gists{/gist_id}","starred_url":"https://api.github.com/users/TomaszKolek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomaszKolek/subscriptions","organizations_url":"https://api.github.com/users/TomaszKolek/orgs","repos_url":"https://api.github.com/users/TomaszKolek/repos","events_url":"https://api.github.com/users/TomaszKolek/events{/privacy}","received_events_url":"https://api.github.com/users/TomaszKolek/received_events","type":"User","site_admin":false},"repo":{"id":53679793,"name":"zulip","full_name":"TomaszKolek/zulip","owner":{"login":"TomaszKolek","id":5993758,"avatar_url":"https://avatars.githubusercontent.com/u/5993758?v=3","gravatar_id":"","url":"https://api.github.com/users/TomaszKolek","html_url":"https://github.com/TomaszKolek","followers_url":"https://api.github.com/users/TomaszKolek/followers","following_url":"https://api.github.com/users/TomaszKolek/following{/other_user}","gists_url":"https://api.github.com/users/TomaszKolek/gists{/gist_id}","starred_url":"https://api.github.com/users/TomaszKolek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomaszKolek/subscriptions","organizations_url":"https://api.github.com/users/TomaszKolek/orgs","repos_url":"https://api.github.com/users/TomaszKolek/repos","events_url":"https://api.github.com/users/TomaszKolek/events{/privacy}","received_events_url":"https://api.github.com/users/TomaszKolek/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/TomaszKolek/zulip","description":"Zulip server - powerful open source group chat","fork":true,"url":"https://api.github.com/repos/TomaszKolek/zulip","forks_url":"https://api.github.com/repos/TomaszKolek/zulip/forks","keys_url":"https://api.github.com/repos/TomaszKolek/zulip/keys{/key_id}","collaborators_url":"https://api.github.com/repos/TomaszKolek/zulip/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/TomaszKolek/zulip/teams","hooks_url":"https://api.github.com/repos/TomaszKolek/zulip/hooks","issue_events_url":"https://api.github.com/repos/TomaszKolek/zulip/issues/events{/number}","events_url":"https://api.github.com/repos/TomaszKolek/zulip/events","assignees_url":"https://api.github.com/repos/TomaszKolek/zulip/assignees{/user}","branches_url":"https://api.github.com/repos/TomaszKolek/zulip/branches{/branch}","tags_url":"https://api.github.com/repos/TomaszKolek/zulip/tags","blobs_url":"https://api.github.com/repos/TomaszKolek/zulip/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/TomaszKolek/zulip/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/TomaszKolek/zulip/git/refs{/sha}","trees_url":"https://api.github.com/repos/TomaszKolek/zulip/git/trees{/sha}","statuses_url":"https://api.github.com/repos/TomaszKolek/zulip/statuses/{sha}","languages_url":"https://api.github.com/repos/TomaszKolek/zulip/languages","stargazers_url":"https://api.github.com/repos/TomaszKolek/zulip/stargazers","contributors_url":"https://api.github.com/repos/TomaszKolek/zulip/contributors","subscribers_url":"https://api.github.com/repos/TomaszKolek/zulip/subscribers","subscription_url":"https://api.github.com/repos/TomaszKolek/zulip/subscription","commits_url":"https://api.github.com/repos/TomaszKolek/zulip/commits{/sha}","git_commits_url":"https://api.github.com/repos/TomaszKolek/zulip/git/commits{/sha}","comments_url":"https://api.github.com/repos/TomaszKolek/zulip/comments{/number}","issue_comment_url":"https://api.github.com/repos/TomaszKolek/zulip/issues/comments{/number}","contents_url":"https://api.github.com/repos/TomaszKolek/zulip/contents/{+path}","compare_url":"https://api.github.com/repos/TomaszKolek/zulip/compare/{base}...{head}","merges_url":"https://api.github.com/repos/TomaszKolek/zulip/merges","archive_url":"https://api.github.com/repos/TomaszKolek/zulip/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/TomaszKolek/zulip/downloads","issues_url":"https://api.github.com/repos/TomaszKolek/zulip/issues{/number}","pulls_url":"https://api.github.com/repos/TomaszKolek/zulip/pulls{/number}","milestones_url":"https://api.github.com/repos/TomaszKolek/zulip/milestones{/number}","notifications_url":"https://api.github.com/repos/TomaszKolek/zulip/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/TomaszKolek/zulip/labels{/name}","releases_url":"https://api.github.com/repos/TomaszKolek/zulip/releases{/id}","deployments_url":"https://api.github.com/repos/TomaszKolek/zulip/deployments","created_at":"2016-03-11T16:16:19Z","updated_at":"2016-03-11T16:16:26Z","pushed_at":"2016-09-11T22:13:21Z","git_url":"git://github.com/TomaszKolek/zulip.git","ssh_url":"git@github.com:TomaszKolek/zulip.git","clone_url":"https://github.com/TomaszKolek/zulip.git","svn_url":"https://github.com/TomaszKolek/zulip","homepage":"","size":116192,"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":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"zulip:master","ref":"master","sha":"4f091fd844e1c74fe06da2d498f203eeabaaee9c","user":{"login":"zulip","id":4921959,"avatar_url":"https://avatars.githubusercontent.com/u/4921959?v=3","gravatar_id":"","url":"https://api.github.com/users/zulip","html_url":"https://github.com/zulip","followers_url":"https://api.github.com/users/zulip/followers","following_url":"https://api.github.com/users/zulip/following{/other_user}","gists_url":"https://api.github.com/users/zulip/gists{/gist_id}","starred_url":"https://api.github.com/users/zulip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zulip/subscriptions","organizations_url":"https://api.github.com/users/zulip/orgs","repos_url":"https://api.github.com/users/zulip/repos","events_url":"https://api.github.com/users/zulip/events{/privacy}","received_events_url":"https://api.github.com/users/zulip/received_events","type":"Organization","site_admin":false},"repo":{"id":43160685,"name":"zulip","full_name":"zulip/zulip","owner":{"login":"zulip","id":4921959,"avatar_url":"https://avatars.githubusercontent.com/u/4921959?v=3","gravatar_id":"","url":"https://api.github.com/users/zulip","html_url":"https://github.com/zulip","followers_url":"https://api.github.com/users/zulip/followers","following_url":"https://api.github.com/users/zulip/following{/other_user}","gists_url":"https://api.github.com/users/zulip/gists{/gist_id}","starred_url":"https://api.github.com/users/zulip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zulip/subscriptions","organizations_url":"https://api.github.com/users/zulip/orgs","repos_url":"https://api.github.com/users/zulip/repos","events_url":"https://api.github.com/users/zulip/events{/privacy}","received_events_url":"https://api.github.com/users/zulip/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zulip/zulip","description":"Zulip server - powerful open source group chat","fork":false,"url":"https://api.github.com/repos/zulip/zulip","forks_url":"https://api.github.com/repos/zulip/zulip/forks","keys_url":"https://api.github.com/repos/zulip/zulip/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zulip/zulip/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zulip/zulip/teams","hooks_url":"https://api.github.com/repos/zulip/zulip/hooks","issue_events_url":"https://api.github.com/repos/zulip/zulip/issues/events{/number}","events_url":"https://api.github.com/repos/zulip/zulip/events","assignees_url":"https://api.github.com/repos/zulip/zulip/assignees{/user}","branches_url":"https://api.github.com/repos/zulip/zulip/branches{/branch}","tags_url":"https://api.github.com/repos/zulip/zulip/tags","blobs_url":"https://api.github.com/repos/zulip/zulip/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zulip/zulip/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zulip/zulip/git/refs{/sha}","trees_url":"https://api.github.com/repos/zulip/zulip/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zulip/zulip/statuses/{sha}","languages_url":"https://api.github.com/repos/zulip/zulip/languages","stargazers_url":"https://api.github.com/repos/zulip/zulip/stargazers","contributors_url":"https://api.github.com/repos/zulip/zulip/contributors","subscribers_url":"https://api.github.com/repos/zulip/zulip/subscribers","subscription_url":"https://api.github.com/repos/zulip/zulip/subscription","commits_url":"https://api.github.com/repos/zulip/zulip/commits{/sha}","git_commits_url":"https://api.github.com/repos/zulip/zulip/git/commits{/sha}","comments_url":"https://api.github.com/repos/zulip/zulip/comments{/number}","issue_comment_url":"https://api.github.com/repos/zulip/zulip/issues/comments{/number}","contents_url":"https://api.github.com/repos/zulip/zulip/contents/{+path}","compare_url":"https://api.github.com/repos/zulip/zulip/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zulip/zulip/merges","archive_url":"https://api.github.com/repos/zulip/zulip/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zulip/zulip/downloads","issues_url":"https://api.github.com/repos/zulip/zulip/issues{/number}","pulls_url":"https://api.github.com/repos/zulip/zulip/pulls{/number}","milestones_url":"https://api.github.com/repos/zulip/zulip/milestones{/number}","notifications_url":"https://api.github.com/repos/zulip/zulip/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zulip/zulip/labels{/name}","releases_url":"https://api.github.com/repos/zulip/zulip/releases{/id}","deployments_url":"https://api.github.com/repos/zulip/zulip/deployments","created_at":"2015-09-25T16:37:25Z","updated_at":"2016-09-11T14:40:52Z","pushed_at":"2016-09-12T06:53:50Z","git_url":"git://github.com/zulip/zulip.git","ssh_url":"git@github.com:zulip/zulip.git","clone_url":"https://github.com/zulip/zulip.git","svn_url":"https://github.com/zulip/zulip","homepage":"","size":123145,"stargazers_count":4038,"watchers_count":4038,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":674,"mirror_url":null,"open_issues_count":546,"forks":674,"open_issues":546,"watchers":4038,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zulip/zulip/pulls/1749"},"html":{"href":"https://github.com/zulip/zulip/pull/1749"},"issue":{"href":"https://api.github.com/repos/zulip/zulip/issues/1749"},"comments":{"href":"https://api.github.com/repos/zulip/zulip/issues/1749/comments"},"review_comments":{"href":"https://api.github.com/repos/zulip/zulip/pulls/1749/comments"},"review_comment":{"href":"https://api.github.com/repos/zulip/zulip/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zulip/zulip/pulls/1749/commits"},"statuses":{"href":"https://api.github.com/repos/zulip/zulip/statuses/7c9b6fc0cfe160c5124a3a5a0e549f4748316643"}}}}
{"actor":{"display_login":"TomaszKolek"}}