-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add more tests for async Machine class
- Loading branch information
1 parent
65605c8
commit 7fc5a7f
Showing
3 changed files
with
78 additions
and
32 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
PLUGINS = ["tests.asyncio.fake_plugins"] | ||
SLACK_BOT_TOKEN = "xoxb-abc123" | ||
SLACK_APP_TOKEN = "xapp-abc123" | ||
STORAGE_BACKEND = "machine.asyncio.storage.backends.memory.MemoryStorage" |
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,40 @@ | ||
import pytest | ||
|
||
from machine.asyncio import Machine | ||
from machine.asyncio.storage.backends.memory import MemoryStorage | ||
|
||
|
||
@pytest.fixture | ||
def socket_mode_client(mocker): | ||
socket_mode_client = mocker.patch("machine.asyncio.core.SocketModeClient", autospec=True) | ||
socket_mode_client.return_value.socket_mode_request_listeners = [] | ||
return socket_mode_client | ||
|
||
|
||
@pytest.fixture | ||
def slack_client(mocker): | ||
socket_mode_client = mocker.patch("machine.asyncio.core.SlackClient", autospec=True) | ||
socket_mode_client.return_value.socket_mode_request_listeners = [] | ||
return slack_client | ||
|
||
|
||
@pytest.fixture | ||
def os_environ(mocker): | ||
os_environ = mocker.patch( | ||
"machine.asyncio.core.os.environ", new={"SM_SETTINGS_MODULE": "tests.asyncio.local_test_settings"} | ||
) | ||
return os_environ | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_setup(os_environ, socket_mode_client, slack_client): | ||
m = Machine() | ||
assert m._settings is None | ||
await m._setup() | ||
assert m._settings is not None | ||
assert m._settings["PLUGINS"] == ["tests.asyncio.fake_plugins"] | ||
assert m._settings["SLACK_BOT_TOKEN"] == "xoxb-abc123" | ||
assert m._settings["SLACK_APP_TOKEN"] == "xapp-abc123" | ||
assert m._settings["STORAGE_BACKEND"] == "machine.asyncio.storage.backends.memory.MemoryStorage" | ||
assert isinstance(m._storage_backend, MemoryStorage) | ||
assert "manual" in m._storage_backend._storage |