def test_sets_adapted_cors_headers_for_subdomain():
    event = build_event(origin="https://www.pyne.studio")

    response = handler(event, {})

    assert (response["headers"]["Access-Control-Allow-Origin"] ==
            "https://www.pyne.studio")
def test_responds_to_preflight_options_calls_with_cors_headers():
    event = build_event(http_method="OPTIONS")

    response = handler(event, {})

    assert (response["headers"]["Access-Control-Allow-Origin"] ==
            "https://www.pyne.studio")
def test_sends_standard_cors_headers_for_standard_origin():
    event = build_event(origin="https://pyne.studio")

    response = handler(event, {})

    assert response["headers"][
        "Access-Control-Allow-Origin"] == "https://pyne.studio"
def test_returns_price_in_euros_for_exiting_product():
    stripe.Product.list = MagicMock(return_value=build_stripe_product_list())
    stripe.Price.list = MagicMock(return_value=build_stripe_price_list(
        price_in_cents=1000))
    event = build_event(path="/price/test_product", http_method="GET")

    response = handler(event, {})

    assert response["statusCode"] == 200
    assert response["body"] == '{"price":"10.00"}'
def test_creates_payment_intent_and_returns_client_secret_for_post_request_with_body(
):
    stripe.PaymentIntent.create = MagicMock(
        return_value=MockPaymentIntent("test_secret"))
    stripe.Product.list = MagicMock(return_value=build_stripe_product_list())
    stripe.Price.list = MagicMock(return_value=build_stripe_price_list())
    event = build_event(http_method="POST", body=build_request_body())

    response = handler(event, {})

    assert response["statusCode"] == 200
    assert response["body"] == '{"clientSecret":"test_secret"}'
def test_returns_client_error_for_non_existing_product():
    stripe.Product.list = MagicMock(return_value=build_stripe_product_list())
    stripe.Price.list = MagicMock(return_value=build_stripe_price_list())
    event = build_event(path="/price/product_that_does_not_exist",
                        http_method="GET")

    response = handler(event, {})

    assert response["statusCode"] == 400
    assert (
        response["body"] ==
        '{"statusCode":400,"message":"Product product_that_does_not_exist not found."}'
    )
def test_responds_with_client_error_to_missing_body():
    event = build_event(body="{}")

    response = handler(event, {})

    assert response["statusCode"] == 400
def test_responds_with_client_error_to_unknown_method():
    event = build_event(http_method="PUT")

    response = handler(event, {})

    assert response["statusCode"] == 404
def test_responds_with_client_error_to_unknown_path():
    event = build_event(path="/unknown")

    response = handler(event, {})

    assert response["statusCode"] == 404