async def registration(customer: Customer, x_session_token: Optional[str] = Header(None), x_session_id: Optional[str] = Header(None)): """ the method to register new customer by telephone, name, password :param customer: in body json: {"customer: {"telephone": customer.telephone, "password": customer.password "name": customer.name} :param x_session_id: the id of the clint session :param x_session_token: the token of the clint session :return: response 400 if json data incorrect + error in json, 401 if session is dead + session in json, 405 if telephone not unique + error in json, 400 if customer data not found + error in json, 200 if auth ok + new customer in json """ # check session live session = Session.find({"id": int(x_session_id), "token": x_session_token}) check = session.check_session_live() if check is False: return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content=json.dumps({ "session": { "id": session.id, "authorized": session.authorized } })) # register try: customer.add() except IntegrityError: return JSONResponse(status_code=status.HTTP_405_METHOD_NOT_ALLOWED, content={"error": "telephone not unique"}) session.auth(customer.id) return JSONResponse(status_code=status.HTTP_200_OK, content={"customer": dict(customer)})
def test_customer_create(db): c = Customer() customers = [ dict( name='British Telecom', web='home.bt.com', ), dict( name='Cellcom', web='cellcom.co.il', ), dict( name='Mahle GmbH', web='www.mahle.com', ), ] for customer in customers: rowid = c.add(customer) print("Row ID: {}".format(rowid)) assert type(rowid).__name__ == 'int'