def expected_update_result(): customer = Customer() customer.set_identifier("ba6a4e88-534f-416d-bf6e-985bd6d03b84") customer.set_first_name("Ann") customer.set_last_name("Jones") customer.set_middle_initial("B") return customer
def expected_find_by_id_result(): customer = Customer() customer.set_identifier("7d0e2324-7057-435f-8510-f05a6bb2d7f5") customer.set_first_name("Jane") customer.set_last_name("Smith") customer.set_middle_initial("K") return customer
def general_test_customer(): customer = Customer() customer.set_identifier("9b4a56ea-de9b-4662-9c12-646033d77483") customer.set_first_name("Test") customer.set_last_name("User") customer.set_middle_initial("R") return customer
def expected_save_result(): customer = Customer() customer.set_identifier("ecf7d5ab-b609-4926-b584-491228739440") customer.set_first_name("Kevin") customer.set_last_name("Anderson") customer.set_middle_initial("A") return customer
def test_new(): customer = Customer() customer = customer.new_from_dict({ "first_name": "John", "last_name": "Doe", "middle_initial": "F" }) assert customer.str() == "Customer [first_name: John, last_name: Doe]"
def test_new_from_dict(): customer = Customer() customer_dict = { "identifier": str(uuid.uuid4()), "first_name": "John", "last_name": "Doe", "middle_initial": "F" } customer = customer.new_from_dict(customer_dict) assert customer.to_dict() == customer_dict
def expected_find_all_result(): customer = Customer() customer.set_identifier("9186630c-a671-4d20-b38d-c627d21da302") customer.set_first_name("John") customer.set_last_name("Doe") customer.set_middle_initial("S") results = set() results.add(customer) return results
def putCustomer(self, item): data = Customer( self.view.listview.itemWidget(item).data.id, self.window.name(), self.window.email(), self.window.phone(), ) headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} r = requests.put("http://localhost:8080/api/v1/customers", data=data.toJson(), headers=headers) if r.status_code == 204: self.getCustomer()
def create_default_objects(): ''' Creates a list of default users and accounts for testing purposes ''' # Create a default Admin user Admin(username="******", password="******", first_name="Jack").save() print("Default Admin Created") cust1 = Customer(username="******", password="******", first_name="John") cust1.save() print("Default Customer Created") Checking_Account(account_number="1", owner=cust1).save() print("Default Checking Account Created") Savings_Account(account_number="2", owner=cust1).save() print("Default Savings Account Created") cust2 = Customer(username="******", password="******", first_name="Clark") cust2.save() print("Default Customer2 Created") Savings_Account(account_number="3", owner=cust2).save() print("Default Savings Account Created") Brokerage_Account(account_number="4", owner=cust1).save() print("Default Brokerage Account Created")
def post(self): #Post trên server sẽ lấy đủ đơn hàng, post trên local sẽ thiếu đơn hàng body = parser.parse_args() items = body["items"] user_id = body.user_id total_spend = 0 order_item = [] dumps = json.dumps(items) ldumps = re.findall(r"[\w']+", dumps) print(len(items)) for i in range(0, len(items) + 1): try: good_id = ldumps[4 * i + 1][1:-1] count = int(ldumps[4 * i + 3]) good = Good.objects().with_id(good_id) price = good.price total_spend += price * count singleOrder = SingleOrder(good=good, count=count) order_item.append(singleOrder) except: print("Index error") print("order_item:", mlab.list2json(order_item)) customer = Customer.objects().with_id(user_id) order = Order(items=order_item, customer=customer, totalspend=total_spend) order.save() add_order = Order.objects().with_id(order.id) return mlab.item2json(add_order)
def test_customer_set_email_negative(self): try: Customer("ravinder", "*****@*****.**") assert False except EmailException as e: assert e.args[ 0] == "Email format invalid. Expected: [<more_than_two_letter>@<more_than_three_letter>.<not_more_than_two_to_three_letter>]+(*All in small case)"
def post(self): #parser.add_argument(name="id", type= int, location="json") #parser.add_argument(name="count", type=int, location="json") body = parser.parse_args() items = body["items"] user_id = body.user_id total_spend = 0 order_item = [] print("body:", body) print("items:", items) print("user_id:", user_id) for item in items: print("item type:", type(item)) print("item:", item) good_id = item["id"] count = item["count"] good = Good.objects().with_id(good_id) price = good.price print("good_id:", good_id, ";count: ", count, "price: ", price) total_spend += price * count singleOrder = SingleOrder(good=good, count=count) order_item.append(singleOrder) customer = Customer.objects().with_id(user_id) #print(mlab.item2json(order_item[0])) #print("order_item0:",mlab.item2json(order_item[0]),"order_item1:",order_item[1]) order = Order(items=order_item, customer=customer, totalspend=total_spend) order.save() add_order = Order.objects().with_id(order.id) return mlab.item2json(add_order)
def test_customer_set_name_negative(self): try: Customer("r1234", "*****@*****.**") assert False except NameException as e: assert e.args[ 0] == "Name format invalid: name may only consist of letter"
def customer_test_value(): customer = Customer() customer.set_identifier("7d0e2324-7057-435f-8510-f05a6bb2d7f5") customer.set_first_name("Tom") customer.set_last_name("Smith") customer.set_middle_initial("K") return customer
def get_all_customers(self): ''' Retrieves information about all of the Customers as an array of Customers ''' customer_array = [] for each_customer in Customer.select(): customer_array.append(each_customer) return customer_array
def on_buttonApply_clicked(self, widget): entryName = self.builder.get_object("entryName") name = entryName.get_text() entryCIF = self.builder.get_object("entryCIF") cif = entryCIF.get_text() newCustomer = Customer(None, name, cif) self.addCustomer(newCustomer) self.window_edit.hide()
def create_customer(self, username, password, first_name): ''' Creates a new customer object and returns it Takes two strings as parameters ''' if len(password) < 8: raise Exception("Password is too short") user_name_exists = False try: Admin.get(usemodelrname=username) user_name_exists = True except: pass if user_name_exists: raise Exception("Username is already in use") cust = Customer(username=username, password=password, first_name=first_name) cust.save() return cust
def authenticate(username, password): print("Authenticate register") for user in Customer.objects(username=username): if user.password == password: if safe_str_cmp(user.password.encode('utf-8'), password.encode('utf-8')): print("OK") return LoginCredentials(str(user.id), user.username, user.password)
def start_order(self): name = self.ui.login_inputs() town, street, number = self.ui.adress_inputs() customer = Customer(name) email = Email(name) adress = Adress(town, street, number) payment = Payment() self.order = Order(customer, email, payment, adress) self.add_to_cart()
def get_customer(self): ''' Ask the user for a username and return the customer with that username ''' cust = None try: cust = Customer.get_customer(input("Username: "******"Could not find the customer with that username") return cust
def login(self, username, password): # try logging as admin try: self.user = Admin.login(username, password) except Admin.DoesNotExist: # try logging as customer try: self.user = Customer.login(username, password) except Customer.DoesNotExist: raise LoginError("The user and password combination you tried is invalid.")
def getCustomer(self): self.view.listview.setEnabled(False) self.view.listview.clear() try: r = requests.get("http://localhost:8080/api/v1/customers") if r.status_code == 200: for data in r.json(): self.addCustomer(Customer(**data)) except: pass self.view.listview.setEnabled(True)
def getCustomer(self): self.view.customers.setEnabled(False) self.view.customers.clear() try: r = requests.get("http://localhost:8080/api/v1/customers") if r.status_code == 200: self._customers = [Customer(**data) for data in r.json()] self.view.customers.addItems( [customer.name for customer in self._customers]) except Exception as e: print("Error to get customers in Sale Window", e) self.view.customers.setEnabled(True)
def post(self): parser = reqparse.RequestParser() parser.add_argument(name="username", type=str, location="json") parser.add_argument(name="password", type=str, location="json") body = parser.parse_args() username = body.username password = body.password print("REGISTER SAVE") if username is None or password is None: return {"meassage": "Thiếu trường"}, 401 found_user = Customer.objects(username=username).first() if found_user is not None: print("User already exist") return redirect('api/login', 307) user = Customer(username=username, password=password) print({"name": user.username + ";password:" + user.password}) user.save() return redirect('api/login', 307)
def _load_customers(self, controller): customers = self._config.items("Customers") for customer in customers: citems = customer[1].split(',') if len(citems) > 7: customer_name = customer[0] (private_ip_subnet, ingress_interface, ip_datapath, router, next_hop, name_server, out_port, datapath_to_router_ip, datapath_to_router_interface, ns_domain_name) = citems c = Customer(customer_name, private_ip_subnet, ingress_interface, ip_datapath, router, next_hop, out_port, datapath_to_router_ip, datapath_to_router_interface, ns_domain_name) if name_server != "": print name_server + "NS" c.set_name_server(name_server) else: customer_name = customer[0] (private_ip_subnet, ingress_interface, ip_datapath, router, next_hop, name_server) = citems c = CustomerAlg1(customer_name, private_ip_subnet, ingress_interface, ip_datapath, router, next_hop) if name_server != "": print name_server + "NS" c.set_name_server(name_server) self._customers.append(c) controller.set_customers(c)
def add_item(): price = request.form['price'] quantity = request.form['quantity'] cal = float(price) * int(quantity) item = {"item_name": food[price], "price": cal, "quantity": quantity} for name, email in zip(user_email.keys(), user_email.values()): username = name usermail = email break Customer.add_items(uid, username, item) data = Customer.get_item(uid) for val in data: total.append(val['items'][0]['price']) items = Item.get_items() for i in total: sets.append(int(i)) con = sum(set(sets)) total.clear() return render_template("profile.html", username=username, items=items, total_price=con)
def main(): # creates 3 customers customers = [Customer(1, "Doe"), Customer(2, "Ray"), Customer(3, "Me")] # creates 3 accounts accounts = [ CreditCardAccount(customers[0]), (SavingsAccount(customers[1])), CreditCardAccount(customers[2]) ] # task 1 for account in accounts: if isinstance(account, CreditCardAccount): credit_limit_account = validator.get_int( "Enter credit card limit: ", 0, True) account.set_credit_limit(credit_limit_account) # task 2 wdr_charge_amount = validator.get_int("Enter savings withdrawal charge: ", 0, True) SavingsAccount.set_withdraw_charge(wdr_charge_amount) # task 3 for account in accounts: # deposit to account deposit_amount = validator.get_int("Enter deposit amount: ", 0, True) account.deposit(deposit_amount) # withdraw from account withdrawal_amount = validator.get_int("Enter withdrawal amount: ", 0, True) account.withdraw(withdrawal_amount) # print the new details of the account for account in accounts: print(account)
def updateCustomer(customerid): if not request.json: abort(400) if not 'name' in request.json or not 'address' in request.json: abort(400) address = Address(request.json['address']['line'], request.json['address']['city'], request.json['address']['state'], request.json['address']['zip']) customer = Customer(customerid, request.json['name'], address) ##Update the Customer ##send CustomerUpdated event customerEventData = CustomerChanged(customer) postToEventStore('CustomerUpdated', customerEventData) return jsonify(customer), 200
def login(self): ''' Request user credentials and logs them in as either an Admin or Customer ''' self.user = None while self.user is None: username = input("Username: "******"Invalid Login")
def post(self, id): parser = reqparse.RequestParser() parser.add_argument(name="user_id", type=str, location="json") parser.add_argument(name="message", type=str, location="json") body = parser.parse_args() id_user = body["user_id"] message = body["message"] rage = Rage.objects().with_id(id) customer = Customer.objects().with_id(id_user) date = datetime.datetime.utcnow() + datetime.timedelta(hours=7) comment = Comment(customer=customer, message=message, date=str(date), rage=rage) comment.save() comment_add = Comment.objects().with_id(comment.id) return mlab.item2json(comment_add), 200