"""Helper methods to compare pricing results. Used in unit tests to check that two lists of pricing results match. """ def check_pricing_results_match(pricing_result1, pricing_result2): """Check that two lists of pricing results are the same.""" for item1 in pricing_result1: if not has_match(item1, pricing_result2): print('Expected:') print(pricing_result1) print('Actual:') print(pricing_result2) raise Exception( 'Item: ' + str(item1) + ' has no match in pricing_result2') for item2 in pricing_result2: if not has_match(item2, pricing_result1): raise Exception( 'Item: ' + str(item2) + ' has no match in pricing_result1') def has_match(item1, pricing_result): """Check if there is an item that matches item1 in pricing_result.""" for item2 in pricing_result: if items_match(item1, item2): return True return False def items_match(item1, item2): # noqa: C901 """Check if two items match.""" if 'track_ids' in item1: if 'track_ids' not in item2: return False elif set(item1['track_ids']) != set(item2['track_ids']): return False if 'resolution' in item1: if 'resolution' not in item2: return False elif item1['resolution'] != item2['resolution']: return False if 'start_date' in item1: if 'start_date' not in item2: return False elif item1['start_date'] != item2['start_date']: return False if 'end_date' in item1: if 'end_date' not in item2: return False elif item1['end_date'] != item2['end_date']: return False if 'custom_price' in item1 or 'custom_price' in item2: if 'custom_price' not in item1: return False elif 'custom_price' not in item2: return False elif item1['custom_price'] != item2['custom_price']: return False if 'custom_currency_code' in item1 or 'custom_currency_code' in item2: if 'custom_currency_code' not in item1: return False elif 'custom_currency_code' not in item2: return False elif item1['custom_currency_code'] != item2['custom_currency_code']: return False if 'price_code' in item1 or 'price_code' in item2: if 'price_code' not in item1: return False elif 'price_code' not in item2: return False elif item1['price_code'] != item2['price_code']: return False return item1['territories'] == item2['territories']