def test_get_my_last_event(): with session_scope(): ecf = EventFactory() fcc = FeedCtrlConnection() new_event = ecf.next_event('MASTER/MASTER', {}) 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) last_event = ecf.next_event('MASTER/Name', {'name': 'Alice'}) fcc.add_event(last_event) ecf2 = EventFactory() new_event = ecf2.next_event('MASTER/MASTER', {}) fcc.add_event(new_event) new_event = ecf2.next_event('MASTER/Name', {'name': 'Bob'}) fcc.add_event(new_event) result = fcc.get_my_last_event() assert result == last_event
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)