Skip to content
This repository has been archived by the owner on Feb 23, 2020. It is now read-only.

Commit

Permalink
Merge pull request #16 from reillysiemens/rename-exception
Browse files Browse the repository at this point in the history
  • Loading branch information
reillysiemens committed Jun 18, 2018
2 parents 9247950 + 8daafcd commit fd5e6fb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Exceptions
.. autoexception:: layabout.LayaboutError
:show-inheritance:

.. autoexception:: layabout.MissingSlackToken
.. autoexception:: layabout.MissingToken
:show-inheritance:

.. autoexception:: layabout.FailedConnection
Expand Down
8 changes: 4 additions & 4 deletions layabout.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class LayaboutError(Exception):
""" Base error for all Layabout exceptions. """


class MissingSlackToken(LayaboutError):
class MissingToken(LayaboutError):
""" Raised if a Slack API token could not be found. """


Expand Down Expand Up @@ -222,7 +222,7 @@ def run(self, *,
Raises:
TypeError: If an unsupported connector is given.
MissingSlackToken: If no API token is available.
MissingToken: If no API token is available.
FailedConnection: If connecting to the Slack API fails.
.. _truncated exponential backoff:
Expand Down Expand Up @@ -300,15 +300,15 @@ def _create_slack_with_env_var(env_var: EnvVar) -> SlackClient:
token = os.getenv(env_var)
if token:
return SlackClient(token=token)
raise MissingSlackToken(f"Could not acquire token from {env_var}")
raise MissingToken(f"Could not acquire token from {env_var}")


@_create_slack.register(Token)
def _create_slack_with_token(token: Token) -> SlackClient:
""" Create a :obj:`SlackClient` with a provided token. """
if token != Token(''):
return SlackClient(token=token)
raise MissingSlackToken("The empty string is an invalid Slack API token")
raise MissingToken("The empty string is an invalid Slack API token")


@_create_slack.register(SlackClient)
Expand Down
17 changes: 8 additions & 9 deletions tests/test_layabout.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
EnvVar,
FailedConnection,
Layabout,
MissingSlackToken,
MissingToken,
Token,
_SlackClientWrapper,
_truncated_exponential,
Expand Down Expand Up @@ -252,31 +252,30 @@ def test_layabout_raises_type_error_with_string_connector():
'instead of str')


def test_layabout_raises_missing_slack_token_without_token(monkeypatch):
def test_layabout_raises_missing_token_without_token(monkeypatch):
"""
Test that layabout raises a MissingSlackToken if there is no Slack API
token for it to use.
Test that layabout raises a MissingToken if there is no Slack API token for
it to use.
"""
environ = dict()
layabout = Layabout()

monkeypatch.setattr(os, 'environ', environ)

with pytest.raises(MissingSlackToken) as exc:
with pytest.raises(MissingToken) as exc:
# until will exit early here just to be safe.
layabout.run(until=lambda e: False)

assert str(exc.value) == 'Could not acquire token from LAYABOUT_TOKEN'


def test_layabout_raises_missing_slack_token_with_empty_token():
def test_layabout_raises_missing_token_with_empty_token():
"""
Test that layabout raises a MissingSlackToken if given an empty Slack API
token.
Test that layabout raises a MissingToken if given an empty Slack API token.
"""
layabout = Layabout()

with pytest.raises(MissingSlackToken) as exc:
with pytest.raises(MissingToken) as exc:
# until will exit early here just to be safe.
layabout.run(connector=Token(''), until=lambda e: False)

Expand Down

0 comments on commit fd5e6fb

Please sign in to comment.