Beispiel #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"
Beispiel #2
0
def register():
    stripe.api_key = current_app.config["STRIPE_API_KEY"]
    user = UserController.createFromRegistration(request.get_json())
    baseUrl = request.headers.get("referer", "https://localhost:5000/")
    try:
        checkout_session = stripe.checkout.Session.create(
            success_url=baseUrl + "success?session_id={CHECKOUT_SESSION_ID}",
            cancel_url=baseUrl + "failed",
            payment_method_types=["card"],
            mode="subscription",
            line_items=[{
                "price": stripe.Price.list()["data"][0]["id"],
                # For metered billing, do not pass quantity
                "quantity": 1,
            }],
            customer_email=user.email,
            client_reference_id=user.id,
            subscription_data={"trial_period_days": 30},
        )
        return jsonify({
            "token":
            user.encodeToken().decode("utf-8"),
            "sessionId":
            checkout_session["id"],
            "pk":
            "pk_test_51I0Hi7AJqS6KUAStIg73brufDB8SmNTBqFvYFLyt7vAV1Ecbf7fPzDDIiwFflpnyD9tbYvaObpEpLhj9lBqROwZC00WywiUsQk",
        })
    except Exception as e:
        print(e)
        return jsonify({"error": {"message": str(e)}}), 400
Beispiel #3
0
def test_BlackList(models):

    # general set up
    Jim, Kim = Users()
    for user in Users():
        user_in_db = UserController.createFromRegistration(user)
        users_token = user_in_db.encodeToken()
        token = BlackListToken(users_token)
        token.addToDB()