# Path: grazyna/tests/commands/base.py
# def execute_message(protocol, data):
#     ctrl = MessageController(protocol, data)
#     ctrl.log = Mock()
#     ctrl.execute_message()
#     return ctrl
# 
# Path: grazyna/irc/models.py
# class User(object):
#     """User class - has nick, realname, and host"""
#     nick = ""
#     host = ""
#     realname = ""
# 
#     def __init__(self, prefix):
#         try:
#             self.nick, _, name_host = prefix.partition('!')
#             self.realname, _, self.host = name_host.partition('@')
#         except:
#             pass
# 
#     @property
#     def prefix(self):
#         return "%s@%s" % (self.realname, self.host)
# 
#     def __repr__(self):
#         return "User('%s!%s')" % (self.nick, self.prefix)
# 
#     def __eq__(self, other):
#         if not isinstance(other, type(self)):
#             return False
# 
#         return (
#             self.nick == other.nick
#             and self.realname == other.realname
#             and self.host == other.host
#         )


from grazyna.tests.commands.base import execute_message
from grazyna.irc.models import User
import pytest



@pytest.mark.asyncio
def test_notice(protocol_with_importer, event_loop):
    yield from []  # noqa - turn on global event_loop
    data = [':socek!a@b', 'NOTICE', '#czarnobyl', 'message']
    ctrl = execute_message(protocol_with_importer, data)

    def check(ctrl):  # wait for another coroutines
        importer = protocol_with_importer.importer
        assert protocol_with_importer.messages == []
        assert importer.execute.assert_called_once_with(
            '#czarnobyl', User('socek!a@b'), 'message'
        )


# Path: grazyna/tests/commands/base.py
# def execute_message(protocol, data):
#     ctrl = MessageController(protocol, data)
#     ctrl.log = Mock()
#     ctrl.execute_message()
#     return ctrl
# 
# Path: grazyna/irc/models.py
# class User(object):
#     """User class - has nick, realname, and host"""
#     nick = ""
#     host = ""
#     realname = ""
# 
#     def __init__(self, prefix):
#         try:
#             self.nick, _, name_host = prefix.partition('!')
#             self.realname, _, self.host = name_host.partition('@')
#         except:
#             pass
# 
#     @property
#     def prefix(self):
#         return "%s@%s" % (self.realname, self.host)
# 
#     def __repr__(self):
#         return "User('%s!%s')" % (self.nick, self.prefix)
# 
#     def __eq__(self, other):
#         if not isinstance(other, type(self)):
#             return False
# 
#         return (
#             self.nick == other.nick
#             and self.realname == other.realname
#             and self.host == other.host
#         )


# Path: grazyna/tests/commands/test_command_notice.py
from grazyna.tests.commands.base import execute_message
from grazyna.irc.models import User
import pytest




@pytest.mark.asyncio
def test_notice(protocol_with_importer, event_loop):
    yield from []  # noqa - turn on global event_loop
    data = [':socek!a@b', 'NOTICE', '#czarnobyl', 'message']
    ctrl = execute_message(protocol_with_importer, data)

    def check(ctrl):  # wait for another coroutines
        importer = protocol_with_importer.importer
        assert protocol_with_importer.messages == []
        assert importer.execute.assert_called_once_with(
            '#czarnobyl', User('socek!a@b'), 'message'
        )


        ctrl.log.assert_called_once_with('#czarnobyl', '<socek> message')