def test_logout(self):
     """
     Tests for person_views.logout
     """
     self.assertState(
         "GET/POST",
         LOGOUT_PATH,
         [causes.person_not_logged_in, causes.invalid_domain],
         [effects.not_logged_in, effects.status(404)],
     )
     self.assertState(
         "GET/POST", LOGOUT_PATH, [causes.person_not_logged_in, causes.no_domain], [effects.status(404)]
     )
     self.assertState(
         "GET/POST",
         LOGOUT_PATH,
         [causes.person_not_logged_in, causes.valid_domain],
         [effects.not_logged_in, effects.redirected(LOGIN_PATH, ssl=True)],
     )
     self.assertState(
         "POST",
         LOGOUT_PATH,
         [causes.person_logged_in, causes.valid_domain],
         [effects.not_logged_in, effects.redirected(LOGIN_PATH, ssl=True)],
     )
     self.assertState(
         "GET", LOGOUT_PATH, [causes.person_logged_in, causes.valid_domain], [effects.logged_in, effects.status(405)]
     )
Пример #2
0
def require_ssl(self, path):
    #-------------------------------------------------
    # If ssl is not on for GET, redirect to ssl page
    #-------------------------------------------------
    self.assertState(
        'GET',
        path,
        [
            causes.valid_domain,
            causes.owner_logged_in,
        ],
        [
            effects.redirected(path, status = 301, ssl = True)
        ]
    )
    #-------------------------------------------------
    # If ssl is not on for POST, 403 Forbidden
    #-------------------------------------------------
    self.assertState(
        'POST',
        path,
        [
            causes.valid_domain,
            causes.owner_logged_in,
        ],
        [
            effects.status(403)
        ]
    )
Пример #3
0
def check(self, path, *extra_causes):
    self.assertState('GET/POST', path, [
        causes.person_logged_in,
        causes.valid_domain,
        causes.account_inactive,
    ] + list(extra_causes), [
        effects.redirected('/account/inactive/', ssl=True),
    ])
    check_account_inactive_ok(self, path, *extra_causes)
Пример #4
0
def check_account_inactive_ok(self, path, *extra_causes):
    self.assertState('GET/POST', path, [
        causes.person_not_logged_in,
        causes.valid_domain,
        causes.account_active,
    ] + list(extra_causes), [
        effects.redirected('/person/login/', ssl=True),
    ])
    self.assertState('GET/POST', path, [
        causes.owner_logged_in,
        causes.mismatched_domain,
    ] + list(extra_causes), [
        effects.redirected('/person/login/', ssl=True),
    ])
    self.assertState('GET/POST', path, [
        causes.person_not_logged_in,
        causes.invalid_domain,
    ] + list(extra_causes), [
        effects.status(404),
    ])
    self.assertState('GET/POST', path, [
        causes.person_logged_in,
        causes.invalid_domain,
    ] + list(extra_causes), [
        effects.status(404),
    ])
    self.assertState('GET/POST', path, [
        causes.person_not_logged_in,
        causes.invalid_domain,
    ] + list(extra_causes), [
        effects.status(404),
    ])
    self.assertState('GET/POST', path, [
        causes.person_logged_in,
        causes.valid_domain,
        causes.account_active,
    ] + list(extra_causes), [
        effects.status(403),
    ])
Пример #5
0
def check(self, path, *extra_causes):
    self.assertState(
        'GET/POST',
        path,
        [
            causes.person_logged_in,
            causes.valid_domain,
            causes.account_inactive,
        ] + list(extra_causes),
        [
            effects.redirected('/account/inactive/', ssl=True),
        ]
    )
    check_account_inactive_ok(self, path, *extra_causes)
Пример #6
0
def require_ssl(self, path):
    #-------------------------------------------------
    # If ssl is not on for GET, redirect to ssl page
    #-------------------------------------------------
    self.assertState('GET', path, [
        causes.valid_domain,
        causes.owner_logged_in,
    ], [effects.redirected(path, status=301, ssl=True)])
    #-------------------------------------------------
    # If ssl is not on for POST, 403 Forbidden
    #-------------------------------------------------
    self.assertState('POST', path, [
        causes.valid_domain,
        causes.owner_logged_in,
    ], [effects.status(403)])
Пример #7
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)
        ])
Пример #8
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,
        ])
Пример #9
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)
            ])
Пример #10
0
    
    
    def test_edit_self(self):
        #-------------------------------------------------
        # You have to be logged in to edit yourself 
        #-------------------------------------------------
        self.assertState(
            'GET/POST',
            EDIT_SELF_PATH,
            [
                causes.person_not_logged_in,
                causes.valid_domain,
            ],
            [
                effects.redirected('/person/login/', ssl = True),
            ]
        )
        
        #-------------------------------------------------
        # You have to be using an account to edit yourself.
        #-------------------------------------------------
        self.assertState(
            'GET/POST',
            EDIT_SELF_PATH,
            [
                causes.invalid_domain,
            ],
            [
                effects.status(404)
            ]
        )
        #-------------------------------------------------
        # Show the form 
        #-------------------------------------------------
        self.assertState(
            'GET',
            EDIT_SELF_PATH,
            [
                causes.person_logged_in,
                causes.valid_domain,
            ],
            [
                effects.rendered('account/person_form.html'),
                effects.context('form', type = forms.BaseForm),
                effects.status(200),
            ]
        )
        #-------------------------------------------------
        # Submitting invalid data shows the form 
        #-------------------------------------------------
        self.assertState(
            'POST',
            EDIT_SELF_PATH,
            [
                causes.person_logged_in,
                causes.valid_domain,
                causes.params(
                    first_name = 'mary',
                    last_name = 'sue',
                    email = '---',
                ),

            ],
            [
                effects.rendered('account/person_form.html'),
                effects.context('form', type = forms.BaseForm),
                effects.status(200),
            ]
        )
        #-------------------------------------------------
        # Submitting valid data changes the record. 
        # But if you're not an admin, you can't edit your roles.
        #-------------------------------------------------
        self.assertState(
            'POST',
            EDIT_SELF_PATH,
            [
                causes.person_logged_in,
                causes.valid_domain,
                causes.params(
                    first_name = 'mary',
                    last_name = 'sue',
                    email = '*****@*****.**',
                    role_set = ['1', '13'],
                ),

            ],
            [
                effects.person_has_password(1, 'password'),
                effects.person_does_not_have_role('account_admin', pk=1),
                effects.person_does_not_have_role('consultant', pk=1),
                effects.rendered('account/person_form.html'),
                effects.context('form', type = forms.BaseForm),
                effects.status(200),
            ]
        )
        #-------------------------------------------------
        # Submitting valid data changes the record. 
        # If your're an admin, you CAN edit your roles
        # with the exception that you CAN NOT remove your
        # own admin priveledges.
        #-------------------------------------------------
        self.assertState(
            'POST',
            EDIT_SELF_PATH,
            [
                causes.owner_logged_in,
                causes.valid_domain,
                causes.params(
                    username = "******",
                    first_name = 'mary',
                    last_name = 'sue',
                    email = '*****@*****.**',
                    role_set = ['14'],
                ),

            ],
            [
                effects.person_has_password(2, 'password'),
                effects.person_has_role('janitor', pk=2),
                effects.person_has_role('account_admin', pk=2),
                effects.redirected('/person/'),
            ]
        )
        #-------------------------------------------------
        # If the user provides a new password, it will be changed
        #-------------------------------------------------
        self.assertState(
            'POST',
            EDIT_SELF_PATH,
            [
                causes.person_logged_in,
                causes.valid_domain,
                causes.params(
                    username = '******',
                    first_name = 'starr',
                    last_name = 'horne',
                    email = '*****@*****.**',
                    new_password = '******',
                    new_password_confirm = 'newone',
                ),

            ],
            [
                effects.person_has_password(1, 'newone'),
        
    ############################
    # 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,
            ],
     
 ############################
 # 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'),
 ############################
 # 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,
         ],
    def test_login(self):
        """
        Tests for person_views.login
        """

        # -------------------------------------------------
        # If ssl is not on for GET, redirect to ssl page
        # -------------------------------------------------
        self.assertState(
            "GET", LOGIN_PATH, [causes.valid_domain], [effects.redirected(LOGIN_PATH, status=301, ssl=True)]
        )
        # -------------------------------------------------
        # If ssl is not on for POST, 403 Forbidden
        # -------------------------------------------------
        self.assertState("POST", LOGIN_PATH, [causes.valid_domain], [effects.status(403)])

        self.assertState(
            "GET/POST",
            LOGIN_PATH,
            [causes.ssl, causes.person_not_logged_in, causes.valid_domain, causes.no_login_parameters],
            [effects.not_logged_in, effects.rendered("account/login_form.html"), effects.status(200)],
        )

        self.assertState(
            "GET/POST",
            LOGIN_PATH,
            [causes.ssl, causes.person_not_logged_in, causes.invalid_domain],
            [effects.not_logged_in, effects.status(404)],
        )

        self.assertState(
            "GET/POST",
            LOGIN_PATH,
            [causes.ssl, causes.person_not_logged_in, causes.no_domain],
            [effects.not_logged_in, effects.status(404)],
        )

        self.assertState(
            "GET/POST",
            LOGIN_PATH,
            [causes.ssl, causes.person_logged_in, causes.valid_domain],
            [effects.logged_in, effects.status(403)],
        )

        self.assertState(
            "POST",
            LOGIN_PATH,
            [
                causes.ssl,
                causes.person_not_logged_in,
                causes.valid_domain,
                causes.valid_login_parameters,
                causes.remember_me_not_checked,
            ],
            [
                effects.logged_in,
                effects.redirected("/"),
                effects.logged_in,  # Make sure we're still logged in after redirect.
                effects.session_expires_on_close,
            ],
        )

        self.assertState(
            "POST",
            LOGIN_PATH,
            [
                causes.ssl,
                causes.person_not_logged_in,
                causes.valid_domain,
                causes.valid_login_parameters,
                causes.account_inactive,
            ],
            [effects.logged_in, effects.redirected("/account/inactive/")],
        )

        self.assertState(
            "POST",
            LOGIN_PATH,
            [
                causes.ssl,
                causes.person_not_logged_in,
                causes.valid_domain,
                causes.valid_admin_login_parameters,
                causes.account_inactive,
            ],
            [effects.person_logged_in(pk=2), effects.redirected("/account/change_payment_method/")],
        )

        self.assertState(
            "POST",
            LOGIN_PATH,
            [
                causes.ssl,
                causes.person_not_logged_in,
                causes.valid_domain,
                causes.valid_login_parameters,
                causes.remember_me_checked,
                causes.account_active,
            ],
            [effects.logged_in, effects.redirected("/"), effects.logged_in, effects.session_persists_after_close],
        )

        self.assertState(
            "POST",
            LOGIN_PATH,
            [
                causes.ssl,
                causes.person_not_logged_in,
                causes.valid_domain,
                causes.invalid_login_parameters,
                causes.account_active,
            ],
            [effects.not_logged_in, effects.rendered("account/login_form.html"), effects.status(200)],
        )

        self.assertState(
            "GET/POST",
            LOGIN_PATH,
            [
                causes.ssl,
                causes.person_logged_in,
                causes.mismatched_domain,
                causes.no_login_parameters,
                causes.account_active,
            ],
            [effects.not_logged_in, effects.rendered("account/login_form.html"), effects.status(200)],
        )
Пример #15
0
 def test_create(self):
     """
     Tests for profile.create
     """
     security.check(self, CREATE_PATH, causes.ssl)
     
     #-------------------------------------------------
     # The person form is displayed
     #-------------------------------------------------
     self.assertState(
         'GET',
         CREATE_PATH,
         [
             causes.ssl,
             causes.owner_logged_in,
             causes.valid_domain,
         ],
         [
             effects.rendered('account/person_form.html'),
             effects.context('form', type = forms.BaseForm),
             effects.status(200),
         ]
     )
     #-------------------------------------------------
     # If input errors, the person form is displayed
     #-------------------------------------------------
     self.assertState(
         'POST',
         CREATE_PATH,
         [
             causes.ssl,
             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),
         ]
     )
     #-------------------------------------------------
     # Password is required for create.
     #-------------------------------------------------
     self.assertState(
         'POST',
         CREATE_PATH,
         [
             causes.ssl,
             causes.owner_logged_in,
             causes.valid_domain,
             causes.params(**create_person_parameters_without_password),
         ],
         [
             effects.rendered('account/person_form.html'),
             effects.context('form', type = forms.BaseForm),
             effects.form_errors('form'),
             effects.status(200),
         ]
     )
     #-------------------------------------------------
     # If everything is valid, create the person
     #-------------------------------------------------
     self.assertState(
         'POST',
         CREATE_PATH,
         [
             causes.ssl,
             causes.alters(Person),
             causes.owner_logged_in,
             causes.valid_domain,
             causes.params(**create_person_parameters),
         ],
         [
             effects.created(Person),
             effects.redirected('/person/list/'),
         ]
     )
Пример #16
0
        


    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)
Пример #17
0
 def test_logout(self):
     """
     Tests for person_views.logout
     """
     self.assertState(
         'GET/POST',
         LOGOUT_PATH,
         [
             causes.person_not_logged_in,
             causes.invalid_domain,
         ],
         [
             effects.not_logged_in,
             effects.status(404),
         ]
     )
     self.assertState(
         'GET/POST',
         LOGOUT_PATH,
         [
             causes.person_not_logged_in,
             causes.no_domain,
         ],
         [
             effects.status(404),
         ]
     )
     self.assertState(
         'GET/POST',
         LOGOUT_PATH,
         [
             causes.person_not_logged_in,
             causes.valid_domain,
         ],
         [
             effects.not_logged_in,
             effects.redirected(LOGIN_PATH, ssl=True),
         ]
     )
     self.assertState(
         'POST',
         LOGOUT_PATH,
         [
             causes.person_logged_in,
             causes.valid_domain,
         ],
         [
             effects.not_logged_in,
             effects.redirected(LOGIN_PATH, ssl=True),
         ]
     )
     self.assertState(
         'GET',
         LOGOUT_PATH,
         [
             causes.person_logged_in,
             causes.valid_domain,
         ],
         [
             effects.logged_in,
             effects.status(405),
         ]
     )
Пример #18
0
 def test_login(self):
     """
     Tests for person_views.login
     """
     
     #-------------------------------------------------
     # If ssl is not on for GET, redirect to ssl page
     #-------------------------------------------------
     self.assertState(
         'GET',
         LOGIN_PATH,
         [
             causes.valid_domain,
         ],
         [
             effects.redirected(LOGIN_PATH, status = 301, ssl = True)
         ]
     )
     #-------------------------------------------------
     # If ssl is not on for POST, 403 Forbidden
     #-------------------------------------------------
     self.assertState(
         'POST',
         LOGIN_PATH,
         [
             causes.valid_domain,
         ],
         [
             effects.status(403)
         ]
     )        
     
     
     self.assertState(
         'GET/POST',
         LOGIN_PATH,
         [
             causes.ssl,
             causes.person_not_logged_in,
             causes.valid_domain,
             causes.no_login_parameters,
         ],
         [
             effects.not_logged_in,
             effects.rendered('account/login_form.html'),
             effects.status(200),
         ]
     )
 
     self.assertState(
         'GET/POST',
         LOGIN_PATH,
         [
             causes.ssl,
             causes.person_not_logged_in,
             causes.invalid_domain,
         ],
         [
             effects.not_logged_in,
             effects.status(404),
         ]
     )
 
     self.assertState(
         'GET/POST',
         LOGIN_PATH,
         [
             causes.ssl,
             causes.person_not_logged_in,
             causes.no_domain,
         ],
         [
             effects.not_logged_in,
             effects.status(404),
         ]
     )
 
     self.assertState(
         'GET/POST',
         LOGIN_PATH,
         [
             causes.ssl,
             causes.person_logged_in,
             causes.valid_domain,
         ],
         [
             effects.logged_in,
             effects.status(403),
         ]
     )
 
     self.assertState(
         'POST',
         LOGIN_PATH,
         [
             causes.ssl,
             causes.person_not_logged_in,
             causes.valid_domain,
             causes.valid_login_parameters,
             causes.remember_me_not_checked,
         ],
         [
             effects.logged_in,
             effects.redirected('/'),
             effects.logged_in, # Make sure we're still logged in after redirect.
             effects.session_expires_on_close,
         ]
     )
 
     self.assertState(
         'POST',
         LOGIN_PATH,
         [
             causes.ssl,
             causes.person_not_logged_in,
             causes.valid_domain,
             causes.valid_login_parameters,
             causes.account_inactive,
         ],
         [
             effects.logged_in,
             effects.redirected('/account/inactive/'),
         ]
     )
     
     self.assertState(
         'POST',
         LOGIN_PATH,
         [
             causes.ssl,
             causes.person_not_logged_in,
             causes.valid_domain,
             causes.valid_admin_login_parameters,
             causes.account_inactive,
         ],
         [
             effects.person_logged_in(pk = 2),
             effects.redirected('/account/change_payment_method/'),
         ]
     )
 
     self.assertState(
         'POST',
         LOGIN_PATH,
         [
             causes.ssl,
             causes.person_not_logged_in,
             causes.valid_domain,
             causes.valid_login_parameters,
             causes.remember_me_checked,
             causes.account_active,
         ],
         [
             effects.logged_in,
             effects.redirected('/'),
             effects.logged_in,
             effects.session_persists_after_close,
         ]
     )
 
     self.assertState(
         'POST',
         LOGIN_PATH,
         [
             causes.ssl,
             causes.person_not_logged_in,
             causes.valid_domain,
             causes.invalid_login_parameters,
             causes.account_active,
         ],
         [
             effects.not_logged_in,
             effects.rendered('account/login_form.html'),
             effects.status(200),
         ]
     )
 
     self.assertState(
         'GET/POST',
         LOGIN_PATH,
         [
             causes.ssl,
             causes.person_logged_in,
             causes.mismatched_domain,
             causes.no_login_parameters,
             causes.account_active,
         ],
         [
             effects.not_logged_in,
             effects.rendered('account/login_form.html'),
             effects.status(200),
         ]
     )
Пример #19
0
def check_account_inactive_ok(self, path, *extra_causes):
    self.assertState(
        'GET/POST',
        path,
        [
            causes.person_not_logged_in,
            causes.valid_domain,
            causes.account_active,
        ] + list(extra_causes),
        [
            effects.redirected('/person/login/', ssl=True),
        ]
    )
    self.assertState(
        'GET/POST',
        path,
        [
            causes.owner_logged_in,
            causes.mismatched_domain,
        ] + list(extra_causes),
        [
            effects.redirected('/person/login/', ssl=True),
        ]
    )
    self.assertState(
        'GET/POST',
        path,
        [
            causes.person_not_logged_in,
            causes.invalid_domain,
        ] + list(extra_causes),
        [
            effects.status(404),
        ]
    )
    self.assertState(
        'GET/POST',
        path,
        [
            causes.person_logged_in,
            causes.invalid_domain,
        ] + list(extra_causes),
        [
            effects.status(404),
        ]
    )
    self.assertState(
        'GET/POST',
        path,
        [
            causes.person_not_logged_in,
            causes.invalid_domain,
        ] + list(extra_causes),
        [
            effects.status(404),
        ]
    )
    self.assertState(
        'GET/POST',
        path,
        [
            causes.person_logged_in,
            causes.valid_domain,
            causes.account_active,
        ] + list(extra_causes),
        [
            effects.status(403),
        ]
    )
Пример #20
0
 
 
 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),