33 lines
874 B
Python
33 lines
874 B
Python
|
|
from dataclasses import dataclass
|
||
|
|
from typing import Any, Callable
|
||
|
|
|
||
|
|
|
||
|
|
def install_contract_suite(
|
||
|
|
channel_id: str,
|
||
|
|
plugin_factory: Callable[[], Any],
|
||
|
|
):
|
||
|
|
def _decorator(cls):
|
||
|
|
cls.make_plugin = staticmethod(plugin_factory)
|
||
|
|
return cls
|
||
|
|
return _decorator
|
||
|
|
|
||
|
|
|
||
|
|
@dataclass
|
||
|
|
class SendTestHarness:
|
||
|
|
plugin: Any
|
||
|
|
to: str = "test_target"
|
||
|
|
sent_count: int = 0
|
||
|
|
|
||
|
|
async def run_send_text(self, content: str, **kwargs):
|
||
|
|
msg_id = await self.plugin.send_text(self.to, content, **kwargs)
|
||
|
|
self.sent_count += 1
|
||
|
|
return msg_id
|
||
|
|
|
||
|
|
async def run_send_media(self, media_url: str, media_type: str = "image", **kwargs):
|
||
|
|
msg_id = await self.plugin.send_media(self.to, media_url, media_type, **kwargs)
|
||
|
|
self.sent_count += 1
|
||
|
|
return msg_id
|
||
|
|
|
||
|
|
@property
|
||
|
|
def sent_messages(self):
|
||
|
|
return self.plugin._sent
|