Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pyslack/):pep8 formatting added #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions pyslack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']:
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions tests/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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)

7 changes: 3 additions & 4 deletions tests/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')