Support client seed cap, support async message handlers
This commit is contained in:
51
tests/base/test_events.py
Normal file
51
tests/base/test_events.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import asyncio
|
||||
import unittest
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from hippolyzer.lib.base.events import Event
|
||||
|
||||
|
||||
class TestEvents(unittest.IsolatedAsyncioTestCase):
|
||||
async def asyncSetUp(self):
|
||||
self.event = Event()
|
||||
|
||||
async def test_trigger_sync(self):
|
||||
mock = MagicMock(return_value=False)
|
||||
self.event.subscribe(mock)
|
||||
self.event.notify("foo")
|
||||
mock.assert_called_with("foo")
|
||||
self.assertIn(mock, [x[0] for x in self.event.subscribers])
|
||||
|
||||
async def test_trigger_sync_unsub(self):
|
||||
mock = MagicMock(return_value=True)
|
||||
self.event.subscribe(mock)
|
||||
self.event.notify("foo")
|
||||
mock.assert_called_with("foo")
|
||||
self.assertNotIn(mock, [x[0] for x in self.event.subscribers])
|
||||
|
||||
async def test_trigger_async(self):
|
||||
called = asyncio.Event()
|
||||
mock = MagicMock()
|
||||
|
||||
async def _mock_wrapper(*args, **kwargs):
|
||||
called.set()
|
||||
mock(*args, **kwargs)
|
||||
self.event.subscribe(_mock_wrapper)
|
||||
self.event.notify("foo")
|
||||
await called.wait()
|
||||
mock.assert_called_with("foo")
|
||||
self.assertIn(_mock_wrapper, [x[0] for x in self.event.subscribers])
|
||||
|
||||
async def test_trigger_async_unsub(self):
|
||||
called = asyncio.Event()
|
||||
mock = MagicMock()
|
||||
|
||||
async def _mock_wrapper(*args, **kwargs):
|
||||
called.set()
|
||||
mock(*args, **kwargs)
|
||||
return True
|
||||
self.event.subscribe(_mock_wrapper)
|
||||
self.event.notify("foo")
|
||||
await called.wait()
|
||||
mock.assert_called_with("foo")
|
||||
self.assertNotIn(_mock_wrapper, [x[0] for x in self.event.subscribers])
|
||||
@@ -23,13 +23,7 @@ import unittest
|
||||
from hippolyzer.lib.base.settings import Settings
|
||||
|
||||
|
||||
class TestEvents(unittest.TestCase):
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
class TestSettings(unittest.TestCase):
|
||||
def test_base_settings(self):
|
||||
settings = Settings()
|
||||
self.assertEqual(settings.ENABLE_DEFERRED_PACKET_PARSING, True)
|
||||
|
||||
@@ -99,6 +99,7 @@ class TestHippoClient(unittest.IsolatedAsyncioTestCase):
|
||||
async def _do_login():
|
||||
with aioresponses.aioresponses() as m:
|
||||
m.post(self.FAKE_LOGIN_URI, body=self._make_fake_login_body())
|
||||
m.post(self.FAKE_LOGIN_RESP['seed_capability'], body="<llsd><map></map></llsd>")
|
||||
await client.login("foo", "bar", login_uri=self.FAKE_LOGIN_URI)
|
||||
await client.logout()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user