def test_Users(models): Jim, Kim = Users() # register Jim jimInDB = UserController.createFromRegistration(Jim) updatedJim = jimInDB.set(test=True) jim = UserController.getFromId(jimInDB.id) assert isinstance(jim, UserController) assert str(jim) == "Jim Bob" # check all the attributes assert jim.email == Jim["email"] assert jim.phone_number == Jim["phone_number"] assert jim.password != Jim["password"] assert jim.test == True # use the login method jimsAPICall = {"email": Jim["email"], "password": Jim["password"]} jim = UserController.fromLogin(jimsAPICall) token = jim.encodeToken() # give the token back to the frontend # do some stuff # frontend submits a request to an auth_required route _jim = UserController.getFromToken(token) assert jim.id == _jim.id # register Kim kimInDB = UserController.createFromRegistration(Kim) # use the getFromId method kim = UserController.getFromId(kimInDB.id) assert isinstance(kim, UserController) assert str(kim) == "Kim Sue"
def login(): user = UserController.fromLogin(request.get_json()) return user.encodeToken()