This repository has been archived by the owner on Jun 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfixes for Action & ActionRouter + testing
- Loading branch information
Showing
8 changed files
with
236 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Version information | ||
|
||
__version__ = '0.3.0' | ||
__version__ = '0.3.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from . import events, methods # noQa | ||
from . import events, methods, actions # noQa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import json | ||
|
||
button_ok = { | ||
'type': 'interactive_message', | ||
'actions': [ | ||
{ | ||
'name': 'ok', | ||
'type': 'button', | ||
'value': 'hello' | ||
} | ||
], | ||
'callback_id': 'test_action', | ||
'team': { | ||
'id': 'T000AAA0A', | ||
'domain': 'team' | ||
}, | ||
'channel': { | ||
'id': 'C00000A00', | ||
'name': 'general' | ||
}, | ||
'user': { | ||
'id': 'U000AA000', | ||
'name': 'username' | ||
}, | ||
'action_ts': '987654321.000001', | ||
'message_ts': '123456789.000001', | ||
'attachment_id': '1', | ||
'token': 'supersecuretoken', | ||
'is_app_unfurl': False, | ||
'response_url': 'https://hooks.slack.com/actions/T000AAA0A/123456789123/YTC81HsJRuuGSLVFbSnlkJlh', | ||
'trigger_id': '000000000.0000000000.e1bb750705a2f472e4476c4228cf4784' | ||
} | ||
|
||
button_cancel = { | ||
'type': 'interactive_message', | ||
'actions': [ | ||
{ | ||
'name': 'cancel', | ||
'type': 'button', | ||
'value': 'hello' | ||
} | ||
], | ||
'callback_id': 'test_action', | ||
'team': { | ||
'id': 'T000AAA0A', | ||
'domain': 'team' | ||
}, | ||
'channel': { | ||
'id': 'C00000A00', | ||
'name': 'general' | ||
}, | ||
'user': { | ||
'id': 'U000AA000', | ||
'name': 'username' | ||
}, | ||
'action_ts': '987654321.000001', | ||
'message_ts': '123456789.000001', | ||
'attachment_id': '1', | ||
'token': 'supersecuretoken', | ||
'is_app_unfurl': False, | ||
'response_url': 'https://hooks.slack.com/actions/T000AAA0A/123456789123/YTC81HsJRuuGSLVFbSnlkJlh', | ||
'trigger_id': '000000000.0000000000.e1bb750705a2f472e4476c4228cf4784' | ||
} | ||
|
||
raw_button_ok = {'payload': json.dumps(button_ok)} | ||
raw_button_cancel = {'payload': json.dumps(button_cancel)} | ||
|
||
actions = { | ||
'button_ok': raw_button_ok, | ||
'button_cancel': raw_button_cancel | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import slack | ||
import pytest | ||
|
||
|
||
class TestActions: | ||
def test_from_http(self, action): | ||
assert isinstance(action, slack.actions.Action) | ||
|
||
def test_parsing_token(self, raw_action): | ||
slack.actions.Action.from_http(raw_action, verification_token='supersecuretoken') | ||
|
||
def test_parsing_team_id(self, raw_action): | ||
slack.actions.Action.from_http(raw_action, team_id='T000AAA0A') | ||
|
||
def test_parsing_wrong_token(self, raw_action): | ||
with pytest.raises(slack.exceptions.FailedVerification): | ||
slack.actions.Action.from_http(raw_action, verification_token='xxx') | ||
|
||
def test_parsing_wrong_team_id(self, raw_action): | ||
with pytest.raises(slack.exceptions.FailedVerification): | ||
slack.actions.Action.from_http(raw_action, team_id='xxx') | ||
|
||
|
||
class TestActionRouter: | ||
def test_register(self, action_router): | ||
def handler(): | ||
pass | ||
|
||
action_router.register('test_action', handler) | ||
assert len(action_router._routes['test_action']['*']) == 1 | ||
assert action_router._routes['test_action']['*'][0] is handler | ||
|
||
def test_register_name(self, action_router): | ||
def handler(): | ||
pass | ||
|
||
action_router.register('test_action', handler, name='aaa') | ||
assert len(action_router._routes['test_action']['aaa']) == 1 | ||
assert action_router._routes['test_action']['aaa'][0] is handler | ||
|
||
def test_multiple_register(self, action_router): | ||
def handler(): | ||
pass | ||
|
||
def handler_bis(): | ||
pass | ||
|
||
action_router.register('test_action', handler) | ||
action_router.register('test_action', handler_bis) | ||
assert len(action_router._routes['test_action']['*']) == 2 | ||
assert action_router._routes['test_action']['*'][0] is handler | ||
assert action_router._routes['test_action']['*'][1] is handler_bis | ||
|
||
def test_dispath(self, action, action_router): | ||
def handler(): | ||
pass | ||
|
||
handlers = list() | ||
action_router.register('test_action', handler) | ||
|
||
for h in action_router.dispatch(action): | ||
handlers.append(h) | ||
assert len(handlers) == 1 | ||
assert handlers[0] is handler | ||
|
||
def test_no_dispatch(self, action, action_router): | ||
def handler(): | ||
pass | ||
|
||
action_router.register('xxx', handler) | ||
for h in action_router.dispatch(action): | ||
assert False | ||
|
||
def test_dispatch_details(self, action, action_router): | ||
def handler(): | ||
pass | ||
|
||
handlers = list() | ||
action_router.register('test_action', handler, name='ok') | ||
action_router.register('test_action', handler, name='cancel') | ||
|
||
for h in action_router.dispatch(action): | ||
handlers.append(h) | ||
assert len(handlers) == 1 | ||
assert handlers[0] is handler | ||
|
||
def test_multiple_dispatch(self, action, action_router): | ||
def handler(): | ||
pass | ||
|
||
def handler_bis(): | ||
pass | ||
|
||
handlers = list() | ||
action_router.register('test_action', handler) | ||
action_router.register('test_action', handler_bis) | ||
|
||
for h in action_router.dispatch(action): | ||
handlers.append(h) | ||
|
||
assert len(handlers) == 2 | ||
assert handlers[0] is handler | ||
assert handlers[1] is handler_bis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters