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 test_no_site(self): self.assert_message_from_report( ("lack of sites for booth configuration (need 2 at least): " "sites missing"), reports.booth_lack_of_sites([]))
def test_multiple_sites(self): self.assert_message_from_report( ("lack of sites for booth configuration (need 2 at least): " "sites site1, site2"), reports.booth_lack_of_sites(["site1", "site2"]))