예제 #1
0
 def test_list(self):
     """
     Tests for profile.list
     """
     def people_match_account(client, response, testcase):
         # client.previous_request is only available
         # in patched test client.
         if hasattr(client, 'previous_request'):
             people = response.context[0]['object_list']           
             expected = Person.objects.filter(account = client.previous_request.account)
             assert len(people) == len(expected)
             for p in people:
                 assert p in expected
         
         
     security.check(self, LIST_PATH)
     
     #-------------------------------------------------
     # The list is displayed.
     #-------------------------------------------------
     self.assertState(
         'GET/POST',
         LIST_PATH,
         [
             causes.owner_logged_in,
             causes.valid_domain,
         ],
         [
             people_match_account,
             effects.rendered('account/person_list.html'),
             effects.status(200),
         ]
     )
예제 #2
0
 def dispatch(self, method, params):
     (db, uid, passwd ) = params[0:3]
     params = params[3:]
     if method not in ['execute','create']:
         raise KeyError("Method not supported %s" % method)
     security.check(db,uid,passwd)
     fn = getattr(self, 'exp_'+method)
     res = fn(db, uid, *params)
     return res
예제 #3
0
 def dispatch(self, method, params):
     (db, uid, passwd ) = params[0:3]
     threading.current_thread().uid = uid
     params = params[3:]
     if method not in ['report', 'report_get', 'render_report']:
         raise KeyError("Method not supported %s" % method)
     security.check(db,uid,passwd)
     fn = getattr(self, 'exp_' + method)
     res = fn(db, uid, *params)
     return res
예제 #4
0
 def common_dispatch(self, method, auth, params):
    (db, uid, passwd ) = params[0:3]
    params = params[3:]
    security.check(db,uid,passwd)
    cr = pooler.get_db(db).cursor()
    fn = getattr(self, 'exp_'+method)
    res = fn(cr, uid, *params)
    cr.commit()
    cr.close()
    return res
예제 #5
0
 def dispatch(self, method, auth, params):
     (db, uid, passwd ) = params[0:3]
     params = params[3:]
     if method not in ['execute','exec_workflow','obj_list']:
         raise KeyError("Method not supported %s" % method)
     security.check(db,uid,passwd)
     ls = netsvc.LocalService('object_proxy')
     fn = getattr(ls, method)
     res = fn(db, uid, *params)
     return res
예제 #6
0
 def dispatch(self, method, params):
     (db, uid, passwd ) = params[0:3]
     params = params[3:]
     if method not in ['report', 'report_get', 'render_report']:
         raise KeyError("Method not supported %s" % method)
     security.check(db,uid,passwd)
     openerp.modules.registry.RegistryManager.check_registry_signaling(db)
     fn = getattr(self, 'exp_' + method)
     res = fn(db, uid, *params)
     openerp.modules.registry.RegistryManager.signal_caches_change(db)
     return res
예제 #7
0
 def dispatch(self, method, auth, params):
     (db, uid, passwd ) = params[0:3]
     params = params[3:]
     if method == 'obj_list':
         raise NameError("obj_list has been discontinued via RPC as of 6.0, please query ir.model directly!")
     if method not in ['execute','exec_workflow']:
         raise NameError("Method not available %s" % method)
     security.check(db,uid,passwd)
     ls = netsvc.LocalService('object_proxy')
     fn = getattr(ls, method)
     res = fn(db, uid, *params)
     return res
예제 #8
0
 def dispatch(self, method, params):
     (db, uid, passwd ) = params[0:3]
     params = params[3:]
     if method == 'obj_list':
         raise NameError("obj_list has been discontinued via RPC as of 6.0, please query ir.model directly!")
     if method not in ['execute', 'execute_kw', 'exec_workflow']:
         raise NameError("Method not available %s" % method)
     security.check(db,uid,passwd)
     assert openerp.osv.osv.service, "The object_proxy class must be started with start_object_proxy."
     fn = getattr(openerp.osv.osv.service, method)
     res = fn(db, uid, *params)
     return res
예제 #9
0
 def dispatch(self, method, params):
     (db, uid, passwd) = params[0:3]
     threading.current_thread().uid = uid
     params = params[3:]
     if method not in ["report", "report_get", "render_report"]:
         raise KeyError("Method not supported %s" % method)
     security.check(db, uid, passwd)
     openerp.modules.registry.RegistryManager.check_registry_signaling(db)
     fn = getattr(self, "exp_" + method)
     res = fn(db, uid, *params)
     openerp.modules.registry.RegistryManager.signal_caches_change(db)
     return res
예제 #10
0
파일: report.py 프로젝트: 0k/odoo
def dispatch(method, params):
    (db, uid, passwd ) = params[0:3]
    threading.current_thread().uid = uid
    params = params[3:]
    if method not in ['report', 'report_get', 'render_report']:
        raise KeyError("Method not supported %s" % method)
    security.check(db,uid,passwd)
    openerp.modules.registry.RegistryManager.check_registry_signaling(db)
    fn = globals()['exp_' + method]
    res = fn(db, uid, *params)
    openerp.modules.registry.RegistryManager.signal_caches_change(db)
    return res
예제 #11
0
 def dispatch(self, method, params):
     (db, uid, passwd) = params[0:3]
     threading.current_thread().uid = uid
     params = params[3:]
     if method == "obj_list":
         raise NameError("obj_list has been discontinued via RPC as of 6.0, please query ir.model directly!")
     if method not in ["execute", "execute_kw", "exec_workflow"]:
         raise NameError("Method not available %s" % method)
     security.check(db, uid, passwd)
     assert openerp.osv.osv.service, "The object_proxy class must be started with start_object_proxy."
     openerp.modules.registry.RegistryManager.check_registry_signaling(db)
     fn = getattr(openerp.osv.osv.service, method)
     res = fn(db, uid, *params)
     openerp.modules.registry.RegistryManager.signal_caches_change(db)
     return res
예제 #12
0
파일: model.py 프로젝트: OpusVL/odoo
def dispatch(method, params):
    (db, uid, passwd ) = params[0:3]

    # set uid tracker - cleaned up at the WSGI
    # dispatching phase in openerp.service.wsgi_server.application
    threading.current_thread().uid = uid

    params = params[3:]
    if method == 'obj_list':
        raise NameError("obj_list has been discontinued via RPC as of 6.0, please query ir.model directly!")
    if method not in ['execute', 'execute_kw', 'exec_workflow']:
        raise NameError("Method not available %s" % method)
    security.check(db,uid,passwd)
    openerp.modules.registry.RegistryManager.check_registry_signaling(db)
    fn = globals()[method]
    res = fn(db, uid, *params)
    openerp.modules.registry.RegistryManager.signal_caches_change(db)
    return res
예제 #13
0
def dispatch(method, params):
    (db, uid, passwd) = params[0:3]

    # set uid tracker - cleaned up at the WSGI
    # dispatching phase in openerp.service.wsgi_server.application
    threading.current_thread().uid = uid

    params = params[3:]
    if method == 'obj_list':
        raise NameError(
            "obj_list has been discontinued via RPC as of 6.0, please query ir.model directly!"
        )
    if method not in ['execute', 'execute_kw', 'exec_workflow']:
        raise NameError("Method not available %s" % method)
    security.check(db, uid, passwd)
    openerp.modules.registry.RegistryManager.check_registry_signaling(db)
    fn = globals()[method]
    res = fn(db, uid, *params)
    openerp.modules.registry.RegistryManager.signal_caches_change(db)
    return res
예제 #14
0
import time
import Adafruit_GPIO.SPI as SPI
import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.PWM as PWM
import Adafruit_SSD1306
import subprocess as subprocess
#from PIL import image
from pymongo import MongoClient
from security import check
from display import display
#from servo import rotate
from gsr import read_gsr_data
if __name__ == "__main__":
    response = check()
    while (response == 'Pin not recognised'):
        response = check()
        display(response, 4)
    display(response, 4)
    #display('Welcome to CAR-e',4)
예제 #15
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)
예제 #16
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/'),
         ]
     )
     
 ############################
 # 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'),
        
    ############################
    # 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,
            ],
     
 ############################
 # 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(
예제 #20
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)
        ])
예제 #21
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,
        ])
예제 #22
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),