Exemplo n.º 1
0
def app(dynamodb):
    os.environ["DYNALITE_URL"] = dynamodb
    app = create_app()
    with app.app.app_context():
        g.subhub_account = app.app.subhub_account
        g.subhub_deleted_users = app.app.subhub_deleted_users
        yield app
Exemplo n.º 2
0
def test_create_app():
    app = create_app()
    assert app
Exemplo n.º 3
0
def test_subhub():
    """
    something
    """
    app = create_app()
    assert isinstance(app, connexion.FlaskApp)
Exemplo n.º 4
0
def app():
    app = create_app()
    with app.app.app_context():
        g.subhub_account = app.app.subhub_account
        g.subhub_deleted_users = app.app.subhub_deleted_users
        yield app
Exemplo n.º 5
0
    def setUp(self) -> None:
        sub_app = create_app()
        with sub_app.app.app_context():
            g.subhub_account = sub_app.app.subhub_account
            g.subhub_deleted_users = sub_app.app.subhub_deleted_users

        self.client = sub_app.app.test_client()

        with open(os.path.join(DIRECTORY,
                               "fixtures/stripe_cust_test1.json")) as fh:
            cust_test1 = json.loads(fh.read())
        self.customer = convert_to_stripe_object(cust_test1)

        with open(os.path.join(DIRECTORY,
                               "fixtures/stripe_deleted_cust.json")) as fh:
            deleted_cust = json.loads(fh.read())
        self.deleted_customer = convert_to_stripe_object(deleted_cust)

        with open(os.path.join(DIRECTORY,
                               "fixtures/stripe_plan_test2.json")) as fh:
            plan_test2 = json.loads(fh.read())
        self.plan2 = convert_to_stripe_object(plan_test2)

        with open(os.path.join(DIRECTORY,
                               "fixtures/stripe_plan_test4.json")) as fh:
            plan_test4 = json.loads(fh.read())
        self.plan4 = convert_to_stripe_object(plan_test4)

        with open(os.path.join(DIRECTORY,
                               "fixtures/stripe_plan_test5.json")) as fh:
            plan_test5 = json.loads(fh.read())
        self.plan5 = convert_to_stripe_object(plan_test5)

        with open(os.path.join(DIRECTORY,
                               "fixtures/stripe_prod_test1.json")) as fh:
            prod1 = json.loads(fh.read())
        self.prod1_fpn = convert_to_stripe_object(prod1)

        with open(os.path.join(DIRECTORY,
                               "fixtures/stripe_prod_test2.json")) as fh:
            prod2 = json.loads(fh.read())
        self.prod2_none = convert_to_stripe_object(prod2)

        with open(os.path.join(DIRECTORY,
                               "fixtures/stripe_prod_test3.json")) as fh:
            prod3 = json.loads(fh.read())
        self.prod3_none = convert_to_stripe_object(prod3)

        with open(os.path.join(DIRECTORY,
                               "fixtures/stripe_prod_test4.json")) as fh:
            prod4 = json.loads(fh.read())
        self.prod4_fpn = convert_to_stripe_object(prod4)

        with open(os.path.join(DIRECTORY,
                               "fixtures/stripe_prod_test5.json")) as fh:
            prod5 = json.loads(fh.read())
        self.prod5_identity = convert_to_stripe_object(prod5)

        with open(os.path.join(DIRECTORY,
                               "fixtures/stripe_sub_test1.json")) as fh:
            sub1 = json.loads(fh.read())
        sub1["plan"] = plan_test4
        self.subscription = convert_to_stripe_object(sub1)

        self.subhub_user = SubHubAccountModel(
            user_id="user_1",
            cust_id="cust_1",
            origin_system="fxa",
            customer_status="active",
        )

        retrieve_customer_patcher = mock.patch("stripe.Customer.retrieve")
        retrieve_plan_patcher = mock.patch("stripe.Plan.retrieve")
        retrieve_product_patcher = mock.patch("stripe.Product.retrieve")
        modify_subscription_patcher = mock.patch("stripe.Subscription.modify")
        get_subhub_user_patcher = mock.patch(
            "shared.db.SubHubAccount.get_user")

        self.addCleanup(retrieve_customer_patcher.stop)
        self.addCleanup(retrieve_plan_patcher.stop)
        self.addCleanup(retrieve_product_patcher.stop)
        self.addCleanup(modify_subscription_patcher.stop)
        self.addCleanup(get_subhub_user_patcher.stop)

        self.retrieve_customer_mock = retrieve_customer_patcher.start()
        self.retrieve_plan_mock = retrieve_plan_patcher.start()
        self.retrieve_product_mock = retrieve_product_patcher.start()
        self.modify_subscription_mock = modify_subscription_patcher.start()
        self.get_subhub_user_mock = get_subhub_user_patcher.start()
Exemplo n.º 6
0
# TODO!
# newrelic.agent.initialize()

from aws_xray_sdk.core import xray_recorder, patch_all
from aws_xray_sdk.core.context import Context
from aws_xray_sdk.ext.flask.middleware import XRayMiddleware

from sub.app import create_app
from shared.log import get_logger

logger = get_logger()

xray_recorder.configure(service="fxa.sub")
patch_all()

sub_app = create_app()
XRayMiddleware(sub_app.app, xray_recorder)


# TODO!
# @newrelic.agent.lambda_handler()
def handle(event, context):
    try:
        logger.info("handling sub event", subhub_event=event, context=context)
        return serverless_wsgi.handle_request(sub_app.app, event, context)
    except Exception as e:  # pylint: disable=broad-except
        logger.exception("exception occurred",
                         subhub_event=event,
                         context=context,
                         error=e)
        # TODO: Add Sentry exception catch here