def test_get_all_master_ids(): with session_scope(): ecf = EventFactory() fcc = FeedCtrlConnection() new_event = ecf.next_event('MASTER/MASTER', {}) fcc.add_event(new_event) ecf2 = EventFactory() new_event1 = ecf2.next_event('MASTER/MASTER', {}) fcc.add_event(new_event1) 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) 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_all_master_ids() assert result1[0] == ecf2.get_feed_id() assert len(result1) == 1
def test_set_radius(): with session_scope(): ecf = EventFactory() fcc = FeedCtrlConnection() new_event = ecf.next_event('MASTER/MASTER', {}) fcc.add_event(new_event) last_event = ecf.next_event('MASTER/Radius', {'radius': 5}) 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/Radius', {'radius': 3}) fcc.add_event(new_event) new_event = ecf2.next_event('MASTER/Name', {'name': 'Alice'}) 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) fcc.set_feed_ids_radius(ecf.get_feed_id(), 6) fcc.set_feed_ids_radius(ecf2.get_feed_id(), 10) result = fcc.get_radius() assert result == 6
def test_get_trusted(): 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) 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/Name', {'name': trust_id4}) fcc.add_event(new_event) trust_id4 = generate_random_feed_id() new_event = ecf.next_event('MASTER/NewFeed', { 'feed_id': trust_id4, 'app_name': 'TestApp' }) fcc.add_event(new_event) new_event = ecf.next_event('MASTER/Radius', {'radius': 5}) fcc.add_event(new_event) result = fcc.get_trusted(ecf.get_feed_id()) assert result[0] == trust_id1 assert result[1] == trust_id2 assert result[2] == trust_id3 assert len(result) == 3
def test_get_username(): with session_scope(): ecf = EventFactory() fcc = FeedCtrlConnection() new_event = ecf.next_event('MASTER/MASTER', {}) fcc.add_event(new_event) new_event = ecf.next_event('MASTER/Name', {'name': 'Alice'}) fcc.add_event(new_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) 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_username(ecf.get_feed_id()) result2 = fcc.get_username(ecf2.get_feed_id()) assert result1 == 'Patrice' assert result2 == 'Bob'
def create_feed(self, article_feed_name): fcc = FeedCtrlConnection() ect = EventCreationTool() ect.set_path_to_keys(DIR_MAIN + '/' + 'Keys', False) event = self.db_connector.get_current_event(self.master_feed_id) ecf_master = EventFactory(event, DIR_MAIN + '/' + 'Keys', False) eventCreationWrapper = EventCreationWrapper(ecf_master) public_key = ect.generate_feed() new_feed_event = eventCreationWrapper.create_newFeed( public_key, 'bac_news') trust_feed_event = eventCreationWrapper.create_trust(public_key) first_event = ect.create_first_event( public_key, 'bac_news/new_article', {'master_feed': self.master_feed_id}) fcc.add_event(new_feed_event) fcc.add_event(trust_feed_event) fcc.add_event(first_event) # creates event containing list name, host name and creation date (second event of the newly created feed) ect = EventCreationTool() ect.set_path_to_keys(DIR_MAIN + '/' + 'Keys', False) dictionary = { 'host': self.get_event_content(self.master_feed_id, 2)[1]['name'], 'list_name': article_feed_name, 'date': datetime.now().isoformat() } second_event = ect.create_event_from_previous(first_event, 'bac_news/new_article', dictionary) fcc.add_event(second_event)
def generate_test_data(): ufh = UiFunctionHandler() fcc = FeedCtrlConnection() ecf = EventFactory() 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': 'TestApp1'}) fcc.add_event(new_event) trust_id2 = generate_random_feed_id() new_event = ecf.next_event('MASTER/NewFeed', {'feed_id': trust_id2, 'app_name': 'TestApp2'}) fcc.add_event(new_event) new_event = ecf.next_event('MASTER/Name', {'name': 'Alice'}) fcc.add_event(new_event) ecf2 = EventFactory() new_event = ecf2.next_event('MASTER/MASTER', {}) fcc.add_event(new_event) trust_id3 = generate_random_feed_id() new_event = ecf2.next_event('MASTER/NewFeed', {'feed_id': trust_id3, 'app_name': 'TestApp1'}) fcc.add_event(new_event) trust_id4 = generate_random_feed_id() new_event = ecf2.next_event('MASTER/NewFeed', {'feed_id': trust_id4, 'app_name': 'TestApp2'}) fcc.add_event(new_event) new_event = ecf2.next_event('MASTER/Name', {'name': 'Bob'}) fcc.add_event(new_event) new_event = ecf.next_event('MASTER/Trust', {'feed_id': trust_id3}) ufh.set_trusted(trust_id1, True) ufh.set_trusted(trust_id4, True) ufh.set_trusted(trust_id2, False) ufh.set_radius(2)
def test_outgoing_master(self): with session_scope(): fcc = FeedCtrlConnection() ecf = EventFactory() new_event = ecf.next_event('MASTER/MASTER', {}) fcc.add_event(new_event) ver = Verification() result = ver.check_outgoing(ecf.get_feed_id()) assert result is True
def test_incoming_not_trusted(self): with session_scope(): ecf = EventFactory() ver = Verification() new_event = ecf.next_event('MASTER/MASTER', {}) fcc = FeedCtrlConnection() fcc.add_event(new_event) trust_id1 = generate_random_feed_id() assert ver.check_incoming(trust_id1, 'TestApp1') is False
def test_outgoing_not_trusted(self): with session_scope(): fcc = FeedCtrlConnection() ecf = EventFactory() new_event = ecf.next_event('MASTER/MASTER', {}) fcc.add_event(new_event) trust_id1 = generate_random_feed_id() ver = Verification() result = ver.check_outgoing(trust_id1) assert result is False
def create_event(self, feed_name, json_file): feed_id = self.get_id_from_feed_name(feed_name) event = self.db_connector.get_current_event(feed_id) ect = EventCreationTool() ect.set_path_to_keys(DIR_MAIN + '/' + 'Keys', False) new_event = ect.create_event_from_previous(event, 'bac_news/new_article', {'json': json_file}) fcc = FeedCtrlConnection() fcc.add_event(new_event)
def test_get_feed_ids_from_application_in_master_id(): 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) trust_id3 = generate_random_feed_id() new_event = ecf.next_event('MASTER/NewFeed', { 'feed_id': trust_id3, '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_feed_ids_from_application_in_master_id( ecf.get_feed_id(), 'Test1') result2 = fcc.get_feed_ids_from_application_in_master_id( ecf2.get_feed_id(), 'Test2') logger.error(result1) assert result1[0] == trust_id1 assert result2[0] == trust_id2 assert result1[1] == trust_id3
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 test_get_feed_ids_in_radius(): with session_scope(): ecf = EventFactory() fcc = FeedCtrlConnection() new_event = ecf.next_event('MASTER/MASTER', {}) fcc.add_event(new_event) new_event = ecf.next_event('MASTER/Radius', {'radius': 3}) fcc.add_event(new_event) ecf2 = EventFactory() new_event = ecf2.next_event('MASTER/MASTER', {}) fcc.add_event(new_event) new_event = ecf2.next_event('MASTER/Radius', {'radius': 5}) fcc.add_event(new_event) ecf3 = EventFactory() new_event = ecf3.next_event('MASTER/MASTER', {}) fcc.add_event(new_event) new_event = ecf3.next_event('MASTER/Radius', {'radius': 1}) fcc.add_event(new_event) ecf4 = EventFactory() new_event = ecf4.next_event('MASTER/MASTER', {}) fcc.add_event(new_event) new_event = ecf4.next_event('MASTER/Radius', {'radius': 2}) fcc.add_event(new_event) new_event = ecf4.next_event('MASTER/Name', {'name': 'Alice'}) 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) result = fcc.get_feed_ids_in_radius() assert result[0] == ecf.get_feed_id() assert result[1] == ecf3.get_feed_id() assert result[2] == ecf4.get_feed_id() assert len(result) == 3
def test_trash(): with session_scope(): ecf = EventFactory() cf = ChatFunction() new_event = ecf.next_event('MASTER/MASTER', {}) fcc = FeedCtrlConnection() fcc.add_event(new_event) trust_id1 = generate_random_feed_id() new_event1 = ecf.next_event('MASTER/Trust', {'feed_id': trust_id1}) fcc.add_event(new_event1) new_event2 = ecf.next_event('MASTER/Trash', {'feed_id': trust_id1}) fcc.add_event(new_event2) new_event2 = ecf.next_event('MASTER/Trash', {'feed_id': trust_id1}) fcc.add_event(new_event2) new_event2 = ecf.next_event('MASTER/Trash', {'feed_id': trust_id1}) fcc.add_event(new_event2) result = cf.get_current_event(ecf.get_feed_id()) assert result == new_event2
def test_add_event_and_get_host_master_id(): with session_scope(): ecf = EventFactory() cf = ChatFunction() new_event = ecf.next_event('MASTER/MASTER', {}) fcc = FeedCtrlConnection() fcc.add_event(new_event) feed = EventFactory() new_event = feed.next_event('chat/MASTER', {'master_feed': ecf.get_feed_id()}) fcc.add_event(new_event) new_event = feed.next_event('chat/whateveraction', { 'messagekey': 'hallo zusammen', 'chat_id': '1', 'timestampkey': 10 }) fcc.add_event(new_event) new_event = feed.next_event('chat/whateveraction', { 'messagekey': 'hallo zusammen', 'chat_id': '1', 'timestampkey': 10 }) 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) result = cf.get_full_chat('1') logger.error(result) result = fcc.get_host_master_id() assert result == ecf.get_feed_id()
def test_in_radius(self): with session_scope(): ver = Verification() fcc = FeedCtrlConnection() ecf1 = EventFactory() new_event = ecf1.next_event('MASTER/MASTER', {}) fcc.add_event(new_event) last_event = ecf1.next_event('MASTER/Radius', {'radius': 5}) fcc.add_event(last_event) ecf2 = EventFactory() new_event = ecf2.next_event('MASTER/MASTER', {}) fcc.add_event(new_event) last_event = ecf2.next_event('MASTER/Radius', {'radius': 3}) fcc.add_event(last_event) ecf3 = EventFactory() new_event = ecf3.next_event('MASTER/MASTER', {}) fcc.add_event(new_event) new_event = ecf3.next_event('MASTER/Radius', {'radius': 3}) fcc.add_event(new_event) trusted_id1 = generate_random_feed_id() new_event = ecf3.next_event('MASTER/NewFeed', { 'feed_id': trusted_id1, 'app_name': 'TestApp' }) fcc.add_event(new_event) trusted_id2 = generate_random_feed_id() new_event = ecf2.next_event('MASTER/NewFeed', { 'feed_id': trusted_id2, 'app_name': 'TestApp' }) fcc.add_event(new_event) new_event = ecf1.next_event('MASTER/Trust', {'feed_id': trusted_id2}) fcc.add_event(new_event) new_event = ecf2.next_event('MASTER/Trust', {'feed_id': trusted_id1}) fcc.add_event(new_event) result = ver._check_in_radius('TestApp') assert result
def __init__(self): self._fcc = FeedCtrlConnection() self._hostID = self._fcc.get_host_master_id()
def exists_db(self): self._fcc = FeedCtrlConnection() master_feed_id = self._fcc.get_host_master_id() if master_feed_id is not None: return 1 return 0