class ICMPMonitoringTests(unittest.TestCase): """ Test class for the ICMPMonitor class """ def _add_test_subscriber(self, imsi): ip = IPAddress(version=IPAddress.IPV4, address=b'127.0.0.1') self.subscribers[imsi] = ip async def _ping_local(self): return await self._monitor._ping_targets( [LOCALHOST], self.subscribers, ) def setUp(self): """ Creates and sets up ICMP monitor """ self.loop = asyncio.get_event_loop() self.subscribers = {} self.obj = CpeMonitoringModule() self._monitor = ICMPJob( self.obj, polling_interval=5, service_loop=self.loop, mtr_interface=LOCALHOST, ) def test_ping_subscriber_saves_response(self): imsi = 'IMSI00000000001' self._add_test_subscriber(imsi) self.loop.run_until_complete(self._ping_local()) sub_states = self.obj.get_subscriber_state() self.loop.close() self.assertTrue(imsi in sub_states)
def _get_serialized_subscriber_states(cpe_monitor: CpeMonitoringModule): return serialize_subscriber_states(cpe_monitor.get_subscriber_state())