Skip to content

Commit

Permalink
WIP coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Nov 27, 2024
1 parent 681bf12 commit 6280394
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .idea/machine-access-control.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/dm_mac/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Decatur Makers Machine Access Control."""

import argparse
import asyncio
from asyncio import AbstractEventLoop, get_event_loop
import logging
import os
import sys
Expand Down Expand Up @@ -101,7 +101,7 @@ def main() -> None:
set_log_debug(logger)
else:
set_log_info(logger)
loop: asyncio.AbstractEventLoop = asyncio.get_event_loop()
loop: AbstractEventLoop = get_event_loop()
app = create_app()
if "SLACK_APP_TOKEN" in os.environ:
slack: SlackHandler = SlackHandler(app)
Expand Down
59 changes: 52 additions & 7 deletions tests/test_init.py
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")
]

0 comments on commit 6280394

Please sign in to comment.