Exemple #1
0
def getEvents():
    try:
        user_id = current_user.entityFK

        if request.method == 'GET':
            org_json        = controller_privileges.getOrgsWithPrivilegesForPersonJSON(user_id)
            org_dict = json.loads(org_json)
            return render_template('events.html', orgs=org_dict)

    except Exception, e:
        return abort(404)
Exemple #2
0
def privilege():
    try:
        user_id = current_user.entityFK

        if request.method == 'GET':
            org_json        = controller_privileges.getOrgsWithPrivilegesForPersonJSON(user_id)
            privilege_json  = controller_privileges.getAllPrivilegesJSON()

            if is_request_json():
                return jsonify(privilege_data=org_json + privilege_json)

            else:
                org_dict = json.loads(org_json)
                privilege_dict = json.loads(privilege_json)
                return render_template('privilege.html', orgs=org_dict, privileges=privilege_dict)
    except Exception, e:
        return abort(404)
    def test_getOrgsWithPrivilegesForPersonJSON(self):
        # Define prerequisite data.
        personKey = 4
        org1 = models.Organization.query.filter_by(entityFK=1).first()
        org2 = models.Organization.query.filter_by(entityFK=2).first()

        # Get the result of the tested method.
        jsonString = controller_privileges.getOrgsWithPrivilegesForPersonJSON(personKey)
        # Validate the result.
        self.assertIsNotNone(jsonString)
        dict = json.loads(jsonString)
        count = 0
        for key,values in dict.iteritems():
            self.assertEqual(key, "Organizations")
            for value in values:
                count += 1
                self.assertTrue(value['org_id'] is org1.entityFK or value['org_id'] is org2.entityFK)
                self.assertTrue(value['org_name'] == org1.name or value['org_name'] == org2.name)
        self.assertEqual(count, 2)