class Radius: def __init__(self): self._fcc = FeedCtrlConnection() self._hostID = self._fcc.get_host_master_id() def calculate_radius(self): radius = self._fcc.get_radius() self.__check_trusted(self._hostID, radius, 'MASTER') def __check_trusted(self, master_id, radius, prev_app_name, step=1, ): if radius < 1 or step > radius: return trusted = self._fcc.get_trusted(master_id) for trusted_id in trusted: application_name = self._fcc.get_application_name(trusted_id) master = None if application_name == 'MASTER': master = trusted_id self._fcc.set_feed_ids_radius(master, step) elif application_name == prev_app_name or prev_app_name == 'MASTER': master = self._fcc.get_master_id_from_feed(trusted_id) self._fcc.set_feed_ids_radius(master, step) else: return self.__check_trusted(master, step + 1, radius, application_name)
def test_get_master_id_from_feed(): with session_scope(): ecf = EventFactory() fcc = FeedCtrlConnection() new_event = ecf.next_event('MASTER/MASTER', {}) fcc.add_event(new_event) trust_id1 = generate_random_feed_id() new_event = ecf.next_event('MASTER/NewFeed', { 'feed_id': trust_id1, 'app_name': 'Test1' }) fcc.add_event(new_event) ecf2 = EventFactory() new_event = ecf2.next_event('MASTER/MASTER', {}) fcc.add_event(new_event) trust_id2 = generate_random_feed_id() new_event = ecf2.next_event('MASTER/NewFeed', { 'feed_id': trust_id2, 'app_name': 'Test2' }) fcc.add_event(new_event) new_event = ecf2.next_event('MASTER/Name', {'name': 'Alice'}) fcc.add_event(new_event) trust_id5 = generate_random_feed_id() new_event = ecf.next_event('MASTER/Trust', {'feed_id': trust_id5}) fcc.add_event(new_event) trust_id5 = generate_random_feed_id() new_event = ecf.next_event('MASTER/NewFeed', { 'feed_id': trust_id5, 'app_name': 'TestApp' }) fcc.add_event(new_event) new_event = ecf.next_event('MASTER/Radius', {'radius': 5}) fcc.add_event(new_event) new_event = ecf.next_event('MASTER/Name', {'name': 'Patrice'}) fcc.add_event(new_event) result1 = fcc.get_master_id_from_feed(trust_id1) result2 = fcc.get_master_id_from_feed(trust_id2) assert result1 == ecf.get_feed_id() assert result2 == ecf2.get_feed_id()