def setUp(self): drinkCollection = [ Drink("Smol Beer", 2, 3.00), Drink("Tol Boi", 4, 4.50) ] self.pub = Pub("The Testing Arms", drinkCollection) self.customers = { "customer older than 18": Customer("Rosie", 29, 25.00), "customer younger than 18": Customer("Oliver", 10, 4) }
def setTestControlDefaults(self): """ The test control customer was defined as the test head office since all other varying customers (loaded customers) will be compared to it Loaded with New York's coordinates """ self.controlCustomer = Customer() self.controlCustomer.latitude = 40.6976637 self.controlCustomer.longitude = -74.1197643 self.controlCustomer.name = "Test Head Office" self.controlCustomer.user_id = -1 self.controlCustomer.calculate() self.testMain.controlCustomer = self.controlCustomer
class TestCustomer(unittest.TestCase): def setUp(self): self.customer = Customer("Testy McTest", 30, 25.00) self.drinks = { "Weak Beer": Drink("Smol Beer", 2, 3.00), "Strong Beer": Drink("Tol Boi", 4, 4.50) } self.food = Food("Pie", 5, 3) def test_buy_drink(self): self.customer.buy_drink(self.drinks["Weak Beer"]) self.assertEqual(22, self.customer.wallet) def test_consume_drink(self): self.customer.consume_drink(self.drinks["Strong Beer"]) self.assertEqual(4, self.customer.drunkeness) def test_buy_food(self): self.customer.buy_food(self.food) self.assertEqual(20.00, self.customer.wallet) def test_consume_food(self): self.customer.consume_food(self.food) self.assertEqual(-3, self.customer.drunkeness)
def test_valid_user_2(self): validUser2 = Customer(validEmail2, validFirstName2, validLastName2, validPassword2) registerObj = validUser2.get_register_data() match = { 'email': validEmail2, 'first_name': validFirstName2, "last_name": validLastName2, "password": validPassword2 } self.assertEqual( registerObj, match, msg= f"registerObj does not match\n\nregisterObj: {registerObj}\n\ncorrect: {match}" )
def get_all_info_customer(id): sql = "select * from customers where customer_id = %s" cur.execute(sql, (id, )) res = cur.fetchall() if len(res) == 0: return None customer = Customer() status = res[0][3] att = res[0][4] customer.set_customer_id(id) customer.set_status(status) customer.set_login_attempts(att) return customer
def set_default_values(self): self.controlData = Customer() self.controlData.latitude = 28.426846 self.controlData.user_id = 1000 self.controlData.name = "Control Customer's Location" self.controlData.longitude = 77.088834 self.controlData.calculate() self.varyingData = Customer() self.varyingData.latitude = 28.394231 self.varyingData.user_id = 1001 self.varyingData.name = "Varying Customer's Location" self.varyingData.longitude = 77.050308 self.varyingData.calculate() self.distance = Distance() self.distance.control_customer = self.controlData self.distance.varying_customer = self.varyingData self.distance.calculate_longitude_abs_diff() self.distance.calculate_central_angle() self.distance.calculate_central_angle_degrees() self.distance.calculate_distance_km() self.distance.calculate_distance_miles()
class TestCustomer(unittest.TestCase): def setUp(self): self.customer = Customer("Jack Jarvis", 1000) self.pet = Pet("Blue", "cat", "British Shorthair", 500) def test_customer_has_name(self): self.assertEqual("Jack Jarvis", self.customer.name) def test_customer_has_cash(self): self.assertEqual(1000, self.customer.cash) def test_pets_start_at_0(self): self.assertEqual(0, self.customer.pet_count()) def test_can_add_pet(self): self.customer.add_pet(self.pet) self.assertEqual(1, self.customer.pet_count()) def test_can_get_total_pet_cost(self): self.customer.add_pet(self.pet) self.customer.add_pet(self.pet) self.customer.add_pet(self.pet) self.assertEqual(1500, self.customer.get_total_value_of_pets())
def _parse_file_data(self, data): """ Parse the meat of the file and return registers and customers """ customers = [] for line in data: line_list = line.split(' ') # The first line is register count if len(line_list) <= 1: registers = self._get_registers(int(line_list[0].rstrip())) # Parse out customers data else: customer = Customer( line_list[0].rstrip(), # type int(line_list[1].rstrip()), # arrival int(line_list[2].rstrip())) # items customers.append(customer) return registers, customers
def sign_up(self): customer: Customer = Customer() first_name = input("Enter First Name\n> ") last_name = input("Enter Last Name\n> ") add_line1 = input("Enter Address Line 1\n> ") add_line2 = input("Enter Address Line 2\n> ") city = input("Enter City\n> ") state = input("Enter State\n> ") try: pincode = int(input("Enter Pincode\n> ")) if pincode < 100000 or pincode > 999999: print("Invalid Pincode") return except: print("Invalid Pincode") return password = input("Enter password (min 8 char and max 20 char)\n> ") while len(password) < 8 or len(password) > 20: print("Please Enter password in given range\n> ") password = input() customer.set_first_name(first_name) customer.set_last_name(last_name) customer.set_password(password) customer.set_status(CustomerStatus.open.value) customer.set_login_attempts(3) addr: Address = Address() addr.set_line_1(add_line1) addr.set_line_2(add_line2) addr.set_city(city) addr.set_state(state) addr.set_pincode(pincode) customer.set_address(addr) database.sign_up_customer(customer) input("\nPress ENTER to continue...") self.state_machine.change_state(self.app.main_menu)
class TestCustomer(unittest.TestCase): def setUp(self): self.customer_a1 = Customer('A', 1, 2) self.customer_a2 = Customer('A', 2, 1) self.customer_b1 = Customer('B', 1, 2) self.customer_b2 = Customer('B', 3, 1) self.registers = [Register(1), Trainer(2)] def tearDown(self): pass def test_find_register(self): """ Test different cases of find_register """ self.customer_a1.find_register(self.registers) # Should be first customer in register 1 self.assertEqual(self.registers[0].customers[0], self.customer_a1) self.customer_b1.find_register(self.registers) self.reset_registers() # Should be first customer in register 2 self.assertEqual(self.registers[1].customers[0], self.customer_b1) self.customer_a2.find_register(self.registers) self.reset_registers() # Should be second customer in register 1 self.assertEqual(self.registers[0].customers[1], self.customer_a2) self.customer_b2.find_register(self.registers) self.reset_registers() # Should be third customer in register 1 self.assertEqual(self.registers[0].customers[2], self.customer_b2) def reset_registers(self): """ For clarity in the test we will put the registers back the way they were """ self.registers.sort(key=lambda r: r.register_num)
async def game(websocket, path): running = True while running: try: message = await websocket.recv() data = json.loads(message) payload = data.get('payload') if data.get('name') == 'restaurant_update': if payload['id'] in RESTAURANTS: restaurant = RESTAURANTS[payload['id']] else: restaurant = Restaurant() restaurant.update(**payload) RESTAURANTS[payload['id']] = restaurant elif data.get('name') == 'customer_update': restaurant_id = payload.get('restaurant_id') if restaurant_id is None: # Geting first restaurant # TODO: get the most empty restaurant restaurant_id = list(RESTAURANTS.keys())[0] restaurant = RESTAURANTS.get(restaurant_id) state = payload['state'] if payload['id'] in CUSTOMERS: customer = CUSTOMERS[payload['id']] else: customer = Customer() customer.update(**payload) CUSTOMERS[customer.id] = customer if state == State.left.value: del CUSTOMERS[customer.id] if customer.get_message(): if customer.get_message() == '#': running = False break await websocket.send(json.dumps(customer.get_message())) except LineExceededSize: await websocket.send('#') except Exception as e: # TODO: deal with the exceptions print(e)
def setUp(self): self.customer_a1 = Customer('A', 1, 2) self.customer_a2 = Customer('A', 2, 1) self.customer_b1 = Customer('B', 1, 2) self.customer_b2 = Customer('B', 3, 1) self.registers = [Register(1), Trainer(2)]
from classes.order import Order # create prodcut model pm = ProductModel(db) # create a product # product = Product("Pinon",5000,"Togo") # insert the product # product = pm.insertProduct(product) products = pm.getProducts() product_list = [] for product in products: product_list.append( Product(product['name'], product['price'], product['country'], product['_id'])) cm = CustomerModel(db) customer = Customer("Serge", "Kossi", "M", "92639417") customer = cm.insertCustomer(customer) om = OrderModel(db) order = Order(customer) for product in product_list: order.add_product(product) order = om.insertOrder(order) print(order)
def set_default_values(self): self.testData = Customer() self.testData.latitude = 40.6976637 self.testData.user_id = 1000 self.testData.name = "Test Name" self.testData.longitude = -74.1197643
class TestCustomer(unittest.TestCase): def set_default_values(self): self.testData = Customer() self.testData.latitude = 40.6976637 self.testData.user_id = 1000 self.testData.name = "Test Name" self.testData.longitude = -74.1197643 def test_DEGREES_IN_RADIAN(self): """ Test to DEGREES_IN_RADIAN value """ self.set_default_values() self.assertEqual(self.testData.get_DEGREES_IN_RADIAN(), 57.29577951) def test_affirm_latitude(self): """ Test to validate attributes are as they are supposed to be """ self.set_default_values() self.assertEqual(self.testData.latitude, 40.6976637) def test_affirm_longitude(self): """ Test to validate attributes are as they are supposed to be """ self.set_default_values() self.assertEqual(self.testData.longitude, -74.1197643) def test_affirm_name(self): """ Test to validate attributes are as they are supposed to be """ self.set_default_values() self.assertEqual(self.testData.name, "Test Name") def test_affirm_user_id(self): """ Test to validate attributes are as they are supposed to be """ self.set_default_values() self.assertEqual(self.testData.user_id, 1000) def test_affirm_latitude_longitude_validity(self): """ Test to validate attributes are as they are supposed to be """ self.set_default_values() self.testData.validate_degrees() self.assertEqual(self.testData.valid, True) def test_affirm_latitude_radian(self): """ Test to validate attributes are as they are supposed to be """ self.set_default_values() self.testData.calculate_radians() self.assertEqual(float("{:.6f}".format(self.testData.latitude_radians)), 0.710308) #6 decimal places to cater for approxination def test_affirm_longitude_radian(self): """ Test to validate attributes are as they are supposed to be """ self.set_default_values() self.testData.calculate_radians() self.assertEqual(float("{:.6f}".format(self.testData.longitude_radians)), -1.293634) #6 decimal places to cater for approxination
def add_new_customer_to_database(self): new_customer = Customer() self.db.add_new_customer(new_customer)
def add_new_customer(self): new_customer = Customer() return new_customer
class TestDistance(unittest.TestCase): """ Test will focus on only attributes consumed by the Distance class """ def set_default_values(self): self.controlData = Customer() self.controlData.latitude = 28.426846 self.controlData.user_id = 1000 self.controlData.name = "Control Customer's Location" self.controlData.longitude = 77.088834 self.controlData.calculate() self.varyingData = Customer() self.varyingData.latitude = 28.394231 self.varyingData.user_id = 1001 self.varyingData.name = "Varying Customer's Location" self.varyingData.longitude = 77.050308 self.varyingData.calculate() self.distance = Distance() self.distance.control_customer = self.controlData self.distance.varying_customer = self.varyingData self.distance.calculate_longitude_abs_diff() self.distance.calculate_central_angle() self.distance.calculate_central_angle_degrees() self.distance.calculate_distance_km() self.distance.calculate_distance_miles() def test_DEGREES_IN_RADIAN(self): """ Test to DEGREES_IN_RADIAN value """ self.set_default_values() self.assertEqual(self.distance.get_DEGREES_IN_RADIAN(), 57.29577951) def test_MEAN_EARTH_RADIUS_KM(self): """ Test to MEAN_EARTH_RADIUS value """ self.set_default_values() self.assertEqual(self.distance.get_MEAN_EARTH_RADIUS_KM(), 6371) def test_KILOMETRES_IN_MILE(self): """ Test to KILOMETRES_IN_MILE value """ self.set_default_values() self.assertEqual(self.distance.get_KILOMETRES_IN_MILE(), 1.60934) def test_varying_customer_lattitude_longitude_validity(self): """ Test to confirm if varying customer_lattitude_longitude_ is valid """ self.set_default_values() self.assertEqual(self.distance.varying_customer.valid, True) def test_control_customer_latitude_longitude_validity(self): """ Test to confirm if control customer_lattitude_longitude_ is valid """ self.set_default_values() self.assertEqual(self.distance.control_customer.valid, True) def test_control_customer_latitude_radians(self): """ Test to confirm if control_customer_latitude_radians is 0.496142 """ self.set_default_values() self.assertEqual( float("{:.6f}".format( self.distance.control_customer.latitude_radians)), 0.496142) def test_control_customer_longitude_radians(self): """ Test to confirm if control_customer_longitude_radians 1.345454 """ self.set_default_values() self.assertEqual( float("{:.6f}".format( self.distance.control_customer.longitude_radians)), 1.345454) def test_varying_customer_latitude_radians(self): """ Test to will """ self.set_default_values() self.assertEqual( float("{:.6f}".format( self.distance.varying_customer.latitude_radians)), 0.495573) def test_varying_customer_longitude_radians(self): """ Test to will """ self.set_default_values() self.assertEqual( float("{:.6f}".format( self.distance.varying_customer.longitude_radians)), 1.344782) def test_longitude_absolute_difference(self): """ Test to longitudes_abs_diff attribute """ self.set_default_values() self.assertEqual( float("{:.6f}".format(self.distance.longitudes_abs_diff)), 0.000672) def test_central_angle_radians(self): """ Test to longitudes_abs_diff attribute """ self.set_default_values() self.assertEqual( float("{:.6f}".format(self.distance.central_angle_radians)), 0.000821) def test_central_angle_degrees(self): """ Test to longitudes_abs_diff attribute """ self.set_default_values() self.assertEqual( float("{:.6f}".format(self.distance.central_angle_degrees)), 0.047032) def test_distance_in_km(self): """ Test to validate the right distance was gotten """ self.set_default_values() self.assertEqual( float("{:.6f}".format(self.distance.distance_kilometres)), 5.229706) def test_distance_in_miles(self): """ Test to validate the right distance was gotten """ self.set_default_values() self.assertEqual(float("{:.2f}".format(self.distance.distance_miles)), 3.25)
class TestCustomer(unittest.TestCase): def setUp(self): self.customer = Customer("Jack Jarvis", 1000) self.pet = Pet("Blue", "cat", "British Shorthair", 500) def test_customer_has_name(self): self.assertEqual("Jack Jarvis", self.customer.name) def test_customer_has_cash(self): self.assertEqual(1000, self.customer.cash) def test_customer_can_reduce_cash(self): self.customer.reduce_cash(500) self.assertEqual(500, self.customer.cash) def test_pets_start_at_0(self): self.assertEqual(0, self.customer.pet_count()) def test_can_add_pet(self): self.customer.add_pet(self.pet) self.assertEqual(1, self.customer.pet_count()) def test_can_get_total_pet_cost(self): self.customer.add_pet(self.pet) self.customer.add_pet(self.pet) self.customer.add_pet(self.pet) # Adds the same pet 3 times just to check the total keeps adding up. Not the best example self.assertEqual(1500, self.customer.get_total_value_of_pets())
no = {'no', 'n'} hotel_for_choose = [] i = 1 for hotel in hotel_list: for (k, v) in hotel.items(): hotel_for_choose.append((i, k)) i += 1 # user dialog # print("Enter your first and last name") # input_names = input().split(" ") input_names = ["Artem", "Sviridov"] customer = Customer(f"{input_names[0]}", f"{input_names[1]}") while True: print("Choose hotel for booking") print(hotel_for_choose) while True: try: input_hotel_number = int(input()) if input_hotel_number > len( hotel_for_choose) or input_hotel_number <= 0: raise InputExceptionError("We dont have such hotel", input_hotel_number) except ValueError: print('Not a number') except InputExceptionError as mr:
def setUp(self): self.customer = Customer("Jack Jarvis", 1000) self.pet = Pet("Blue", "cat", "British Shorthair", 500)
def test_invalid_user_2(self): with self.assertRaises( ValueError, msg="Values passed should have raised a Value Error"): Customer(invalidEmail2, invalidFirstName2, invalidLastName2, invalidPassword2)
class TestMain(unittest.TestCase): def set_default_values(self): self.testMain = Main() self.setTestControlDefaults() self.testMain.setDistanceControlCustomer() self.testMain.raw_data = ( '{"latitude": "39.7645187", "user_id": 12, "name": "Denver", "longitude": "-104.9951948"}\n' + '{"latitude": "25.7825453", "user_id": 1, "name": "Miami", "longitude": " -80.2994985"}\n' + '{"latitude": "41.8339037", "user_id": 2, "name": "Chicago", "longitude": "-87.8720471"}\n' ) self.testMain.DISTANCE_CHECK = 2000 def setTestControlDefaults(self): """ The test control customer was defined as the test head office since all other varying customers (loaded customers) will be compared to it Loaded with New York's coordinates """ self.controlCustomer = Customer() self.controlCustomer.latitude = 40.6976637 self.controlCustomer.longitude = -74.1197643 self.controlCustomer.name = "Test Head Office" self.controlCustomer.user_id = -1 self.controlCustomer.calculate() self.testMain.controlCustomer = self.controlCustomer def test_control_customer_details(self): """ Test to validate Control Customer's details were correctly loaded """ self.set_default_values() self.assertEqual(self.testMain.controlCustomer.latitude, 40.6976637) def test_control_customer_details_distance(self): """ Test to validate Control Customer's details were correctly loaded into the distance object """ self.set_default_values() self.assertEqual(self.testMain.distance.control_customer.latitude, 40.6976637) def test_customer_data(self): """ Test to validate all raw_data were properly parsed and saved """ self.set_default_values() self.testMain.load_and_set_all_sorted_customer_data() self.assertEqual(self.testMain.load_data.countCustomerData(), 3) def test_customer_data_sorted(self): """ Test to validate all raw_data were properly sorted """ self.set_default_values() self.testMain.load_and_set_all_sorted_customer_data() self.assertEqual(self.testMain.customer_data[0].user_id, 1) def test_DISTANCE_CHECK(self): """ Test to validate all raw_data were properly sorted """ self.set_default_values() self.assertEqual(self.testMain.DISTANCE_CHECK, 2000) def test_DINNER_LIST(self): """ Test to validate only those customers within 2000Km were invited (Miami and Chicago) """ self.set_default_values() self.testMain.load_and_set_all_sorted_customer_data() self.testMain.findDinnerList() self.assertEqual(len(self.testMain.dinner_list), 2) def test_program_output(self): """ Test to validate the program output """ self.set_default_values() self.testMain.load_and_set_all_sorted_customer_data() self.testMain.findDinnerList() self.assertEqual( self.testMain.getOutput(), "---------LIST OF CUSTOMERS INVITED FOR DINNER--------\n-----Start Customer #1 -------\n User Id: 1\n User Name: Miami\n Latitude: 25.7825453\n Longitude: -80.2994985\n Distance to Head Office: 1754.0Km\n-----End Customer #1-------\n-----Start Customer #2 -------\n User Id: 2\n User Name: Chicago\n Latitude: 41.8339037\n Longitude: -87.8720471\n Distance to Head Office: 1155.09Km\n-----End Customer #2-------\n" )
def test_invalid_email_setter_1(self): with self.assertRaises( ValueError, msg="Values passed should have raised a Value Error"): user = Customer() user.setEmail(invalidEmail1)