def test_subscribe_customer_existing(create_customer_for_processing): """ GIVEN create a subscription WHEN provided a customer and plan THEN validate subscription is created """ uid = uuid.uuid4() subscription, code = payments.subscribe_to_plan( "validcustomer", { "pmt_token": "tok_visa", "plan_id": "plan_EtMcOlFMNWW4nd", "email": f"valid@{uid}customer.com", "orig_system": "Test_system", }, ) subscription2, code2 = payments.subscribe_to_plan( "validcustomer", { "pmt_token": "tok_visa", "plan_id": "plan_EtMcOlFMNWW4nd", "email": f"valid@{uid}customer.com", "orig_system": "Test_system", }, ) assert 409 == code2 payments.cancel_subscription( "validcustomer", subscription["subscriptions"][0]["subscription_id"]) g.subhub_account.remove_from_db("validcustomer")
def test_cancel_subscription_already_cancelled( app, create_subscription_for_processing): (subscription, code) = create_subscription_for_processing cancelled, code = payments.cancel_subscription( "process_test", subscription["subscriptions"][0]["subscription_id"]) cancelled2, code2 = payments.cancel_subscription( "process_test", subscription["subscriptions"][0]["subscription_id"]) assert cancelled["message"] == "Subscription cancellation successful" assert 201 == code assert cancelled2["message"] == "Subscription cancellation successful" assert 201 == code2 g.subhub_account.remove_from_db("process_test")
def test_cancel_subscription_with_invalid_stripe_customer( app, create_subscription_for_processing): """ GIVEN an userid and subscription id WHEN the user has an invalid stripe customer id THEN a StripeError is raised """ subscription, code = create_subscription_for_processing subhub_user = g.subhub_account.get_user("process_test") subhub_user.cust_id = None g.subhub_account.save_user(subhub_user) exception = None try: cancelled, code = payments.cancel_subscription( "process_test", subscription["subscriptions"][0]["subscription_id"]) except Exception as e: exception = e g.subhub_account.remove_from_db("process_test") assert isinstance(exception, InvalidRequestError) assert "Customer instance has invalid ID" in exception.user_message
def test_cancel_subscription_with_invalid_data( app, create_subscription_for_processing): (subscription, code) = create_subscription_for_processing (cancelled, code) = payments.cancel_subscription( "process_test", subscription["subscriptions"][0]["subscription_id"] + "invalid") assert cancelled["message"] == "Subscription not available." assert 400 == code g.subhub_account.remove_from_db("process_test")
def test_cancel_subscription_with_invalid_subhub_user(app): """ GIVEN an active subscription WHEN provided an api_token and an invalid userid THEN return customer not found error """ cancelled, code = payments.cancel_subscription("invalid_user", "subscription_id") assert 404 == code assert cancelled["message"] == "Customer does not exist."
def test_create_subscription_with_valid_data(): """ GIVEN create a subscription WHEN provided a api_token, userid, pmt_token, plan_id, cust_id THEN validate subscription is created """ uid = uuid.uuid4() subscription, code = payments.subscribe_to_plan( "validcustomer", { "pmt_token": "tok_visa", "plan_id": "plan_EtMcOlFMNWW4nd", "email": "valid@{}customer.com".format(uid), "orig_system": "Test_system", }, ) assert 201 == code payments.cancel_subscription( "validcustomer", subscription["subscriptions"][0]["subscription_id"]) g.subhub_account.remove_from_db("validcustomer")
def test_cancel_subscription_with_valid_data_multiple_subscriptions_remove_second( ): """ GIVEN a user with multiple subscriptions WHEN the second subscription is cancelled THEN the specified subscription is cancelled """ uid = uuid.uuid4() subscription1, code1 = payments.subscribe_to_plan( "valid_customer", { "pmt_token": "tok_visa", "plan_id": "plan_EtMcOlFMNWW4nd", "email": f"valid@{uid}customer.com", "orig_system": "Test_system", "display_name": "Jon Tester", }, ) subscription2, code2 = payments.subscribe_to_plan( "valid_customer", { "pmt_token": "tok_visa", "plan_id": "plan_F4G9jB3x5i6Dpj", "email": f"valid@{uid}customer.com", "orig_system": "Test_system", "display_name": "Jon Tester", }, ) # cancel the second subscription created cancelled, code = payments.cancel_subscription( "valid_customer", subscription2["subscriptions"][0]["subscription_id"]) assert cancelled["message"] == "Subscription cancellation successful" assert 201 == code # clean up test data created cancelled, code = payments.cancel_subscription( "valid_customer", subscription1["subscriptions"][0]["subscription_id"]) g.subhub_account.remove_from_db("valid_customer") assert cancelled["message"] == "Subscription cancellation successful" assert 201 == code
def test_cancel_subscription_with_valid_data( app, create_subscription_for_processing): """ GIVEN should cancel an active subscription WHEN provided a api_token, and subscription id THEN validate should cancel subscription """ (subscription, code) = create_subscription_for_processing (cancelled, code) = payments.cancel_subscription( "process_test", subscription["subscriptions"][0]["subscription_id"]) assert cancelled["message"] == "Subscription cancellation successful" assert 201 == code g.subhub_account.remove_from_db("process_test")