コード例 #1
0
 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)
コード例 #2
0
 def test_extractPrivilegeFromDict(self):
     control = models.Privilege.query.filter_by(pk=4).first()
     stringJSON = '{"privilege_pk":4,"privilege":"VIEW_ALL_ORGANIZATIONS"}'
     data = json.loads(stringJSON)
     target = controller_privileges.extractPrivilegeFromDict(data)
     
     self.assertEqual(control.pk, target.pk)
     self.assertEqual(control.privilege, target.privilege)
     self.assertEqual(control.__repr__(), target.__repr__())
コード例 #3
0
 def test_getAllPrivilegesJSON(self):
     jsonString = controller_privileges.getAllPrivilegesJSON()
     self.assertIsNotNone(jsonString)
     self.assertTrue(len(jsonString) > 0)
     dict = json.loads(jsonString)
     privCount = 0
     for key1,value1 in dict.iteritems():
         if key1 == 'Privileges':
             for dictPrivilege in value1:
                 privilege = controller_privileges.extractPrivilegeFromDict(dictPrivilege)
                 privCount += 1
                 self.assertTrue(privilege.pk >= 1 or privilege.pk <= 8)
                 self.assertTrue(privilege.privilege == 'ASSIGN_EMPS_TO_SHIFTS' or privilege.privilege == 'DELETE_ORGANIZATION' or
                                 privilege.privilege == 'MODIFY_ORGANIZATION' or privilege.privilege == 'REGISTER_NEW_ORGANIZATION' or
                                 privilege.privilege == 'SOME_OTHER_EMP_PRIVILEGE' or privilege.privilege == 'VIEW_ALL_EMPLOYEES_IN_ORG' or
                                 privilege.privilege == 'VIEW_ALL_ORGANIZATIONS' or privilege.privilege == 'YET_ANOTHER_EMP_PRIVILEGE')
     self.assertEqual(privCount, 8)
コード例 #4
0
 def test_getGlobalPrivilegesForPersonJSON(self):
     # Define prerequisite data.
     personKey = 3
     # Get the result of the tested method.
     jsonString = controller_privileges.getGlobalPrivilegesForPersonJSON(personKey)
     # Validate the result.
     self.assertIsNotNone(jsonString)
     self.assertTrue(len(jsonString) > 0)
     dict = json.loads(jsonString)
     personKeyInOutput = False
     for key1,value1 in dict.iteritems():
         if key1 == models.EMPLOYEE_ENTITYFK_KEY:
             self.assertEqual(value1, personKey)
             personKeyInOutput = True
         elif key1 == 'GlobalPrivileges':
             privCount = 0
             for dictPrivilege in value1:
                 privilege = controller_privileges.extractPrivilegeFromDict(dictPrivilege)
                 privCount += 1
                 self.assertTrue(privilege.pk is 1 or privilege.pk is 4)
                 self.assertTrue(privilege.privilege == 'REGISTER_NEW_ORGANIZATION' or privilege.privilege == 'VIEW_ALL_ORGANIZATIONS')
             self.assertEqual(privCount, 2)
     self.assertTrue(personKeyInOutput)