def test_get_blocked(): with session_scope(): ecf = EventFactory() new_event = ecf.next_event('MASTER/MASTER', {}) fcc = FeedCtrlConnection() fcc.add_event(new_event) trust_id1 = generate_random_feed_id() new_event = ecf.next_event('MASTER/Trust', {'feed_id': trust_id1}) fcc.add_event(new_event) trust_id2 = generate_random_feed_id() new_event = ecf.next_event('MASTER/Trust', {'feed_id': trust_id2}) fcc.add_event(new_event) new_event = ecf.next_event('MASTER/Block', {'feed_id': trust_id2}) fcc.add_event(new_event) trust_id3 = generate_random_feed_id() new_event = ecf.next_event('MASTER/Trust', {'feed_id': trust_id3}) fcc.add_event(new_event) trust_id4 = generate_random_feed_id() new_event = ecf.next_event('MASTER/Block', {'feed_id': trust_id4}) 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/Name', {'name': 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) result1 = fcc.get_blocked(ecf.get_feed_id()) result2 = fcc.get_trusted(ecf.get_feed_id()) assert result1[0] == trust_id2 assert result1[1] == trust_id4 assert result2[0] == trust_id1 assert result2[1] == trust_id3 assert len(result1) == 2 assert len(result2) == 3
class UiFunctionHandler: def __init__(self): self._fcc = FeedCtrlConnection() # try catch or if None?? lastEvent = self._fcc.get_my_last_event() if lastEvent is not None: self._ecf = EventFactory(lastEvent) self._eventCreationWrapper = EventCreationWrapper(self._ecf) else: self._ecf = EventFactory() self._eventCreationWrapper = EventCreationWrapper(self._ecf) _firstEvent = self._eventCreationWrapper.create_MASTER() _secondEvent = self._eventCreationWrapper.create_radius(1) _thirdEvent = self._eventCreationWrapper.create_name('Anon') self._fcc.add_event(_firstEvent) self._fcc.add_event(_secondEvent) self._fcc.add_event(_thirdEvent) self._masterID = self._fcc.get_host_master_id() def get_host_master_id(self): # returns the host masterID return self._masterID def get_master_ids(self): # return list of masterIDs from FeedCtrlConnection return self._fcc.get_all_master_ids() def get_all_master_ids_feed_ids(self, masterID): # return a list of feed_ids which belong to the given masterID return self._fcc.get_all_master_ids_feed_ids(masterID) def get_radius_list(self): # return a list of feed_ids which are inside the radius return self._fcc.get_feed_ids_in_radius() def get_trusted(self): # return a list of trusted feed_ids return self._fcc.get_trusted(self._masterID) def set_trusted(self, feed_id, state): # sets a feed to trusted or untrusted (event) if state: new_event = self._eventCreationWrapper.create_trust(feed_id) else: new_event = self._eventCreationWrapper.create_block(feed_id) self._fcc.add_event(new_event) def get_blocked(self): # return a list of blocked feed_ids return self._fcc.get_blocked(self._masterID) def get_radius(self): # return the current radius return self._fcc.get_radius() def set_radius(self, radius): # sets the new radius # calls calcRadius() to recalculate the new Elements, which are in the radius self._fcc.set_feed_ids_radius(self._masterID, radius) def get_username(self, masterID): # return username from given masterID return self._fcc.get_username(masterID) def set_username(self, name): new_event = self._eventCreationWrapper.create_name(name) self._fcc.add_event(new_event) def get_application(self, feed_id): # return application name from given feed_id return self._fcc.get_application_name(feed_id)