moved RelayPlugin initialization to fixture

This commit is contained in:
missytake 2023-10-08 08:19:57 +02:00
parent e5f7a8891e
commit dde8ee1343
2 changed files with 30 additions and 25 deletions

View file

@ -5,6 +5,8 @@ import deltachat
import pytest import pytest
from _pytest.pytester import LineMatcher from _pytest.pytester import LineMatcher
from teams_bot.bot import RelayPlugin
class ClickRunner: class ClickRunner:
def __init__(self, main): def __init__(self, main):
@ -75,6 +77,14 @@ def tmp_file_path(request, tmpdir):
return path return path
@pytest.fixture
def relaycrew(crew):
crew.bot.relayplugin = RelayPlugin(crew.bot)
crew.bot.add_account_plugin(crew.bot.relayplugin)
assert not crew.bot.relayplugin.is_relay_group(crew)
yield crew
@pytest.fixture @pytest.fixture
def crew(teams_bot, teams_user): def crew(teams_bot, teams_user):
from teams_bot.bot import SetupPlugin from teams_bot.bot import SetupPlugin

View file

@ -1,53 +1,48 @@
from teams_bot.bot import RelayPlugin
from teams_bot.commands import get_crew_id from teams_bot.commands import get_crew_id
def test_is_relay_group(crew, outsider): def test_is_relay_group(relaycrew, outsider):
crew.bot.relayplugin = RelayPlugin(crew.bot) botcontact_outsider = outsider.create_contact(relaycrew.bot.get_config("addr"))
crew.bot.add_account_plugin(crew.bot.relayplugin)
assert not crew.bot.relayplugin.is_relay_group(crew)
botcontact_outsider = outsider.create_contact(crew.bot.get_config("addr"))
outsider_to_bot = outsider.create_chat(botcontact_outsider) outsider_to_bot = outsider.create_chat(botcontact_outsider)
outsider_to_bot.send_text("test message to bot") outsider_to_bot.send_text("test message to bot")
message_from_outsider = crew.bot.wait_next_incoming_message() message_from_outsider = relaycrew.bot.wait_next_incoming_message()
assert not crew.bot.relayplugin.is_relay_group(message_from_outsider.chat) assert not relaycrew.bot.relayplugin.is_relay_group(message_from_outsider.chat)
crew.user.wait_next_incoming_message() # group added message relaycrew.user.wait_next_incoming_message() # group added message
forwarded_message_from_outsider = crew.user.wait_next_incoming_message() forwarded_message_from_outsider = relaycrew.user.wait_next_incoming_message()
user_relay_group = forwarded_message_from_outsider.create_chat() user_relay_group = forwarded_message_from_outsider.create_chat()
user_relay_group.send_text("Harmless reply in relay group") user_relay_group.send_text("Harmless reply in relay group")
message_in_relay_group = crew.bot.wait_next_incoming_message() message_in_relay_group = relaycrew.bot.wait_next_incoming_message()
assert message_in_relay_group.chat.get_name().startswith( assert message_in_relay_group.chat.get_name().startswith(
"[%s] " % (crew.bot.get_config("addr").split("@")[0],) "[%s] " % (relaycrew.bot.get_config("addr").split("@")[0],)
) )
assert ( assert (
message_in_relay_group.chat.get_messages()[0].get_sender_contact() message_in_relay_group.chat.get_messages()[0].get_sender_contact()
== crew.bot.get_self_contact() == relaycrew.bot.get_self_contact()
) )
assert not message_in_relay_group.chat.is_protected() assert not message_in_relay_group.chat.is_protected()
assert ( assert (
crew.bot.get_chat_by_id(get_crew_id(crew.bot)).get_contacts() relaycrew.bot.get_chat_by_id(get_crew_id(relaycrew.bot)).get_contacts()
== message_in_relay_group.chat.get_contacts() == message_in_relay_group.chat.get_contacts()
) )
assert crew.bot.relayplugin.is_relay_group(message_in_relay_group.chat) assert relaycrew.bot.relayplugin.is_relay_group(message_in_relay_group.chat)
outsider_to_bot = outsider.create_group_chat( outsider_to_bot = outsider.create_group_chat(
"test with outsider", contacts=[botcontact_outsider] "test with outsider", contacts=[botcontact_outsider]
) )
outsider_to_bot.send_text("test message to outsider group") outsider_to_bot.send_text("test message to outsider group")
message_from_outsider = crew.bot.wait_next_incoming_message() message_from_outsider = relaycrew.bot.wait_next_incoming_message()
assert not crew.bot.relayplugin.is_relay_group(message_from_outsider.chat) assert not relaycrew.bot.relayplugin.is_relay_group(message_from_outsider.chat)
botcontact_user = crew.user.create_contact(crew.bot.get_config("addr")) botcontact_user = relaycrew.user.create_contact(relaycrew.bot.get_config("addr"))
user_to_bot = crew.user.create_chat(botcontact_user) user_to_bot = relaycrew.user.create_chat(botcontact_user)
user_to_bot.send_text("test message to bot") user_to_bot.send_text("test message to bot")
message_from_user = crew.bot.wait_next_incoming_message() message_from_user = relaycrew.bot.wait_next_incoming_message()
assert not crew.bot.relayplugin.is_relay_group(message_from_user.chat) assert not relaycrew.bot.relayplugin.is_relay_group(message_from_user.chat)
user_group = crew.user.create_group_chat( user_group = relaycrew.user.create_group_chat(
"test with user", contacts=[botcontact_user] "test with user", contacts=[botcontact_user]
) )
user_group.send_text("testing message to user group") user_group.send_text("testing message to user group")
message_from_user = crew.bot.wait_next_incoming_message() message_from_user = relaycrew.bot.wait_next_incoming_message()
assert not crew.bot.relayplugin.is_relay_group(message_from_user.chat) assert not relaycrew.bot.relayplugin.is_relay_group(message_from_user.chat)