diff --git a/pyslack/__init__.py b/pyslack/__init__.py index a67d32f..2736402 100644 --- a/pyslack/__init__.py +++ b/pyslack/__init__.py @@ -27,8 +27,8 @@ def _make_request(self, method, params): """ if self.blocked_until is not None and \ datetime.datetime.utcnow() < self.blocked_until: - raise SlackError("Too many requests - wait until {0}" \ - .format(self.blocked_until)) + raise SlackError("Too many requests - wait until {0}" + .format(self.blocked_until)) url = "%s/%s" % (SlackClient.BASE_URL, method) params['token'] = self.token @@ -38,9 +38,9 @@ def _make_request(self, method, params): # Too many requests retry_after = int(response.headers.get('retry-after', '1')) self.blocked_until = datetime.datetime.utcnow() + \ - datetime.timedelta(seconds=retry_after) - raise SlackError("Too many requests - retry after {0} second(s)" \ - .format(retry_after)) + datetime.timedelta(seconds=retry_after) + raise SlackError("Too many requests - retry after {0} second(s)" + .format(retry_after)) result = response.json() if not result['ok']: @@ -109,11 +109,13 @@ def chat_update_message(self, channel, text, timestamp, **params): class SlackHandler(logging.Handler): + """A logging handler that posts messages to a Slack channel! References: http://docs.python.org/2/library/logging.html#handler-objects """ + def __init__(self, token, channel, **kwargs): super(SlackHandler, self).__init__() self.client = SlackClient(token) diff --git a/tests/client.py b/tests/client.py index 10e17f9..d2c7862 100644 --- a/tests/client.py +++ b/tests/client.py @@ -17,7 +17,7 @@ def test_post_message(self, r_post): client = pyslack.SlackClient(self.token) reply = {"ok": True} - r_post.return_value.json = Mock(return_value = reply) + r_post.return_value.json = Mock(return_value=reply) result = client.chat_post_message('#channel', 'message') self.assertEqual(reply, result) @@ -48,8 +48,8 @@ def test_rate_limit(self, r_post): client.chat_post_message('#channel', 'message') self.assertEqual(r_post.call_count, 1) - self.assertGreater(client.blocked_until, - datetime.datetime.utcnow() + datetime.timedelta(seconds=8)) + self.assertGreater(client.blocked_until, + datetime.datetime.utcnow() + datetime.timedelta(seconds=8)) # A second send attempt should also throw, but without creating a request with self.assertRaises(pyslack.SlackError) as context: @@ -59,11 +59,10 @@ def test_rate_limit(self, r_post): # After the time has expired, it should be business as usual client.blocked_until = datetime.datetime.utcnow() - \ - datetime.timedelta(seconds=5) + datetime.timedelta(seconds=5) r_post.return_value = Mock(status_code=200) r_post.return_value.json.return_value = {"ok": True} client.chat_post_message('#channel', 'message') self.assertEqual(r_post.call_count, 2) - diff --git a/tests/handler.py b/tests/handler.py index 18d299d..5264b10 100644 --- a/tests/handler.py +++ b/tests/handler.py @@ -26,7 +26,6 @@ def test_post_message(self, client_chatpostmessage): logger.error("Oh noh!") client_chatpostmessage.assert_called_with( - '#channel', - '[ERROR] Oh noh!', - username='botname') - + '#channel', + '[ERROR] Oh noh!', + username='botname')