def test_layabout_can_connect_to_slack_with_token(monkeypatch): """ Test that layabout can connect to the Slack API when given a valid Slack API token. """ layabout = Layabout() SlackClient, slack = mock_slack(connections=(True, )) monkeypatch.setattr('layabout.SlackClient', SlackClient) layabout.run(connector=TOKEN, until=lambda e: False) # Verify we instantiated a SlackClient with the given token. SlackClient.assert_called_with(token=TOKEN)
def test_layabout_can_connect_to_slack_with_env_var(monkeypatch): """ Test that layabout can discover and use a Slack API token from an environment variable when not given one directly. """ env_var = EnvVar('_TEST_LAYABOUT_TOKEN') environ = {env_var: TOKEN} layabout = Layabout() SlackClient, slack = mock_slack(connections=(True, )) monkeypatch.setattr(os, 'environ', environ) monkeypatch.setattr('layabout.SlackClient', SlackClient) # Purposefully don't provide a connector so we have to use an env var. layabout.run(connector=env_var, until=lambda e: False) # Verify we instantiated a SlackClient with the given token and used it to # connect to the Slack API. SlackClient.assert_called_with(token=TOKEN)