def test_delete_subscription(authenticated_client_with_customer_id, stripe_subscription_product_id, user_with_customer_id, subscription_id): response = make_request(authenticated_client_with_customer_id.delete, "subscriptions", 200, signal=signals.subscription_cancelled, url_params={'obj_id': subscription_id}) assert response.data['status'] == 'canceled' response = payments.is_subscribed_and_cancelled_time(user_with_customer_id, stripe_subscription_product_id) assert response['sub_id'] is None assert response['cancel_at'] is None
def test_delete_other_user_subscription(authenticated_client_second_user, user_with_customer_id, stripe_subscription_product_id, payment_method_id, subscription_id, not_owned_subscription_error): response = make_request(authenticated_client_second_user.delete, "subscriptions", 500, url_params={'obj_id': subscription_id}) assert response.data == not_owned_subscription_error response = payments.is_subscribed_and_cancelled_time(user_with_customer_id, stripe_subscription_product_id) assert response['sub_id'] == subscription_id assert response['cancel_at'] is None
def test_new_subscription_no_payment_method(authenticated_client_with_customer_id, user_with_customer_id, stripe_price_id, stripe_subscription_product_id, no_default_payment_method_error): response = make_request(authenticated_client_with_customer_id.post, "subscriptions", 500, price_id=stripe_price_id) assert response.data == no_default_payment_method_error response = payments.is_subscribed_and_cancelled_time(user_with_customer_id, stripe_subscription_product_id) assert response['sub_id'] is None assert response['cancel_at'] is None
def test_is_subscribed(user_with_customer_id, subscription_id, stripe_subscription_product_id, stripe_price_id): is_subscribed = payments.is_subscribed_and_cancelled_time( user_with_customer_id, stripe_subscription_product_id) assert is_subscribed['sub_id'] == subscription_id assert is_subscribed['cancel_at'] is None assert is_subscribed['evaluation'] is False assert is_subscribed['price_id'] == stripe_price_id assert subscriptions.is_subscribed(user_with_customer_id, stripe_subscription_product_id)
def test_new_subscription_change_default_payment_method_with_no_payment_method( authenticated_client_with_customer_id, stripe_price_id, stripe_subscription_product_id, user_with_customer_id, no_default_payment_method_to_set_as_default_error): response = make_request(authenticated_client_with_customer_id.post, "subscriptions", 400, price_id=stripe_price_id, set_as_default_payment_method=True) assert response.data == no_default_payment_method_to_set_as_default_error response = payments.is_subscribed_and_cancelled_time(user_with_customer_id, stripe_subscription_product_id) assert response['sub_id'] is None assert response['cancel_at'] is None customer = stripe.Customer.retrieve(user_with_customer_id.stripe_customer_id) assert customer['invoice_settings']['default_payment_method'] == None
def test_is_subscribed_allowed_access_until(user_allowed_access_until, stripe_subscription_product_id): sub_info = payments.is_subscribed_and_cancelled_time( user_allowed_access_until) assert sub_info == { 'sub_id': payments.FREE, 'cancel_at': None, 'current_period_end': 1924905599, 'evaluation': True, 'product_id': stripe_subscription_product_id, 'price_id': None } assert payments.is_subscribed(user_allowed_access_until, stripe_subscription_product_id)
def test_is_not_subscribed(no_user_and_user_with_and_without_customer_id, stripe_subscription_product_id, stripe_price_id): sub_info = payments.is_subscribed_and_cancelled_time( no_user_and_user_with_and_without_customer_id, stripe_subscription_product_id) assert sub_info == { 'sub_id': None, 'cancel_at': None, 'current_period_end': None, 'evaluation': False, 'product_id': None, 'price_id': None } assert subscriptions.is_subscribed( no_user_and_user_with_and_without_customer_id, stripe_subscription_product_id) is False
def test_modify_subscription(authenticated_client_with_customer_id, stripe_subscription_product_id, payment_method_id, user_with_customer_id, subscription, subscription_response_alternative_payment_method, data, customer_default_payment_methods): response = make_request(authenticated_client_with_customer_id.put, "subscriptions", 200, signal=signals.subscription_modified, url_params={'obj_id': subscription['id']}, default_payment_method=payment_method_id, **data) sub_id = response.data['id'] assert response.data.pop('current_period_start') is not None assert response.data.pop('id') is not None assert response.data.pop('latest_invoice') is not None assert response.data.pop('start_date') is not None assert response.data.pop('created') is not None assert response.data == subscription_response_alternative_payment_method response = payments.is_subscribed_and_cancelled_time(user_with_customer_id, stripe_subscription_product_id) assert response['sub_id'] == sub_id assert response['cancel_at'] is None customer = stripe.Customer.retrieve(user_with_customer_id.stripe_customer_id) assert customer['invoice_settings']['default_payment_method'] == customer_default_payment_methods