Exemple #1
0
def test_update_payment_method_valid_parameters(
        app, create_subscription_for_processing):
    """
    GIVEN api_token, userid, pmt_token
    WHEN all parameters are valid
    THEN update payment method for a customer
    """
    subscription, code = create_subscription_for_processing
    updated_pmt, code = payments.update_payment_method(
        "process_test", {"pmt_token": "tok_mastercard"})
    assert 201 == code
    g.subhub_account.remove_from_db("process_test")
def test_update_payment_method_invalid_payment_token(
        app, create_subscription_for_processing):
    """
    GIVEN api_token, userid, pmt_token
    WHEN invalid pmt_token
    THEN do not update payment method for a customer
    """
    (updated_pmt,
     code) = payments.update_payment_method("process_test",
                                            {"pmt_token": "tok_invalid"})
    assert 400 == code
    assert "No such token:" in updated_pmt["message"]
    g.subhub_account.remove_from_db("process_test")
Exemple #3
0
def test_update_payment_method_invalid_payment_token(
        app, create_subscription_for_processing):
    """
    GIVEN api_token, userid, pmt_token
    WHEN invalid pmt_token
    THEN a StripeError exception is raised
    """
    exception = None
    try:
        updated_pmt, code = payments.update_payment_method(
            "process_test", {"pmt_token": "tok_invalid"})
    except Exception as e:
        exception = e

    g.subhub_account.remove_from_db("process_test")

    assert isinstance(exception, InvalidRequestError)
    assert "No such token:" in exception.user_message
Exemple #4
0
def test_update_payment_method_missing_stripe_customer(monkeypatch):
    """
    GIVEN api_token, userid, pmt_token
    WHEN provided user with missing stripe customer id
    THEN return missing customer
    """
    subhub_account = MagicMock()

    get_user = MagicMock()
    user_id = PropertyMock(return_value="process_test")
    cust_id = PropertyMock(return_value=None)
    type(get_user).user_id = user_id
    type(get_user).cust_id = cust_id

    subhub_account.get_user = get_user

    updated_pmt, code = payments.update_payment_method(
        "process_test", {"pmt_token": "tok_invalid"})
    assert 404 == code
Exemple #5
0
def test_update_payment_method_invalid_stripe_customer(
        app, create_subscription_for_processing):
    """
    GIVEN api_token, userid, pmt_token
    WHEN provided invalid stripe data
    THEN a StripeError is raised
    """

    subscription, code = create_subscription_for_processing
    subhub_user = g.subhub_account.get_user("process_test")
    subhub_user.cust_id = "bad_id"
    g.subhub_account.save_user(subhub_user)

    exception = None
    try:
        updated_pmt, code = payments.update_payment_method(
            "process_test", {"pmt_token": "tok_invalid"})
    except Exception as e:
        exception = e

    g.subhub_account.remove_from_db("process_test")

    assert isinstance(exception, InvalidRequestError)
    assert "No such customer:" in exception.user_message