Fix Context initialization in tests
This commit is contained in:
@@ -6,9 +6,8 @@ from _pytest.fixtures import FixtureRequest
|
||||
from pytest_mock import MockFixture
|
||||
|
||||
import mautrix_telegram.commands.handler
|
||||
from mautrix_telegram.commands.handler import (
|
||||
CommandEvent, CommandHandler, CommandProcessor, HelpSection
|
||||
)
|
||||
from mautrix_telegram.commands.handler import (CommandEvent, CommandHandler, CommandProcessor,
|
||||
HelpSection)
|
||||
from mautrix_telegram.config import Config
|
||||
from mautrix_telegram.context import Context
|
||||
from mautrix_telegram.types import MatrixEventID, MatrixRoomID, MatrixUserID
|
||||
@@ -25,13 +24,7 @@ def context(request: FixtureRequest) -> Context:
|
||||
"""
|
||||
# Config(path, registration_path, base_path)
|
||||
config = getattr(request.cls, 'config', Config("", "", ""))
|
||||
return Context(
|
||||
Mock(), # az
|
||||
Mock(), # db
|
||||
config, # config
|
||||
Mock(), # loop
|
||||
Mock() # session_container
|
||||
)
|
||||
return Context(az=Mock(), config=config, loop=Mock(), session_container=Mock(), bot=Mock())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -97,15 +90,12 @@ class TestCommandEvent:
|
||||
mock_az.intent.send_notice.assert_called_with(
|
||||
MatrixRoomID("#mock_room:example.org"),
|
||||
"**This** <i>was</i><br/><strong>all</strong>fun*!",
|
||||
html=(
|
||||
"<p><strong>This</strong> <i>was</i><br/>"
|
||||
"<strong>all</strong>fun*!</p>\n"
|
||||
),
|
||||
html="<p><strong>This</strong> <i>was</i><br/>"
|
||||
"<strong>all</strong>fun*!</p>\n"
|
||||
)
|
||||
|
||||
def test_reply_with_cmdprefix(
|
||||
self, command_processor: CommandProcessor, mocker: MockFixture
|
||||
) -> None:
|
||||
def test_reply_with_cmdprefix(self, command_processor: CommandProcessor, mocker: MockFixture
|
||||
) -> None:
|
||||
mocker.patch("mautrix_telegram.user.config", self.config)
|
||||
|
||||
evt = CommandEvent(
|
||||
@@ -121,11 +111,8 @@ class TestCommandEvent:
|
||||
|
||||
mock_az = command_processor.az
|
||||
|
||||
evt.reply(
|
||||
"$cmdprefix+sp ....$cmdprefix+sp...$cmdprefix $cmdprefix",
|
||||
allow_html=False,
|
||||
render_markdown=False,
|
||||
)
|
||||
evt.reply("$cmdprefix+sp ....$cmdprefix+sp...$cmdprefix $cmdprefix", allow_html=False,
|
||||
render_markdown=False)
|
||||
|
||||
mock_az.intent.send_notice.assert_called_with(
|
||||
MatrixRoomID("#mock_room:example.org"),
|
||||
@@ -133,9 +120,8 @@ class TestCommandEvent:
|
||||
html=None,
|
||||
)
|
||||
|
||||
def test_reply_with_cmdprefix_in_management_room(
|
||||
self, command_processor: CommandProcessor, mocker: MockFixture
|
||||
) -> None:
|
||||
def test_reply_with_cmdprefix_in_management_room(self, command_processor: CommandProcessor,
|
||||
mocker: MockFixture) -> None:
|
||||
mocker.patch("mautrix_telegram.user.config", self.config)
|
||||
|
||||
evt = CommandEvent(
|
||||
@@ -163,6 +149,7 @@ class TestCommandEvent:
|
||||
html="<p>....tg+sp...tg tg</p>\n",
|
||||
)
|
||||
|
||||
|
||||
class TestCommandHandler:
|
||||
config = Config("", "", "")
|
||||
config["bridge.permissions"] = {"*": "noperm"}
|
||||
@@ -301,12 +288,8 @@ class TestCommandProcessor:
|
||||
config["bridge.permissions"] = {"*": "relaybot"}
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle(
|
||||
self,
|
||||
command_processor: CommandProcessor,
|
||||
boolean2: Tuple[bool, bool],
|
||||
mocker: MockFixture,
|
||||
) -> None:
|
||||
async def test_handle(self, command_processor: CommandProcessor, boolean2: Tuple[bool, bool],
|
||||
mocker: MockFixture) -> None:
|
||||
mocker.patch('mautrix_telegram.user.config', self.config)
|
||||
mocker.patch(
|
||||
'mautrix_telegram.commands.handler.command_handlers',
|
||||
@@ -330,12 +313,8 @@ class TestCommandProcessor:
|
||||
command_handlers["help"].mock.assert_called_once() # type: ignore
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_unknown_command(
|
||||
self,
|
||||
command_processor: CommandProcessor,
|
||||
boolean2: Tuple[bool, bool],
|
||||
mocker: MockFixture,
|
||||
) -> None:
|
||||
async def test_handle_unknown_command(self, command_processor: CommandProcessor,
|
||||
boolean2: Tuple[bool, bool], mocker: MockFixture) -> None:
|
||||
mocker.patch('mautrix_telegram.user.config', self.config)
|
||||
mocker.patch(
|
||||
'mautrix_telegram.commands.handler.command_handlers',
|
||||
@@ -361,12 +340,9 @@ class TestCommandProcessor:
|
||||
command_handlers["unknown-command"].mock.assert_called_once() # type: ignore
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_delegated_handler(
|
||||
self,
|
||||
command_processor: CommandProcessor,
|
||||
boolean2: Tuple[bool, bool],
|
||||
mocker: MockFixture,
|
||||
) -> None:
|
||||
async def test_handle_delegated_handler(self, command_processor: CommandProcessor,
|
||||
boolean2: Tuple[bool, bool],
|
||||
mocker: MockFixture) -> None:
|
||||
mocker.patch('mautrix_telegram.user.config', self.config)
|
||||
mocker.patch(
|
||||
'mautrix_telegram.commands.handler.command_handlers',
|
||||
|
||||
@@ -12,19 +12,16 @@ def boolean(request: FixtureRequest) -> bool:
|
||||
|
||||
@pytest.fixture
|
||||
def boolean1(boolean: bool) -> Tuple[bool]:
|
||||
return (boolean,)
|
||||
return boolean,
|
||||
|
||||
|
||||
@pytest.fixture(params=[True, False])
|
||||
def boolean2(request: FixtureRequest, boolean: bool) -> Tuple[bool, bool]:
|
||||
return (boolean, request.param)
|
||||
return boolean, request.param
|
||||
|
||||
|
||||
@pytest.fixture(params=[True, False])
|
||||
def boolean3(
|
||||
request: FixtureRequest, boolean2: Tuple[bool, bool]
|
||||
) -> Tuple[bool, bool, bool]:
|
||||
return (boolean2[0], boolean2[1], request.param)
|
||||
|
||||
def boolean3(request: FixtureRequest, boolean2: Tuple[bool, bool]) -> Tuple[bool, bool, bool]:
|
||||
return boolean2[0], boolean2[1], request.param
|
||||
|
||||
# …
|
||||
|
||||
Reference in New Issue
Block a user