-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,12 +1,57 @@ | ||
from unittest.mock import patch, DEFAULT, MagicMock, call | ||
from typing import List | ||
|
||
from dm_mac import main | ||
|
||
|
||
class TestMain: | ||
|
||
def test_happy_path_no_slack(self): | ||
# patch sys.argv | ||
# patch set_log_debug and _info | ||
# patch asyncio.get_event_loop | ||
# patch create_app() | ||
# patch ... all the slack stuff | ||
pass | ||
@patch('sys.argv', ['mac-server']) | ||
@patch.dict('os.environ', {'SLACK_APP_TOKEN': 'app-token'}) | ||
def test_with_slack(self): | ||
mocks: List[MagicMock] | ||
with patch.multiple( | ||
'dm_mac', | ||
set_log_debug=DEFAULT, | ||
set_log_info=DEFAULT, | ||
get_event_loop=DEFAULT, | ||
SlackHandler=DEFAULT, | ||
AsyncSocketModeHandler=DEFAULT, | ||
logger=DEFAULT, | ||
create_app=DEFAULT, | ||
new_callable=MagicMock | ||
) as mocks: | ||
slack_app = MagicMock() | ||
type(mocks['SlackHandler']).app = slack_app | ||
loop = MagicMock() | ||
app = MagicMock() | ||
handler = MagicMock() | ||
mocks['get_event_loop'].return_value = loop | ||
mocks['create_app'].return_value = app | ||
mocks['AsyncSocketModeHandler'].return_value = handler | ||
main() | ||
assert mocks['set_log_debug'].mock_calls == [] | ||
assert mocks['set_log_info'].mock_calls == [call(mocks['logger'])] | ||
assert mocks['create_app'].mock_calls == [ | ||
call(), | ||
call().config.update({ | ||
'SLACK_HANDLER': mocks['SlackHandler'].return_value | ||
}), | ||
call().run(loop=loop, debug=False, host='0.0.0.0') | ||
] | ||
assert app.mock_calls == [ | ||
call.config.update({ | ||
'SLACK_HANDLER': mocks['SlackHandler'].return_value | ||
}), | ||
call.run(loop=loop, debug=False, host='0.0.0.0') | ||
] | ||
assert mocks['SlackHandler'].mock_calls == [call(app)] | ||
assert mocks['AsyncSocketModeHandler'].mock_calls == [ | ||
call(slack_app, 'app-token', loop=loop) | ||
] | ||
assert loop.mock_calls == [ | ||
call.create_task(handler.start_async()) | ||
] | ||
assert app.mock_calls == [ | ||
call.run(loop=loop, debug=False, host="0.0.0.0") | ||
] |