# Path: core/validation/permissions.py
# def get_role_approval_step(group):
# 
#     # Approvation roles 
#     approvation_roles = [ s['approver'] if 'approver' in s else '' for s in conf_approval_flow ]
# 
#     # Administrator can see every expence, return 0
#     if group == 'administrator':
#         return 0
#     # Roles that can approves can see only expences >= owned step.
#     elif group in approvation_roles[1:-1]:
#         return approvation_roles.index(group)
#     # Else, return draft step 
#     else:
#         return len(approvation_roles)-1


from testclasses import TestClassBase, TestCaseAsEmployee, TestCaseAsManager
from core.validation.permissions import get_role_approval_step
                                                                                                                                                  
                                                                                                                                                  ]})

         
         
    def test_trips_ko(self):
         
        # Insert one expence in unknown project
        self._assert_req('/data/push_trips', [ 
                                { '_id' : '7'*24, 
                                 "trips" : [ 
                                                 { "user_id" : self.employee_id, "description" : "descr2", "status" : 2, "start" : "2009-10-08", "end" : "2009-10-10", "country" : "USA", 'city' : "Austin", 'notes' : [ 'too expensive' ], 'accommodation' : {} }     
                                ] } ], 
               { 'error' : "TSValidationError: Access to project '%s' is restricted for current user" % ('7'*24) }
               )          
         
        # Insert one expence in project where user does not work 
        self._assert_req('/data/push_trips', [ 
                                { '_id' : self.projects_ids[2], 
                                 "trips" : [ 
                                                 { "user_id" : self.employee_id, "description" : "descr2", "status" : 2, "start" : "2009-10-08", "end" : "2009-10-10", "country" : "USA", 'city' : "Austin", 'notes' : [ 'too expensive' ], 'accommodation' : {} }     
                                ] } ], 
               { 'error' : "TSValidationError: Access to project '%s' is restricted for current user" % (self.projects_ids[2]) }
               )       
 
        # Insert a trip in correct project with wrong user_id
        self.maxDiff = None
        self._assert_req('/data/push_trips', [ 
                                 { '_id' : self.projects_ids[1], 
                                  "trips" : [ 

# Path: core/validation/permissions.py
# def get_role_approval_step(group):
# 
#     # Approvation roles 
#     approvation_roles = [ s['approver'] if 'approver' in s else '' for s in conf_approval_flow ]
# 
#     # Administrator can see every expence, return 0
#     if group == 'administrator':
#         return 0
#     # Roles that can approves can see only expences >= owned step.
#     elif group in approvation_roles[1:-1]:
#         return approvation_roles.index(group)
#     # Else, return draft step 
#     else:
#         return len(approvation_roles)-1


# Path: test/test_trips.py
from testclasses import TestClassBase, TestCaseAsEmployee, TestCaseAsManager
from core.validation.permissions import get_role_approval_step

                                                                                                                                                  
                                                                                                                                                  ]})

         
         
    def test_trips_ko(self):
         
        # Insert one expence in unknown project
        self._assert_req('/data/push_trips', [ 
                                { '_id' : '7'*24, 
                                 "trips" : [ 
                                                 { "user_id" : self.employee_id, "description" : "descr2", "status" : 2, "start" : "2009-10-08", "end" : "2009-10-10", "country" : "USA", 'city' : "Austin", 'notes' : [ 'too expensive' ], 'accommodation' : {} }     
                                ] } ], 
               { 'error' : "TSValidationError: Access to project '%s' is restricted for current user" % ('7'*24) }
               )          
         
        # Insert one expence in project where user does not work 
        self._assert_req('/data/push_trips', [ 
                                { '_id' : self.projects_ids[2], 
                                 "trips" : [ 
                                                 { "user_id" : self.employee_id, "description" : "descr2", "status" : 2, "start" : "2009-10-08", "end" : "2009-10-10", "country" : "USA", 'city' : "Austin", 'notes' : [ 'too expensive' ], 'accommodation' : {} }     
                                ] } ], 
               { 'error' : "TSValidationError: Access to project '%s' is restricted for current user" % (self.projects_ids[2]) }
               )       
 
        # Insert a trip in correct project with wrong user_id
        self.maxDiff = None
        self._assert_req('/data/push_trips', [ 
                                 { '_id' : self.projects_ids[1], 
                                  "trips" : [ 

                                                  { "user_id" : self.users_ids[1], "description" : "descr2", "status" : get_role_approval_step('draft'), "start" : "2009-10-08", "end" : "2009-10-10", "country" : "USA", 'city' : "Austin", 'notes' : [ 'too expensive' ], 'accommodation' : {} }     