def test_grantPrivilegeToPerson_Person_JSON(self):
        # Sub-Test 1: Invalid person key.
        # Define prerequisite data.
        privilegeKey = 1
        personKey = 9999
        organizationKey = 1
        # Get the result of the tested method.
        result = controller_privileges.grantPrivilegeToPersonJSON(self.db, privilegeKey, personKey, organizationKey)
        # Validate the result.
        self.assertEqual(result, '{"success":"false"}')

        # Sub-Test 2: Invalid privilege key.
        # Define prerequisite data.
        privilegeKey = 9999
        personKey = 4
        organizationKey = 1
        # Get the result of the tested method.
        result = controller_privileges.grantPrivilegeToPersonJSON(self.db, privilegeKey, personKey, organizationKey)
        # Validate the result.
        self.assertEqual(result, '{"success":"false"}')

        # Sub-Test 3: Invalid organization key.
        # Define prerequisite data.
        privilegeKey = 1
        personKey = 4
        organizationKey = 9999
        # Get the result of the tested method.
        result = controller_privileges.grantPrivilegeToPersonJSON(self.db, privilegeKey, personKey, organizationKey)
        # Validate the result.
        self.assertEqual(result, '{"success":"false"}')

        # Sub-Test 4: Valid execution.
        # Define prerequisite data.
        privilegeKey = 2
        personKey = 4
        organizationKey = 1
        # Get the result of the tested method.
        result = controller_privileges.grantPrivilegeToPersonJSON(self.db, privilegeKey, personKey, organizationKey)
        # Validate the result.
        self.assertEqual(result, '{"success":"true"}')

        # Sub-Test 5: Duplicate permission.
        # Define prerequisite data.
        privilegeKey = 2
        personKey = 4
        organizationKey = 1
        # Get the result of the tested method.
        result = controller_privileges.grantPrivilegeToPersonJSON(self.db, privilegeKey, personKey, organizationKey)
        # Validate the result.
        self.assertEqual(result, '{"success":"true"}')

        # Sub-Test 6: Duplicate permission, but different organization.
        # Define prerequisite data.
        privilegeKey = 2
        personKey = 4
        organizationKey = 2
        # Get the result of the tested method.
        result = controller_privileges.grantPrivilegeToPersonJSON(self.db, privilegeKey, personKey, organizationKey)
        # Validate the result.
        self.assertEqual(result, '{"success":"true"}')
    def test_grantPrivilegeToPerson_Global_JSON(self):
        # Sub-Test 1: Invalid person key.
        # Define prerequisite data.
        privilegeKey = 7
        personKey = 9999
        # Get the result of the tested method.
        result = controller_privileges.grantPrivilegeToPersonJSON(self.db, privilegeKey, personKey, None)
        # Validate the result.
        self.assertEqual(result, '{"success":"false"}')

        # Sub-Test 2: Invalid privilege key.
        # Define prerequisite data.
        privilegeKey = 9999
        personKey = 5
        # Get the result of the tested method.
        result = controller_privileges.grantPrivilegeToPersonJSON(self.db, privilegeKey, personKey, None)
        # Validate the result.
        self.assertEqual(result, '{"success":"false"}')

        # Sub-Test 3: Valid execution.
        # Define prerequisite data.
        privilegeKey = 7
        personKey = 5
        # Get the result of the tested method.
        result = controller_privileges.grantPrivilegeToPersonJSON(self.db, privilegeKey, personKey, None)
        # Validate the result.
        self.assertEqual(result, '{"success":"true"}')

        # Sub-Test 4: Duplicate permission.
        # Define prerequisite data.
        privilegeKey = 7
        personKey = 5
        # Get the result of the tested method.
        result = controller_privileges.grantPrivilegeToPersonJSON(self.db, privilegeKey, personKey, None)
        # Validate the result.
        self.assertEqual(result, '{"success":"true"}')
示例#3
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)