Beispiel #1
0
    def test_cancel_payment_method(self):
        security.check(self, CANCEL_PM_PATH)

        #-------------------------------------------------
        # If the account does NOT have a RecurringPayment,
        # then the account is deactivated immediately.
        #-------------------------------------------------
        self.assertState('POST', CANCEL_PM_PATH, [
            causes.valid_domain,
            causes.owner_logged_in,
            account_has_no_payment_method,
        ], [
            effects.field_value(Account, {'pk': 1}, active=False),
            effects.redirected('/account/reactivate_free_account/')
        ])

        #-------------------------------------------------
        # If the account has a RecurringPayment, show the form
        #-------------------------------------------------
        self.assertState('GET', CANCEL_PM_PATH, [
            causes.valid_domain,
            causes.owner_logged_in,
            account_has_payment_method,
        ], [
            effects.field_value(Account, {'pk': 1}, active=True),
            effects.rendered('account/payment_cancel_form.html'),
            effects.status(200)
        ])

        #-------------------------------------------------
        # If the account does not have a RecurringPayment, show the form
        #-------------------------------------------------
        self.assertState('GET', CANCEL_PM_PATH, [
            causes.valid_domain,
            causes.owner_logged_in,
            account_has_no_payment_method,
        ], [
            effects.field_value(Account, {'pk': 1}, active=True),
            effects.rendered('account/payment_cancel_form.html'),
            effects.status(200)
        ])

        #-------------------------------------------------
        # If the form is posted, and a payment exists, the
        # payment is canceled. Note that it is not deleted.
        # Instead, the inactive flag is set, which triggers
        # the account for suspension whenever payment runs
        # out.
        #-------------------------------------------------
        self.assertState('POST', CANCEL_PM_PATH, [
            causes.valid_domain,
            causes.owner_logged_in,
            account_has_payment_method,
        ], [
            effects.field_value(Account, {'pk': 1}, active=True),
            effects.redirected('/account/'),
            effects.count(1, RecurringPayment, account__pk=1),
            payment_is_inactive,
        ])

        #-------------------------------------------------
        # If a gateway error is returned on cancel, show
        # the error page and email admin
        #-------------------------------------------------
        self.assertState('POST', CANCEL_PM_PATH, [
            causes.valid_domain,
            causes.owner_logged_in,
            account_has_payment_method,
            payment_response_error_on_cancel,
        ], [
            effects.field_value(Account, {'pk': 1}, active=True),
            effects.outbox_len(1),
            effects.rendered('account/payment_cancel_error.html'),
            effects.count(1, RecurringPayment, account__pk=1),
            payment_is_active,
        ])
     
 ############################
 # Cancel Payment Method Tests
 ############################
     
 def test_cancel_payment_method(self):
     security.check(self, CANCEL_PM_PATH)
     
     #-------------------------------------------------
     # If the account does NOT have a RecurringPayment, 
     # then the account is deactivated immediately.
     #-------------------------------------------------
     self.assertState(
         'POST',
         CANCEL_PM_PATH,
         [
             causes.valid_domain,
             causes.owner_logged_in,
             account_has_no_payment_method,
         ],
         [
             effects.field_value(Account, {'pk': 1}, active = False),
             effects.redirected('/account/reactivate_free_account/')
         ]
     )
     
     #-------------------------------------------------
     # If the account has a RecurringPayment, show the form
     #-------------------------------------------------
     self.assertState(
         'GET',
         CANCEL_PM_PATH,
         [
             causes.valid_domain,
             causes.owner_logged_in,
             account_has_payment_method,
         ],
         [
             effects.field_value(Account, {'pk': 1}, active = True),
             effects.rendered('account/payment_cancel_form.html'),
             effects.status(200)
         ]
     )
     
     #-------------------------------------------------
     # If the account does not have a RecurringPayment, show the form
     #-------------------------------------------------
     self.assertState(
         'GET',
         CANCEL_PM_PATH,
         [
             causes.valid_domain,
             causes.owner_logged_in,
             account_has_no_payment_method,
         ],
         [
             effects.field_value(Account, {'pk': 1}, active = True),
             effects.rendered('account/payment_cancel_form.html'),
             effects.status(200)
         ]
     )
         
     #-------------------------------------------------
     # If the form is posted, and a payment exists, the
     # payment is canceled. Note that it is not deleted.
     # Instead, the inactive flag is set, which triggers
     # the account for suspension whenever payment runs
     # out. 
     #-------------------------------------------------
     self.assertState(
         'POST',
         CANCEL_PM_PATH,
         [
             causes.valid_domain,
             causes.owner_logged_in,
             account_has_payment_method,
         ],
         [
             effects.field_value(Account, {'pk': 1}, active = True),
             effects.redirected('/account/'),
             effects.count(1, RecurringPayment, account__pk = 1),
             payment_is_inactive,
             
         ]
     )
     
     #-------------------------------------------------
     # If a gateway error is returned on cancel, show
     # the error page and email admin
     #-------------------------------------------------
     self.assertState(
         'POST',
         CANCEL_PM_PATH,
         [
             causes.valid_domain,
             causes.owner_logged_in,
             account_has_payment_method,
             payment_response_error_on_cancel,
         ],
         [
             effects.field_value(Account, {'pk': 1}, active = True),
             effects.outbox_len(1),
             effects.rendered('account/payment_cancel_error.html'),
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'),