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) ])
def test_signup(self): #------------------------------------------------- # If ssl is not on for GET, redirect to ssl page #------------------------------------------------- self.assertState('GET', CREATE_PATH % 1, [ causes.no_domain, causes.no_parameters, ], [effects.redirected(CREATE_PATH % 1, status=301, ssl=True)]) #------------------------------------------------- # If ssl is not on for POST, 403 Forbidden #------------------------------------------------- self.assertState('POST', CREATE_PATH % 1, [ causes.no_domain, causes.no_parameters, ], [effects.status(403)]) #------------------------------------------------- # You can't sign up from a domain belonging # to an account. #------------------------------------------------- self.assertState('GET/POST', CREATE_PATH % 0, [ causes.ssl, causes.person_not_logged_in, causes.valid_domain, ], [ effects.status(404), ]) #------------------------------------------------- # Show the signup form #------------------------------------------------- self.assertState('GET/POST', CREATE_PATH % 0, [ causes.ssl, causes.no_domain, causes.no_parameters, ], [effects.rendered('account/signup_form.html'), effects.status(200)]) #------------------------------------------------- # If the subscription level is invaid, show 404 #------------------------------------------------- self.assertState( 'GET/POST', CREATE_PATH % 789, # 789 is invalid subscription level [ causes.ssl, causes.no_domain, causes.no_parameters, ], [effects.status(404)]) #------------------------------------------------- # If the subscription level is free, a credit # card is not required. #------------------------------------------------- self.assertState( 'POST', CREATE_PATH % 0, # 0 is Free Account [ causes.ssl, delete_test_account, causes.no_domain, causes.params(**signup_params_no_cc), ], [ effects.redirected_to_url("http://%s/" % domain), effects.exists( Account, subdomain=signup_params_no_cc['subdomain'], domain=signup_params_no_cc['domain'], ), effects.exists(Person, email='*****@*****.**'), effects.person_has_role('account_admin', username='******'), ]) #------------------------------------------------- # If the subscription level is NOT free, a credit # card IS required. #------------------------------------------------- self.assertState( 'POST', CREATE_PATH % 1, # 1 is Silver (pay) account [ causes.ssl, delete_test_account, causes.no_domain, causes.params(**signup_params_no_cc), ], [ effects.rendered('account/signup_form.html'), effects.does_not_exist(Person, email='*****@*****.**'), effects.does_not_exist( Account, subdomain=signup_params_no_cc['subdomain'], domain=signup_params_no_cc['domain'], ), effects.status(200) ]) #------------------------------------------------- # If everything validates, create a person, account # and recurring payment. #------------------------------------------------- self.assertState( 'POST', CREATE_PATH % 1, # 1 is Silver (pay) account [ causes.ssl, delete_test_account, causes.no_domain, causes.params(**signup_params_no_cc), causes.params(**cc_params), ], [ effects.redirected_to_url("http://%s/" % domain), effects.exists( Account, subdomain=signup_params_no_cc['subdomain'], domain=signup_params_no_cc['domain'], ), effects.exists(Person, email='*****@*****.**'), effects.person_has_role('account_admin', username='******'), effects.exists(RecurringPayment, name='billy bob'), ]) #------------------------------------------------- # If the gateway returns an unrecognized response, # show a special message & email the administrator. #------------------------------------------------- self.assertState( 'POST', CREATE_PATH % 1, # 1 is Silver (pay) account [ causes.ssl, delete_test_account, causes.no_domain, causes.params(**signup_params_no_cc), causes.params(**cc_params), payment_response_error ], [ effects.outbox_len(1), effects.rendered('account/payment_create_error.html'), ]) #------------------------------------------------- # If the gateway does not accept the payment info, # show the form. #------------------------------------------------- self.assertState( 'POST', CREATE_PATH % 1, # 1 is Silver (pay) account [ causes.ssl, delete_test_account, causes.no_domain, causes.params(**signup_params_no_cc), causes.params(**cc_params), payment_request_error, ], [ effects.rendered('account/signup_form.html'), effects.status(200) ])
############################ # Signup Tests ############################ def test_signup(self): #------------------------------------------------- # If ssl is not on for GET, redirect to ssl page #------------------------------------------------- self.assertState( 'GET', CREATE_PATH % 1, [ causes.no_domain, causes.no_parameters, ], [ effects.redirected(CREATE_PATH % 1, status = 301, ssl = True) ] ) #------------------------------------------------- # If ssl is not on for POST, 403 Forbidden #------------------------------------------------- self.assertState( 'POST', CREATE_PATH % 1, [ causes.no_domain, causes.no_parameters, ], [ effects.status(403) ] ) #------------------------------------------------- # You can't sign up from a domain belonging # to an account. #------------------------------------------------- self.assertState( 'GET/POST', CREATE_PATH % 0, [ causes.ssl, causes.person_not_logged_in, causes.valid_domain, ], [ effects.status(404), ] ) #------------------------------------------------- # Show the signup form #------------------------------------------------- self.assertState( 'GET/POST', CREATE_PATH % 0, [ causes.ssl, causes.no_domain, causes.no_parameters, ], [ effects.rendered('account/signup_form.html'), effects.status(200) ] ) #------------------------------------------------- # If the subscription level is invaid, show 404 #------------------------------------------------- self.assertState( 'GET/POST', CREATE_PATH % 789, # 789 is invalid subscription level [ causes.ssl, causes.no_domain, causes.no_parameters, ], [ effects.status(404) ] ) #------------------------------------------------- # If the subscription level is free, a credit # card is not required. #------------------------------------------------- self.assertState( 'POST', CREATE_PATH % 0, # 0 is Free Account [ causes.ssl, delete_test_account, causes.no_domain, causes.params(**signup_params_no_cc), ], [ effects.redirected_to_url( "http://%s/" % domain ), effects.exists( Account, subdomain = signup_params_no_cc['subdomain'], domain = signup_params_no_cc['domain'], ), effects.exists(Person, email = '*****@*****.**'), effects.person_has_role('account_admin', username = '******'), ] ) #------------------------------------------------- # If the subscription level is NOT free, a credit # card IS required. #------------------------------------------------- self.assertState( 'POST', CREATE_PATH % 1, # 1 is Silver (pay) account [ causes.ssl, delete_test_account, causes.no_domain, causes.params(**signup_params_no_cc), ], [ effects.rendered('account/signup_form.html'), effects.does_not_exist(Person, email = '*****@*****.**'), effects.does_not_exist( Account, subdomain = signup_params_no_cc['subdomain'], domain = signup_params_no_cc['domain'], ), effects.status(200) ] ) #------------------------------------------------- # If everything validates, create a person, account # and recurring payment. #------------------------------------------------- self.assertState( 'POST', CREATE_PATH % 1, # 1 is Silver (pay) account [ causes.ssl, delete_test_account, causes.no_domain, causes.params(**signup_params_no_cc), causes.params(**cc_params), ], [ effects.redirected_to_url( "http://%s/" % domain ), effects.exists( Account, subdomain = signup_params_no_cc['subdomain'], domain = signup_params_no_cc['domain'], ), effects.exists(Person, email = '*****@*****.**'), effects.person_has_role('account_admin', username = '******'), effects.exists(RecurringPayment, name = 'billy bob'), ] ) #------------------------------------------------- # If the gateway returns an unrecognized response, # show a special message & email the administrator. #------------------------------------------------- self.assertState( 'POST', CREATE_PATH % 1, # 1 is Silver (pay) account [ causes.ssl, delete_test_account, causes.no_domain, causes.params(**signup_params_no_cc), causes.params(**cc_params), payment_response_error ], [ effects.outbox_len(1), effects.rendered('account/payment_create_error.html'), ] ) #------------------------------------------------- # If the gateway does not accept the payment info, # show the form. #------------------------------------------------- self.assertState( 'POST', CREATE_PATH % 1, # 1 is Silver (pay) account [ causes.ssl, delete_test_account, causes.no_domain, causes.params(**signup_params_no_cc), causes.params(**cc_params), payment_request_error, ],
############################ # 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'),
def test_destroy(self): """ Tests for profile.destroy """ security.check(self, DESTROY_PATH) self.assertState( 'GET', DESTROY_PATH, [ causes.owner_logged_in, causes.valid_domain, ], [ effects.rendered('account/confirm_destroy.html') ] ) self.assertState( 'POST', DESTROY_PATH_INVALID, [ causes.owner_logged_in, causes.valid_domain, ], [ effects.status(404), ] ) self.assertState( 'POST', DESTROY_PATH_MISMATCH, [ causes.owner_logged_in, causes.valid_domain, ], [ effects.status(404), ] ) self.assertState( 'POST', DESTROY_PATH, [ causes.owner_logged_in, causes.valid_domain, ], [ effects.does_not_exist(Person, id = 1), effects.redirected('/person/list/') ] ) self.assertState( 'POST', DESTROY_PATH_OWNER, [ causes.owner_logged_in, causes.valid_domain, ], [ effects.exists(Person, id = 2), effects.status(403)