Exemplo n.º 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])),
        ])
     
 ############################
 # 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(
Exemplo n.º 3
0
    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,
         ],