def test_getPrivilegesForPersonJSON(self):
     # Define prerequisite data.
     personKey = 3
     organizationKey = 1
     # Get the result of the tested method.
     jsonString = controller_privileges.getPrivilegesForPersonJSON(personKey, organizationKey)
     # Validate the result.
     self.assertIsNotNone(jsonString)
     self.assertTrue(len(jsonString) > 0)
     dict = json.loads(jsonString)
     personKeyInOutput = False
     orgKeyInOutput = False
     privCount = 0
     for key1,value1 in dict.iteritems():
         if key1 == models.EMPLOYEE_ENTITYFK_KEY:
             self.assertEqual(value1, personKey)
             personKeyInOutput = True
         elif key1 == models.ORGANIZATION_ENTITYFK_KEY:
             self.assertEqual(value1, organizationKey)
             orgKeyInOutput = True
         elif key1 == 'PersonPrivileges':
             for dictPrivilege in value1:
                 privilege = controller_privileges.extractPrivilegeFromDict(dictPrivilege)
                 privCount += 1
                 self.assertTrue(privilege.pk is 5 or privilege.pk is 6)
                 self.assertTrue(privilege.privilege == 'VIEW_ALL_EMPLOYEES_IN_ORG' or privilege.privilege == 'ASSIGN_EMPS_TO_SHIFTS')
     self.assertEqual(privCount, 2)
     self.assertTrue(personKeyInOutput)
     self.assertTrue(orgKeyInOutput)
Exemplo n.º 2
0
def privilege_org_member(org_id, person_id):
    try:
        user_id = current_user.entityFK;

        if request.method == 'GET':
            privileges = controller_privileges.getPrivilegesForPersonJSON(person_id, org_id)

            if is_request_json():
                return Response(response=privileges, mimetype='application/json')

        elif request.method == 'POST':

            if is_request_json():
                result = controller_privileges.grantPrivilegeToPersonJSON(db, request.json['privilege_id'], person_id, org_id)
                return Response(response=result, mimetype='application/json')

    except Exception, e:
        return abort(404)
 def test_getPrivilegesForPersonJSON_noprivilege(self):
     # Define prerequisite data.
     personKey = 5
     organizationKey = 1
     # Get the result of the tested method.
     jsonString = controller_privileges.getPrivilegesForPersonJSON(personKey, organizationKey)
     # Validate the result.
     self.assertIsNotNone(jsonString)
     self.assertTrue(len(jsonString) > 0)
     dict = json.loads(jsonString)
     personKeyInOutput = False
     orgKeyInOutput = False
     for key1,value1 in dict.iteritems():
         if key1 == models.EMPLOYEE_ENTITYFK_KEY:
             self.assertEqual(value1, personKey)
             personKeyInOutput = True
         elif key1 == models.ORGANIZATION_ENTITYFK_KEY:
             self.assertEqual(value1, organizationKey)
             orgKeyInOutput = True
         elif key1 == 'PersonPrivileges':
             self.assertEqual(value1, 'None')
     self.assertTrue(personKeyInOutput)
     self.assertTrue(orgKeyInOutput)