hebdobot/tests/utils.py

55 lines
1.1 KiB
Python
Raw Normal View History

from dataclasses import dataclass
2024-01-11 08:17:25 +01:00
import pytest
from hebdobot import HebdoBot
2024-01-11 08:17:25 +01:00
from tests import settings
OWNER = "me"
SENDER = "foobar"
SENDER_2 = "foobaz"
2024-01-11 08:17:25 +01:00
@dataclass
class Answer():
target: str
message: str
@dataclass
class Source():
nick: str
class Event():
def __init__(self, target, nick, message):
self.target = target
self.source = Source(nick)
self.arguments = [message]
def test_privmsg(self, target, message):
self.answers.append(Answer(target, message))
def test_public_message(self, target, sender, message):
self.answers = []
self.on_pubmsg(None, Event(target, sender, message))
def test_private_message(self, target, sender, message):
self.answers = []
self.on_privmsg(None, Event(target, sender, message))
2024-01-11 08:17:25 +01:00
@pytest.fixture
def bot():
HebdoBot.test_public_message = test_public_message
HebdoBot.test_private_message = test_private_message
HebdoBot.test_privmsg = test_privmsg
hebdobot = HebdoBot(settings)
hebdobot.connection.privmsg = hebdobot.test_privmsg
hebdobot.answers = []
return hebdobot