# Path: core/config.py

# 
# 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.config import conf_approval_flow
from core.validation.permissions import get_role_approval_step
                               { '_id' : self.projects_ids[0], 
                                "expences" : [ { '_id' : found_expences['records'][0]['_id'] } ] } ], 
              { 'error' : None, 'ids' : [ '' ] }
          )

         self._assert_req('/data/search_expences', { "project_id" : self.projects_ids[0], 'start' : '2005-09-09', 'end' : '2005-10-10' }, { 'error' : None, 'records' : [ 
                                                 { '_id' : '', 'project_id':  self.projects_ids[0], "user_id" : self.users_ids[1], "trip_id" : '2'*24, 'status': 0, "date" : "2005-10-08", "file" : {}, 'objects' : [{}] },   
                                                 { '_id' : '', 'project_id':  self.projects_ids[0], "user_id" : '1'*24, "trip_id" : '2'*24, 'status': 0, "date" : "2005-10-08", "file" : {}, 'objects' : [{}] }     
                                               ]})
    
class ExpencesAPIAsEmployee(TestCaseAsEmployee, ModuleData):
    
    def setUp(self):        
        TestClassBase.setUp(self)
        self._add_user_data()
        ModuleData._add_module_data(self, self.employee_id)
        self._log_as_user()
        
        
    def test_expences_ok(self):

        # Insert one trip in a project where user works
        self._assert_req('/data/push_expences', [ 
                                { '_id' : self.projects_ids[1], 
                                 "expences" : [ 
                                                 { "user_id" : self.employee_id, "trip_id" : '2'*24, 'status': get_role_approval_step('draft'), "date" : "2005-10-08", "file" : {}, 'objects' : [{}] },   
                                ] } ], 
               { 'error' : None, 'ids' : [ '' ] }
       )


# Path: core/config.py

# 
# 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_expences.py
from testclasses import TestClassBase, TestCaseAsEmployee, TestCaseAsManager
from core.config import conf_approval_flow
from core.validation.permissions import get_role_approval_step

                               { '_id' : self.projects_ids[0], 
                                "expences" : [ { '_id' : found_expences['records'][0]['_id'] } ] } ], 
              { 'error' : None, 'ids' : [ '' ] }
          )

         self._assert_req('/data/search_expences', { "project_id" : self.projects_ids[0], 'start' : '2005-09-09', 'end' : '2005-10-10' }, { 'error' : None, 'records' : [ 
                                                 { '_id' : '', 'project_id':  self.projects_ids[0], "user_id" : self.users_ids[1], "trip_id" : '2'*24, 'status': 0, "date" : "2005-10-08", "file" : {}, 'objects' : [{}] },   
                                                 { '_id' : '', 'project_id':  self.projects_ids[0], "user_id" : '1'*24, "trip_id" : '2'*24, 'status': 0, "date" : "2005-10-08", "file" : {}, 'objects' : [{}] }     
                                               ]})
    
class ExpencesAPIAsEmployee(TestCaseAsEmployee, ModuleData):
    
    def setUp(self):        
        TestClassBase.setUp(self)
        self._add_user_data()
        ModuleData._add_module_data(self, self.employee_id)
        self._log_as_user()
        
        
    def test_expences_ok(self):

        # Insert one trip in a project where user works
        self._assert_req('/data/push_expences', [ 
                                { '_id' : self.projects_ids[1], 
                                 "expences" : [ 
                                                 { "user_id" : self.employee_id, "trip_id" : '2'*24, 'status': get_role_approval_step('draft'), "date" : "2005-10-08", "file" : {}, 'objects' : [{}] },   
                                ] } ], 
               { 'error' : None, 'ids' : [ '' ] }
       )


        self._assert_req('/data/search_expences', { "user_id" : self.employee_id,  "employee_id" : self.employee_id }, {u'error': None, 'records' : [{ '_id' : '', "user_id" : self.employee_id, 'project_id' : self.projects_ids[1], "trip_id" : '2'*24, 'status' : get_role_approval_step('draft'), "date" : "2005-10-08", "file" : {}, 'objects' : [{}] }]})