def create(site_list, arbitrator_list): """ Validate creating a minimal booth config iterable site_list -- list of booth sites' addresses iterable arbitrator_list -- list of arbitrators' addresses """ report_list = [] peer_list = site_list + arbitrator_list if len(site_list) < 2: report_list.append(reports.booth_lack_of_sites(site_list)) if len(peer_list) % 2 == 0: report_list.append(reports.booth_even_peers_num(len(peer_list))) duplicate_addresses = { address for address, count in Counter(peer_list).items() if count > 1 } if duplicate_addresses: report_list.append( reports.booth_address_duplication(duplicate_addresses)) return report_list
def validate_peers(site_list, arbitrator_list): report = [] if len(site_list) < 2: report.append(reports.booth_lack_of_sites(site_list)) peer_list = site_list + arbitrator_list if len(peer_list) % 2 == 0: report.append(reports.booth_even_peers_num(len(peer_list))) address_set = set() duplicate_addresses = set() for address in peer_list: if address in address_set: duplicate_addresses.add(address) else: address_set.add(address) if duplicate_addresses: report.append(reports.booth_address_duplication(duplicate_addresses)) if report: raise LibraryError(*report)
def validate_peers(site_list, arbitrator_list): report = [] if len(site_list) < 2: report.append(reports.booth_lack_of_sites(site_list)) peer_list = site_list + arbitrator_list if len(peer_list) % 2 == 0: report.append(reports.booth_even_peers_num(len(peer_list))) address_set = set() duplicate_addresses = set() for address in peer_list: if address in address_set: duplicate_addresses.add(address) else: address_set.add(address) if duplicate_addresses: report.append(reports.booth_address_duplication(duplicate_addresses)) if report: raise LibraryError(*report)
def test_multiple_addresses(self): self.assert_message_from_report( "duplicate address for booth configuration: addr1, addr2, addr3", reports.booth_address_duplication(["addr2", "addr1", "addr3"]))
def test_single_address(self): self.assert_message_from_report( "duplicate address for booth configuration: addr1", reports.booth_address_duplication(["addr1"]))