Beispiel #1
0
    def test_upgrade(self):

        security.check(self, UPGRADE_PATH % 2, causes.ssl)
        security.require_ssl(self, UPGRADE_PATH % 2)

        #-------------------------------------------------
        # Show Form
        #-------------------------------------------------
        self.assertState('GET', UPGRADE_PATH % 2, [
            causes.ssl,
            causes.valid_domain,
            causes.owner_logged_in,
            account_has_payment_method,
        ], [effects.rendered('account/upgrade_form.html')])

        #-------------------------------------------------
        # If invalid subscription level, 404 - Not Found
        #-------------------------------------------------
        self.assertState('GET/POST', UPGRADE_PATH % 666, [
            causes.ssl,
            causes.valid_domain,
            causes.owner_logged_in,
            account_has_payment_method,
        ], [effects.status(404)])
        #-------------------------------------------------
        # If account alreay has subscription label, 403 - Forbidden
        #-------------------------------------------------
        self.assertState('POST', UPGRADE_PATH % 1, [
            causes.ssl,
            causes.valid_domain,
            causes.owner_logged_in,
            account_has_payment_method,
        ], [effects.status(403)])
        #-------------------------------------------------
        # If everything is valid, and the account has a
        # RecurringPayment, change level and change payment
        #-------------------------------------------------
        self.assertState('POST', UPGRADE_PATH % 2, [
            causes.ssl,
            account_has_subscription_level(1),
            causes.valid_domain,
            causes.owner_logged_in,
            account_has_payment_method,
        ], [
            gateway_change_called,
            effects.redirected('/account/'),
            subscription_level_is(2)
        ])
        #-------------------------------------------------
        # If the account has an inactive RecurringPayment,
        # new CC info is required
        #-------------------------------------------------
        self.assertState('POST', UPGRADE_PATH % 2, [
            causes.ssl,
            account_has_subscription_level(1), causes.valid_domain,
            causes.owner_logged_in, account_has_inactive_payment_method,
            causes.params(**change_payment_method_params)
        ], [
            gateway_change_called,
            effects.redirected('/account/'),
            subscription_level_is(2)
        ])
        #-------------------------------------------------
        # If the account does not have a RecurringPayment,
        # credit card params are required.
        #-------------------------------------------------
        self.assertState('POST', UPGRADE_PATH % 2, [
            causes.ssl,
            account_has_subscription_level(1),
            causes.valid_domain,
            causes.owner_logged_in,
            account_has_no_payment_method,
        ], [
            effects.rendered('account/upgrade_form.html'),
            subscription_level_is(1)
        ])
        #-------------------------------------------------
        # If the account doesn't have a RecurringPayment,
        # and you've provided billing information, change
        # subscription level.
        #-------------------------------------------------
        self.assertState('POST', UPGRADE_PATH % 2, [
            causes.ssl,
            account_has_subscription_level(1), causes.valid_domain,
            causes.owner_logged_in, account_has_no_payment_method,
            causes.params(**change_payment_method_params)
        ], [
            gateway_start_called,
            effects.redirected('/account/'),
            subscription_level_is(2)
        ])

        #-------------------------------------------------
        # If the gateway returns an unrecognized response,
        # show a special message & email the administrator.
        #-------------------------------------------------
        self.assertState('POST', UPGRADE_PATH % 2, [
            causes.ssl,
            account_has_subscription_level(1),
            causes.valid_domain,
            causes.owner_logged_in,
            account_has_no_payment_method,
            causes.params(**change_payment_method_params),
            payment_response_error,
        ], [
            effects.outbox_len(1),
            effects.rendered('account/payment_create_error.html'),
            subscription_level_is(1)
        ])

        #-------------------------------------------------
        # If the gateway does not accept the payment info,
        # show the form.
        #-------------------------------------------------
        self.assertState('POST', UPGRADE_PATH % 2, [
            causes.ssl,
            account_has_subscription_level(1),
            causes.valid_domain,
            causes.owner_logged_in,
            account_has_no_payment_method,
            causes.params(**change_payment_method_params),
            payment_request_error,
        ], [
            effects.rendered('account/upgrade_form.html'),
            effects.status(200)
        ])
        
    ############################
    # Upgrade Tests
    ############################
    
    def test_upgrade(self):

        security.check(self, UPGRADE_PATH % 2, causes.ssl)
        security.require_ssl(self, UPGRADE_PATH % 2)
            
        #-------------------------------------------------
        # Show Form
        #-------------------------------------------------
        self.assertState(
            'GET',
            UPGRADE_PATH % 2,
            [
                causes.ssl,
                causes.valid_domain,
                causes.owner_logged_in,
                account_has_payment_method,
            ],
            [
                effects.rendered('account/upgrade_form.html')
            ]
        )
        
        #-------------------------------------------------
        # If invalid subscription level, 404 - Not Found
        #-------------------------------------------------
        self.assertState(
            'GET/POST',
            UPGRADE_PATH % 666,
            [
                causes.ssl,
                causes.valid_domain,
                causes.owner_logged_in,
                account_has_payment_method,
            ],
            [
                effects.status(404)
            ]
        )
        #-------------------------------------------------
        # If account alreay has subscription label, 403 - Forbidden
        #-------------------------------------------------
        self.assertState(
            'POST',
            UPGRADE_PATH % 1,
            [
                causes.ssl,
                causes.valid_domain,
                causes.owner_logged_in,
                account_has_payment_method,
            ],
            [
                effects.status(403)
            ]
        )
        #-------------------------------------------------
        # If everything is valid, and the account has a
        # RecurringPayment, change level and change payment
        #-------------------------------------------------
        self.assertState(
            'POST',
            UPGRADE_PATH % 2,
            [
                causes.ssl,
                account_has_subscription_level(1),
                causes.valid_domain,
                causes.owner_logged_in,
                account_has_payment_method,
            ],
            [
                gateway_change_called,
                effects.redirected('/account/'),
                subscription_level_is(2)
            ]
        )
        #-------------------------------------------------
        # If the account has an inactive RecurringPayment, 
        # new CC info is required
        #-------------------------------------------------
        self.assertState(
            'POST',
            UPGRADE_PATH % 2,
            [
                causes.ssl,
                account_has_subscription_level(1),
                causes.valid_domain,
                causes.owner_logged_in,
                account_has_inactive_payment_method,
                causes.params(**change_payment_method_params)
            ],
            [
                gateway_change_called,
                effects.redirected('/account/'),
                subscription_level_is(2)
            ]
        )
        #-------------------------------------------------
        # If the account does not have a RecurringPayment, 
        # credit card params are required. 
        #-------------------------------------------------
        self.assertState(
            'POST',
            UPGRADE_PATH % 2,
            [
                causes.ssl,
                account_has_subscription_level(1),
                causes.valid_domain,
                causes.owner_logged_in,
                account_has_no_payment_method,
            ],
            [
                effects.rendered('account/upgrade_form.html'),
                subscription_level_is(1)
            ]
        )
        #-------------------------------------------------
        # If the account doesn't have a RecurringPayment, 
        # and you've provided billing information, change
        # subscription level.
        #-------------------------------------------------
        self.assertState(
            'POST',
            UPGRADE_PATH % 2,
            [
                causes.ssl,
                account_has_subscription_level(1),
                causes.valid_domain,
                causes.owner_logged_in,
                account_has_no_payment_method,
                causes.params(**change_payment_method_params)
            ],
            [
                gateway_start_called,
                effects.redirected('/account/'),
                subscription_level_is(2)
                
            ]
        )
        
        #-------------------------------------------------
        # If the gateway returns an unrecognized response,
        # show a special message & email the administrator.
        #-------------------------------------------------
        self.assertState(
            'POST',
            UPGRADE_PATH % 2, 
            [
                causes.ssl,
                account_has_subscription_level(1),
                causes.valid_domain,
                causes.owner_logged_in,
                account_has_no_payment_method,
                causes.params(**change_payment_method_params),
                payment_response_error,
            ],
            [
                effects.outbox_len(1),
                effects.rendered('account/payment_create_error.html'),
                subscription_level_is(1)
            ]
        )
        
        #-------------------------------------------------
        # If the gateway does not accept the payment info,
        # show the form.
        #-------------------------------------------------
        self.assertState(
            'POST',
            UPGRADE_PATH % 2,
            [
                causes.ssl,
                account_has_subscription_level(1),
                causes.valid_domain,
                causes.owner_logged_in,
                account_has_no_payment_method,
                causes.params(**change_payment_method_params),
                payment_request_error,
            ],
Beispiel #3
0
    def test_change_payment_method(self):
        security.check_account_inactive_ok(self, CHANGE_PM_PATH, causes.ssl)
        security.require_ssl(self, CHANGE_PM_PATH)

        #-------------------------------------------------
        # The form is shown
        #-------------------------------------------------
        self.assertState('GET/POST', CHANGE_PM_PATH, [
            causes.ssl,
            causes.valid_domain,
            causes.owner_logged_in,
            causes.no_parameters,
        ], [
            effects.rendered('account/payment_method_form.html'),
            effects.status(200)
        ])

        #-------------------------------------------------
        # The form is shown if input is invalid
        #-------------------------------------------------
        self.assertState('POST', CHANGE_PM_PATH, [
            causes.ssl, causes.valid_domain, causes.owner_logged_in,
            causes.no_parameters,
            causes.params(first_name='billy',
                          last_name='bob',
                          card_number='411111111111',
                          card_expiration=None)
        ], [
            effects.rendered('account/payment_method_form.html'),
            effects.status(200)
        ])

        #-------------------------------------------------
        # If input is valid, a RecurringPayment is created
        #-------------------------------------------------
        self.assertState('POST', CHANGE_PM_PATH, [
            causes.ssl,
            causes.valid_domain,
            causes.owner_logged_in,
            causes.no_parameters,
            causes.params(first_name='billy',
                          last_name='bob',
                          card_number='411111111111',
                          card_expiration=date.today()),
            account_has_no_payment_method,
        ], [
            effects.exists(RecurringPayment, account__subdomain='starr'),
            effects.rendered('account/payment_method_form.html'),
            effects.status(200)
        ])

        #-------------------------------------------------
        # If input is valid, and a RecurringPayment exists,
        # the old RecurringPayment is deleted and a new one
        # is created.
        #-------------------------------------------------
        self.assertState('POST', CHANGE_PM_PATH, [
            causes.ssl,
            causes.valid_domain,
            causes.owner_logged_in,
            causes.no_parameters,
            causes.params(**change_payment_method_params),
            account_has_payment_method,
        ], [
            gateway_cancel_called, new_payment_starts_when_old_one_stops,
            effects.exists(RecurringPayment, account__pk=1),
            effects.rendered('account/payment_method_form.html'),
            effects.status(200)
        ])

        #-------------------------------------------------
        # If we get a PeymentRequestError, it means that
        # the user probably entered some invalid info.
        # If the payment gateway returned this error, a
        # RecurringPayment is NOT created.
        #-------------------------------------------------

        self.assertState('POST', CHANGE_PM_PATH, [
            causes.ssl,
            causes.valid_domain,
            causes.owner_logged_in,
            causes.no_parameters,
            causes.params(**change_payment_method_params),
            account_has_no_payment_method,
            payment_request_error,
        ], [
            gateway_cancel_called,
            effects.does_not_exist(
                RecurringPayment,
                account__pk=1,
            ),
            effects.does_not_exist(RecurringPayment, name='billy bob'),
            effects.rendered('account/payment_method_form.html'),
            effects.status(200)
        ])

        #-------------------------------------------------
        # If we get a PeymentRequestError, it means that
        # the user probably entered some invalid info.
        # If the payment gateway returned this error, AND a
        # RecurringPayment exists for the account, do NOT
        # delete it.
        #-------------------------------------------------
        self.assertState('POST', CHANGE_PM_PATH, [
            causes.ssl,
            causes.valid_domain,
            causes.owner_logged_in,
            causes.no_parameters,
            causes.params(**change_payment_method_params),
            account_has_payment_method,
            payment_request_error,
        ], [
            gateway_cancel_called,
            effects.exists(
                RecurringPayment,
                account__pk=1,
            ),
            effects.count(1, RecurringPayment, name='Bob Jones'),
            effects.count(0, RecurringPayment, name='billy bob'),
            effects.rendered('account/payment_method_form.html'),
            effects.status(200)
        ])

        #-------------------------------------------------
        # If there is a PaymentResponse error, it means
        # we couldn't understand the response from the
        # gateway. So a special error page is displayed
        # and the administrator is emailed.
        #-------------------------------------------------

        self.assertState('POST', CHANGE_PM_PATH, [
            causes.ssl,
            causes.valid_domain,
            causes.owner_logged_in,
            causes.no_parameters,
            causes.params(**change_payment_method_params),
            account_has_payment_method,
            payment_response_error,
        ], [
            gateway_cancel_called,
            effects.exists(
                RecurringPayment,
                account__pk=1,
            ),
            effects.outbox_len(1),
            effects.count(1, RecurringPayment, name='Bob Jones'),
            effects.count(0, RecurringPayment, name='billy bob'),
            effects.rendered('account/payment_create_error.html'),
            effects.status(200)
        ])

        #-------------------------------------------------
        # If there is a PaymentResponse error when canceling
        # an existing payment, it is very bad. It means that
        # the customer will be billed twice! So we diaplay a
        # special error message, and email the administrator.
        #-------------------------------------------------
        self.assertState('POST', CHANGE_PM_PATH, [
            causes.ssl,
            causes.valid_domain,
            causes.owner_logged_in,
            causes.no_parameters,
            causes.params(**change_payment_method_params),
            account_has_payment_method,
            payment_response_error_on_cancel,
        ], [
            gateway_cancel_called,
            effects.exists(
                RecurringPayment,
                account__pk=1,
            ),
            effects.outbox_len(1),
            effects.count(0, RecurringPayment, name='Bob Jones'),
            effects.count(1, RecurringPayment, name='billy bob'),
            effects.rendered('account/payment_cancel_error.html'),
            effects.status(200)
        ])
     
 ############################
 # Change Payment Method Tests
 ############################
     
 def test_change_payment_method(self):
     security.check_account_inactive_ok(self, CHANGE_PM_PATH, causes.ssl)
     security.require_ssl(self, CHANGE_PM_PATH)
         
     #-------------------------------------------------
     # The form is shown
     #-------------------------------------------------
     self.assertState(
         'GET/POST',
         CHANGE_PM_PATH,
         [
             causes.ssl,
             causes.valid_domain,
             causes.owner_logged_in,
             causes.no_parameters,
         ],
         [
             effects.rendered('account/payment_method_form.html'),
             effects.status(200)
         ]
     )
     
         
     #-------------------------------------------------
     # The form is shown if input is invalid
     #-------------------------------------------------
     self.assertState(
         'POST',
         CHANGE_PM_PATH,
         [
             causes.ssl,
             causes.valid_domain,
             causes.owner_logged_in,
             causes.no_parameters,
             causes.params(
                 first_name = 'billy',
                 last_name = 'bob',                    
                 card_number = '411111111111',
                 card_expiration = None
             )
         ],
         [
             effects.rendered('account/payment_method_form.html'),
             effects.status(200)
         ]
     )
     
     #-------------------------------------------------
     # If input is valid, a RecurringPayment is created
     #-------------------------------------------------
     self.assertState(
         'POST',
         CHANGE_PM_PATH,
         [
             causes.ssl,
             causes.valid_domain,
             causes.owner_logged_in,
             causes.no_parameters,
             causes.params(
                 first_name = 'billy',
                 last_name = 'bob',                    
                 card_number = '411111111111',
                 card_expiration = date.today()
             ),
             account_has_no_payment_method,
         ],
         [
             effects.exists(
                 RecurringPayment, 
                 account__subdomain = 'starr'
             ),
             effects.rendered('account/payment_method_form.html'),
             effects.status(200)
         ]
     )
     
         
     #-------------------------------------------------
     # If input is valid, and a RecurringPayment exists,
     # the old RecurringPayment is deleted and a new one
     # is created.
     #-------------------------------------------------
     self.assertState(
         'POST',
         CHANGE_PM_PATH,
         [
             causes.ssl,
             causes.valid_domain,
             causes.owner_logged_in,
             causes.no_parameters,
             causes.params(**change_payment_method_params),
             account_has_payment_method,
         ],
         [
             gateway_cancel_called,
             new_payment_starts_when_old_one_stops,
             effects.exists(RecurringPayment, account__pk = 1),
             effects.rendered('account/payment_method_form.html'),
             effects.status(200)
         ]
     )
     
     #-------------------------------------------------
     # If we get a PeymentRequestError, it means that
     # the user probably entered some invalid info.
     # If the payment gateway returned this error, a 
     # RecurringPayment is NOT created.
     #-------------------------------------------------
     
     self.assertState(
         'POST',
         CHANGE_PM_PATH,
         [
             causes.ssl,
             causes.valid_domain,
             causes.owner_logged_in,
             causes.no_parameters,
             causes.params(**change_payment_method_params),
             account_has_no_payment_method,
             payment_request_error,
         
         ],
         [
             gateway_cancel_called,
             effects.does_not_exist(
                 RecurringPayment, 
                 account__pk = 1,
             ),
             effects.does_not_exist(
                 RecurringPayment, 
                 name = 'billy bob'
             ),
             effects.rendered('account/payment_method_form.html'),
             effects.status(200)
         ]
     )
     
     #-------------------------------------------------
     # If we get a PeymentRequestError, it means that
     # the user probably entered some invalid info.
     # If the payment gateway returned this error, AND a
     # RecurringPayment exists for the account, do NOT
     # delete it.
     #-------------------------------------------------
     self.assertState(
         'POST',
         CHANGE_PM_PATH,
         [
             causes.ssl,
             causes.valid_domain,
             causes.owner_logged_in,
             causes.no_parameters,
             causes.params(**change_payment_method_params),
             account_has_payment_method,
             payment_request_error,
         
         ],
         [
             gateway_cancel_called,
             effects.exists(
                 RecurringPayment, 
                 account__pk = 1,
             ),
             effects.count(1, RecurringPayment, name = 'Bob Jones'),
             effects.count(0, RecurringPayment, name = 'billy bob'),
             effects.rendered('account/payment_method_form.html'),
             effects.status(200)
         ]
     )
     
     #-------------------------------------------------
     # If there is a PaymentResponse error, it means
     # we couldn't understand the response from the 
     # gateway. So a special error page is displayed
     # and the administrator is emailed.
     #-------------------------------------------------
     
     self.assertState(
         'POST',
         CHANGE_PM_PATH,
         [
             causes.ssl,
             causes.valid_domain,
             causes.owner_logged_in,
             causes.no_parameters,
             causes.params(**change_payment_method_params),
             account_has_payment_method,
             payment_response_error,
         
         ],
         [
             gateway_cancel_called,
             effects.exists(
                 RecurringPayment, 
                 account__pk = 1,
             ),
             effects.outbox_len(1),
             effects.count(1, RecurringPayment, name = 'Bob Jones'),
             effects.count(0, RecurringPayment, name = 'billy bob'),
             effects.rendered('account/payment_create_error.html'),
             effects.status(200)
         ]
     )
     
     #-------------------------------------------------
     # If there is a PaymentResponse error when canceling
     # an existing payment, it is very bad. It means that 
     # the customer will be billed twice! So we diaplay a
     # special error message, and email the administrator.
     #-------------------------------------------------
     self.assertState(
         'POST',
         CHANGE_PM_PATH,
         [
             causes.ssl,
             causes.valid_domain,
             causes.owner_logged_in,
             causes.no_parameters,
             causes.params(**change_payment_method_params),
             account_has_payment_method,
             payment_response_error_on_cancel,
         
         ],
         [
             gateway_cancel_called,
             effects.exists(
                 RecurringPayment, 
                 account__pk = 1,
             ),
             effects.outbox_len(1),
             effects.count(0, RecurringPayment, name = 'Bob Jones'),