slack-bolt-testcase
A simple unittest TestCase class to use it in your Slack Bolt App unittest tests
Introduction
The Slack bolt library and the Slack SDK for Python are the best and official ways of implementing Slack bots in Python. However, there is a small piece missing there: no official documentation about how to do tests with the standard unittest library that allow developers to test that they have registered their handlers correctly. slack-bolt-testcase fixes that.
Requirements
- Python >= 3.9
- slack_bolt~=1.23.0
- slack_sdk~=3.35.0
Use
To use this TestCase, you just need to inherit from EventTestCase and make sure you have registered your event handlers in the AppTestCase.app.
from unittest.mock import call
from slack_bolt import Say
from slack_bolt_testcase.event_test_case import EventTestCase
# Inherit from the EventTestCase
class TestEventExample(EventTestCase):
def test_handled_event(self):
# Make sure you have registered your events in a way with the self.app mocked Slack App object
# you can do it here or pass the self.app object to a register function.
@self.app.event('app_mention')
def handle_message_events(event: dict[str, str], say: Say):
# Ensure we are receiving the right text
if event.get('text') == 'hello':
event_type = event.get('type')
say(f'Hello the handler handled a(n) {event_type}!')
# Trigger the event
self.trigger_event(event_type='app_mention', text='hello', user='U12345')
# Check the assertions
self.assertEqual(
[call(f'Hello the handler handled a(n) app_mention!')],
self.mock_say.call_args_list,
)
More examples in the tests folder.
License
Disclaimer
Slack is a trademark of Slack Technologies, LLC. This project is not affiliated with, endorsed by, or sponsored by Slack Technologies, LLC. The use of the name "Slack" in this repository is solely for descriptive purposes and does not imply any association or intent to infringe on any trademarks.
Metadata
Release files for slack-bolt-testcase 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| slack_bolt_testcase-0.0.2.tar.gz | 6.8 kB | Details |
Release files / slack_bolt_testcase-0.0.2.tar.gz
| Download URL | slack_bolt_testcase-0.0.2.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6f1af1b296f7b792bb8a6446d4fb48359af09871340482b630294028fd42e1f6
|
|
BLAKE2b-256 checksum How to use checksums |
d6ef73d9f30c4d7ddd9861aa9ddf6d09a2a4cc5a298b6c736396320c0f046fc4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|