def create_customer(self, data: dict): try: LOGGER.debug('Creating customer service') self.__validations.data(data=data) customer = Customer(**data) customer = self.__database.save(document=customer) return self.__parser.raw_to_json( data=customer.to_mongo().to_dict()) except NotUniqueError: LOGGER.info('Email already used') raise EmailAlreadyUsedException() except ValidationError as exception: LOGGER.debug(traceback.format_exc()) LOGGER.debug('Invalid fields value') raise InvalidFieldsValuesException(validations=exception.to_dict()) except MissingRequiredFieldsException as exception: raise exception except Exception as exception: LOGGER.debug(traceback.format_exc()) LOGGER.critical(exception) raise exception
def update_customer_by_id(self, customer_id: str, data: dict) -> Customer: LOGGER.debug(f'Updating customer {customer_id} in database') customer = Customer.objects(id=customer_id).first() # pylint: disable=no-member if not customer: raise NotFoundException customer.update(**data) # pylint: disable=no-member customer = Customer.objects(id=customer_id).first() return customer
def test_when_there_are_multiple_customers(self): customers = CustomerClassifier.get_top_buyers( [ Customer("1", [OrderWithBarCodes("1", "1", ["1111"])]), Customer("2", [OrderWithBarCodes("2", "2", ["2222","3333"])]) ], 1) self.assertEquals(len(customers), 1) self.assertEquals(customers[0].get_id(), "2") self.assertEquals(customers[0].get_total_of_bar_codes(), 2)
def parse_file(self, file) -> Iterable[Purchase]: try: # note this is easier with Pandas, but Alpine docker images have trouble with that! with open(file) as f: rows = f.readlines() for raw_row in rows: row = raw_row.split('\t') customer = Customer() customer.id = int(row[0]) customer.first_name = row[1] customer.last_name = row[2] customer.address = row[3] customer.state = row[4] customer.zip_code = str(row[5]) status = PurchaseStatusChange.canceled if row[ 6] == 'canceled' else PurchaseStatusChange.new product = Product() product.id = int(row[7]) product.name = row[8] purchase = Purchase() purchase.customer = customer purchase.product = product purchase.status_change = status purchase.amount = float(row[9]) purchase.datetime = dateutil.parser.parse(row[10]) yield purchase except Exception as e: log(ERROR, '', e) yield None
def get_customer_by_id(self, customer_id: str) -> Customer: LOGGER.debug(f'Getting customer {customer_id} in database') customer = Customer.objects(id=customer_id).first() # pylint: disable=no-member if not customer: LOGGER.debug('None customer found to customer_id informed') raise NotFoundException return customer
def create_customer(): customer = Customer() customer.first_name = 'Testy' customer.last_name = 'McTesterson' customer.state = "NY" customer.zip_code = '11213' customer.address = '1641 Pacific St 1' return customer
def findById(self, id): conn = ConnectionManagment.getConnection() cursor = conn.cursor() tupleId = (id, ) sql = 'select * from customer where customer_id = %s' cursor.execute(sql, tupleId) item = cursor.fetchone() conn.commit() conn.close try: customer = Customer(item[0], item[1], item[2], item[3], item[4], item[5], item[6]) except: customer = Customer(None, None, None, None, None, None, None) return customer
def test_parse_customer_favorites_successfully(self): customer = Customer(**CUSTOMER) data_parsed = Parser().parse_customer_favorites(customer=customer) self.assertEqual(customer.name, data_parsed.get('name')) self.assertEqual(customer.email, data_parsed.get('email')) self.assertEqual(customer.favorites, data_parsed.get('favorites'))
def test_raw_to_json_successfully(self): customer = Customer(**CUSTOMER) Parser.raw_to_json(data=customer.to_mongo().to_dict())
def test_raw_to_json_failure_incorrect_data(self): with self.assertRaises(Exception): customer = Customer(**CUSTOMER) Parser.raw_to_json(data=customer)
def pull_product_to_favorites(self, customer: Customer, product: Product) -> Customer: LOGGER.debug(f'Pulling product to {customer.id}') customer.update(pull__favorites=product) customer = Customer.objects(id=customer.id).first() return customer
def delete_customer_by_id(self, customer_id: str) -> None: LOGGER.debug(f'Deleting customer {customer_id} in database') customer = Customer.objects(id=customer_id).delete() # pylint: disable=no-member if not customer: raise NotFoundException
clock = pygame.time.Clock() pygame.mixer.music.play(-1) pygame.mixer.music.set_volume(0.8) mapper = Mapper() fit = Genetic_fitness(mapper) positions = fit.get_position() mapper.update_tables(positions) env = Restaurant(GRID_LENGTH, GRID_WIDTH) arr = mapper.return_arrangement() env.push_grid_positions(arr) entry = arr[2] agent = WaiterAgent(env.grid[entry[0][0], entry[0][1]]) customer = Customer(env.grid[entry[1][0], entry[1][1]], direction=Direction.UP) env.grid[entry[0][0], entry[0][1]].occupation = agent env.grid[entry[1][0], entry[1][1]].occupation = customer map_renderer = MapRenderer(env, screen, agent, customer) conversation_finished = False # Simple scenario - customer enters the restaurant and then waiter serves him cg, ag = mapper.seat_customer() customer_goal = {'tile': env.grid[cg[0]][cg[1]], 'direction': Direction.UP} cus_node_seq = astar_search(customer, customer_goal) customer.actions = [node.action for node in cus_node_seq] agent_goal = {'tile': env.grid[ag[0]][ag[1]], 'direction': Direction.DOWN} agent_node_seq = astar_search(agent, agent_goal) agent.actions = [node.action for node in agent_node_seq] done = False
def test_when_list_has_a_customer_with_multiple_barcodes(self): self.__assert_console_result([ Customer("1", [OrderWithBarCodes("2", "1", [1111, 2222, 33333])]), Customer("2", [OrderWithBarCodes("5", "2", [4444, 5555, 6666])]), Customer("3", [OrderWithBarCodes("6", "3", [7777, 8888, 9999])]), ], "multiple_customers.txt")
def test_when_list_has_a_customer_with_barcodes(self): self.__assert_console_result([ Customer("1", [OrderWithBarCodes("2", "1", [1111, 2222, 33333])]) ], "customer_with_barcodes.txt")
def __append_customer(customers, order_with_bar_codes): customer_id = order_with_bar_codes.get_customer_id() customers[customer_id] = Customer(customer_id, [order_with_bar_codes])
def test_when_there_is_only_one_customer(self): customers = CustomerClassifier.get_top_buyers([Customer("1", [OrderWithBarCodes("1", "1", ["1111"])])], 1) self.assertEquals(len(customers), 1) self.assertEquals(customers[0].get_id(), "1") self.assertEquals(customers[0].get_total_of_bar_codes(), 1)