def calculate_customers_nearby(): """ Calculates the a set of customers who are eligible for invitation and then tabulates and shows them in a sorted manner :return: None :rtype: None """ result_set = CustomerDb.invite_customers(DUBLIN_LONGITUDE, DUBLIN_LATITUDE, CUSTOMER_DISTANCE) customers = [ customer_obj for key in sorted(result_set.keys()) for customer_obj in result_set[key] ] customer_list = [[customer.user_id, customer.name] for customer in customers] print(tabulate(customer_list, headers=["ID", "Name"]))
def test_invalid_latitude(self, random_longitude, latitude, random_distance): with pytest.raises(ValueError): CustomerDb.invite_customers(random_longitude, latitude, random_distance)
def test_negative_customer_distance(self, customer_distance, random_longitude, random_latitude): with pytest.raises(ValueError): CustomerDb.invite_customers(random_longitude, random_latitude, customer_distance)
def test_invite_customers(self, random_longitude, random_latitude, random_distance): result_set = CustomerDb.invite_customers(random_longitude, random_latitude, random_distance) assert isinstance(result_set, dict)
def test_customer_db_generator(self): customers = CustomerDb.all() assert isinstance(customers, Generator)
def test_invite_customers_custom_distance(self, custom_distance, expected_ids): invited_customers = CustomerDb.invite_customers(DUBLIN_LONGITUDE, DUBLIN_LATITUDE, custom_distance) assert expected_ids == sorted(invited_customers.keys())
def test_invite_customers(self, expected_customers_id_for_100kms): invited_customers = CustomerDb.invite_customers(DUBLIN_LONGITUDE, DUBLIN_LATITUDE, CUSTOMER_DISTANCE) assert expected_customers_id_for_100kms == sorted(invited_customers.keys())