slack.tests.plugin - Pytest fixtures¶
Slack-sansio provide a pytest plugin with some fixtures to facilitate testing of the slack API.
Installation¶
To load the plugin add the snippet below to your conftest.py.
pytest_plugins = "slack.tests.plugin",
Available fixtures¶
-
slack.tests.plugin.slack_event()¶ Fixture returning data sent by the slack event API.
This fixture can be parametrized to return one or more available event from
slack.tests.data.Eventsandslack.tests.data.Messages.@pytest.mark.parametrize('slack_event', ('channel_deleted', 'simple'), indirect=True) def test_events(slack_event): assert True
To only get
slack.tests.data.Messagesmembers you can parametrize the test that way:@pytest.mark.parametrize("slack_event", {**slack.tests.data.Messages.__members__}, indirect=True) async def test_messages(self, slack_event): assert slack_event["event"]["type"] == "message"
-
slack.tests.plugin.slack_action()¶ Fixture returning data sent by the slack API when using an interactive message or dialog.
This fixture can be parametrized to return one or more available action from
slack.tests.data.InteractiveMessageorslack.tests.data.DialogSubmission.@pytest.mark.parametrize('slack_action', ('button_ok', 'button_cancel'), indirect=True) def test_actions(slack_action): assert True
-
slack.tests.plugin.slack_command()¶ Fixture returning data sent by the slack API when using a slash command.
This fixture can be parametrized to return one or more available command from
slack.tests.data.Commands.@pytest.mark.parametrize('slack_command', ('text', 'no_text'), indirect=True) def test_commands(slack_command): assert True
-
slack.tests.plugin.slack_client()¶ Fixture returning a fake slack client.
- By default the client return to any request:
- status:
200 - body:
{'ok': True} - headers:
{'content-type': 'application/json; charset=utf-8'}
- status:
This can be parametrize with the
_requestparameter.@pytest.mark.asyncio @pytest.mark.parametrize('slack_client', ({'_request': {'body': {'ok': True, 'hello': 'world'}}},), indirect=True) async def test_client(slack_client): data = await slack_client.query(slack.methods.AUTH_TEST) assert data == {'ok': True, 'hello': 'world'}
The
bodyparameter of a request can be a string corresponding to one of the methods available inslack.tests.data.Methods.For multiple requests you can set the
_requestparameter to alist.@pytest.mark.asyncio @pytest.mark.parametrize('slack_client', ({'_request': [ {'body': 'channels'}, {'status': 500} ]},), indirect=True) async def test_client(slack_client): data1 = await slack_client.query(slack.methods.AUTH_TEST) with pytest.raises(slack.exceptions.HTTPException): await slack_client.query(slack.methods.AUTH_TEST)
Available data¶
-
class
slack.tests.data.Events[source]¶ List of available event for testing
- channel_deleted
- pin_added
- reaction_added
-
class
slack.tests.data.Messages[source]¶ List of available message for testing
- simple
- snippet
- shared
- threaded
- bot
- bot_edit
- attachment
- edit
- edit_threaded
- mention
- none_text
- channel_topic
-
class
slack.tests.data.InteractiveMessage[source]¶ List of available interactive message action for testing
- button_ok
- button_cancel