Beispiel #1
0
    def test_edit_account(self):
        security.check(self, EDIT_ACCOUNT_PATH)

        #-------------------------------------------------
        # Show the form when no params
        #-------------------------------------------------
        self.assertState('GET/POST', EDIT_ACCOUNT_PATH, [
            causes.valid_domain,
            causes.owner_logged_in,
            causes.no_parameters,
        ], [
            effects.status(200),
            effects.rendered('account/account_form.html'),
        ])

        #-------------------------------------------------
        # Show the form when invalid params
        #-------------------------------------------------
        self.assertState('POST', EDIT_ACCOUNT_PATH, [
            causes.valid_domain,
            causes.owner_logged_in,
            causes.params(domain='---', ),
        ], [
            effects.status(200),
            effects.rendered('account/account_form.html'),
        ])
        #-------------------------------------------------
        # If everything's valid, changes are saved
        # The user is redirected to the subdomain.domain
        #-------------------------------------------------
        edit_account_params = dict(
            subdomain='newname',
            domain=settings.ACCOUNT_DOMAINS[1][0],
            name='newname',
            timezone=settings.ACCOUNT_TIME_ZONES[1][0],
        )
        self.assertState('POST', EDIT_ACCOUNT_PATH, [
            causes.valid_domain,
            causes.owner_logged_in,
            causes.params(**edit_account_params),
        ], [
            effects.field_value(Account, {'pk': 1}, **edit_account_params),
            effects.redirected_to_url('http://%s.%s/account/' %
                                      (edit_account_params['subdomain'],
                                       settings.ACCOUNT_DOMAINS[1][0])),
        ])
Beispiel #2
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'),
     
 ############################
 # Edit account Tests
 ############################
     
 def test_edit_account(self):
     security.check(self, EDIT_ACCOUNT_PATH)
     
     #-------------------------------------------------
     # Show the form when no params
     #-------------------------------------------------
     self.assertState(
         'GET/POST',
         EDIT_ACCOUNT_PATH,
         [
             causes.valid_domain,
             causes.owner_logged_in,
             causes.no_parameters,
         ],
         [
             effects.status(200),
             effects.rendered('account/account_form.html'),
         ]
     )
     
     #-------------------------------------------------
     # Show the form when invalid params
     #-------------------------------------------------
     self.assertState(
         'POST',
         EDIT_ACCOUNT_PATH,
         [
             causes.valid_domain,
             causes.owner_logged_in,
             causes.params(
                 domain = '---',
             ),
         ],
         [
             effects.status(200),
             effects.rendered('account/account_form.html'),
         ]
     )
     #-------------------------------------------------
     # If everything's valid, changes are saved
     # The user is redirected to the subdomain.domain
     #-------------------------------------------------
     edit_account_params = dict(
         subdomain = 'newname',
         domain = settings.ACCOUNT_DOMAINS[1][0],
         name = 'newname',
         timezone = settings.ACCOUNT_TIME_ZONES[1][0],
     )
     self.assertState(
         'POST',
         EDIT_ACCOUNT_PATH,
         [
             causes.valid_domain,
             causes.owner_logged_in,
             causes.params(**edit_account_params),
         ],
         [
             effects.field_value(
                 Account, 
                 {'pk': 1}, 
                 **edit_account_params
             ),
             effects.redirected_to_url(
 
 
 def test_edit(self):
     security.check(self, EDIT_PATH)
     
     #-------------------------------------------------
     # Show the form
     #-------------------------------------------------
     self.assertState(
         'GET',
         EDIT_PATH,
         [
             causes.owner_logged_in,
             causes.valid_domain,
         ],
         [
             effects.rendered('account/person_form.html'),
             effects.context('form', type = forms.BaseForm),
             effects.status(200),
         ]
     )
     #-------------------------------------------------
     # If the person does not exist, 404
     #-------------------------------------------------
     self.assertState(
         'GET/POST',
         EDIT_PATH_INVALID,
         [
             causes.owner_logged_in,
             causes.valid_domain,
         ],
         [
             effects.status(404),
         ]
     )
     #-------------------------------------------------
     # If the person does not belong to the account 404
     #-------------------------------------------------
     self.assertState(
         'GET/POST',
         EDIT_PATH_MISMATCH,
         [
             causes.owner_logged_in,
             causes.valid_domain,
         ],
         [
             effects.status(404),
         ]
     )
     #-------------------------------------------------
     # If invalid input, show form
     #-------------------------------------------------
     self.assertState(
         'POST',
         EDIT_PATH,
         [
             causes.owner_logged_in,
             causes.valid_domain,
             causes.invalid_create_person_parameters,
         ],
         [
             effects.rendered('account/person_form.html'),
             effects.context('form', type = forms.BaseForm),
             effects.form_errors('form'),
             effects.status(200),
         ]
     )
     
     #-------------------------------------------------
     # If valid, save changes
     #-------------------------------------------------
     self.assertState(
         'POST',
         EDIT_PATH,
         [
             causes.alters(Person),
             causes.owner_logged_in,
             causes.valid_domain,
             causes.params(
                 username = '******',
                 new_password = '',
                 new_password_confirm = '',
                 first_name = 'bob',
                 last_name = 'jones',
                 email = '*****@*****.**',
             ),
         ],
         [
             effects.field_value(Person, {'pk':1}, first_name = 'bob'),
             effects.person_has_password(1, 'password'),
             effects.redirected('/person/list/'),
         ]
     )
     
     #-------------------------------------------------
     # If valid, save changes
     #-------------------------------------------------
     self.assertState(
         'POST',
         EDIT_PATH,
         [
             causes.alters(Person),
             causes.owner_logged_in,
             causes.valid_domain,
             causes.params(
                 username = '******',
                 new_password = '******',
                 new_password_confirm = 'anewpassword',
                 first_name = 'bob',
                 last_name = 'jones',
                 email = '*****@*****.**',
             ),
         ],
         [
             effects.person_has_password(1, 'anewpassword'),
             effects.field_value(Person, {'pk':1}, first_name = 'bob'),
             effects.redirected('/person/list/'),
         ]
     )
     #-------------------------------------------------
     # Edit does not require pasword, does not change
     # if one is not provided.
     #-------------------------------------------------
     self.assertState(
         'POST',
         EDIT_PATH,
         [
             causes.alters(Person),
             causes.owner_logged_in,
             causes.valid_domain,
             causes.params(
                 username = '******',
                 new_password = '',
                 new_password_confirm = '',
                 first_name = 'bob',
                 last_name = 'jones',
                 email = '*****@*****.**',
             ),
         ],
         [
             effects.person_has_password(1, 'anewpassword'),
             effects.field_value(Person, {'pk':1}, first_name = 'bob'),
             effects.redirected('/person/list/'),
         ]
     )
     #-------------------------------------------------
     # If passwords didn't match, show form
     #-------------------------------------------------
     self.assertState(
         'POST',
         EDIT_PATH,
         [
             causes.alters(Person),
             causes.owner_logged_in,
             causes.valid_domain,
             causes.params(
                 username = '******',
                 new_password = '******',
                 new_password_confirm = 'does_not_match',
                 first_name = 'bob',
                 last_name = 'jones',
                 email = '*****@*****.**',
             ),
         ],
         [
             effects.rendered('account/person_form.html'),
             effects.context('form', type = forms.BaseForm),
             effects.form_errors('form'),
             effects.status(200),