Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# -*- coding: utf-8 -*-
from irc3.testing import BotTestCase
from irc3.testing import MagicMock
from irc3.testing import patch
from collections import defaultdict
from panoramisk import Message
class Event(Message):
def __init__(self, event, **kwargs):
self.name = event
self.headers = dict(event=event, **kwargs)
def __getitem__(self, name):
return self.headers[name]
def update(self, **kwargs):
self.headers.update(kwargs)
self.name = self.headers['event']
class TestAsterirc(BotTestCase):
config = dict(
def setUp(self):
self.patch_asyncio()
patcher = patch('panoramisk.Manager.send_action_via_http')
self.send_action = patcher.start()
self.response = Message(
'response', '', headers={'Response': 'Success'})
self.send_action.return_value = self.response
self.addCleanup(patcher.stop)
self.mocks = {}
for name in ('connect', 'close'):
patcher = patch('panoramisk.Manager.' + name)
self.mocks[name] = patcher.start()
self.addCleanup(patcher.stop)
def send_action(self, *args, **kwargs):
try:
res = self.manager.send_action(*args, **kwargs)
return res
except Exception as e:
self.log.error('send_action(%r, **%r)', args, kwargs)
self.log.exception(e)
return Message('response',
'Sorry an error occured. ({})'.format(repr(e)),
headers={'Response': 'Failed'})