-
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
1 parent
1b45e44
commit d20b88c
Showing
7 changed files
with
73 additions
and
37 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
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
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,25 +1,46 @@ | ||
from unittest.mock import AsyncMock | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
|
||
from lotb.common.config import Config | ||
from lotb.plugins.welcome import Plugin | ||
|
||
|
||
@pytest.fixture | ||
def mock_config(): | ||
config = MagicMock(spec=Config) | ||
config.get.side_effect = lambda key, default=None: { | ||
"core.database": "/tmp/test.db", | ||
"plugins.welcome": {"enabled": "true"}, | ||
}.get(key, default) | ||
return config | ||
|
||
|
||
@pytest.fixture | ||
def mock_update(mock_update): | ||
update = mock_update | ||
update.message.text = "/welcome What is dead may never die" | ||
return update | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_welcome_plugin(mock_update, mock_context): | ||
@pytest.fixture | ||
def welcome_plugin(mock_config): | ||
plugin = Plugin() | ||
await plugin.execute(mock_update, mock_context) | ||
plugin.set_config(mock_config) | ||
plugin.initialize() | ||
plugin.reply_message = AsyncMock() | ||
return plugin | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_welcome_plugin(mock_update, mock_context, welcome_plugin): | ||
await welcome_plugin.execute(mock_update, mock_context) | ||
mock_update.message.reply_text.assert_called_once_with("Welcome: What is dead may never die", quote=True) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_welcome_plugin_no_message(mock_update, mock_context): | ||
plugin = Plugin() | ||
async def test_welcome_plugin_no_message(mock_update, mock_context, welcome_plugin): | ||
mock_update.message.text = "/welcome" | ||
await plugin.execute(mock_update, mock_context) | ||
await welcome_plugin.execute(mock_update, mock_context) | ||
mock_update.message.reply_text.assert_called_once_with("Welcome!", quote=True) |