Esempio n. 1
0
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"
Esempio n. 2
0
 def route_wrapper(*args, **kwargs):
     token = get_token_auth_header()
     user = UserController.getFromToken(token)
     return func(RecipeController(user.id, user.active), *args, **kwargs)
Esempio n. 3
0
 def route_wrapper(*args, **kwargs):
     token = get_token_auth_header()
     user = UserController.getFromToken(token)
     return func(user, *args, **kwargs)