def test_setAttrAndReset(self):

        #check that the value is correct to start
        err, unknownErr = pref.get(pref.ERROR_UNKNOWN)
        self.assertEqual(
            pref.getError(pref.ERROR_UNKNOWN).code, unknownErr.code)
        self.assertEqual(pref.Success.code, err.code)

        #set new value
        err = pref.setAttr(pref.ERROR_UNKNOWN, "error")
        self.assertEqual(pref.Success.code, err.code)

        #check new value
        err, unknownErr = pref.get(pref.ERROR_UNKNOWN)
        self.assertEqual("error", unknownErr)
        self.assertEqual(pref.Success.code, err.code)

        #reset config
        pref.resetConfig()

        #check that the value was reset
        err, unknownErr = pref.get(pref.ERROR_UNKNOWN)
        self.assertEqual(
            pref.getError(pref.ERROR_UNKNOWN).code, unknownErr.code)
        self.assertEqual(pref.Success.code, err.code)
    def test_setAttrInDict(self):
        err = pref.setAttr(pref.ERROR_UNKNOWN, "error")
        self.assertEqual(pref.Success.code, err.code)

        err, unknownErr = pref.get(pref.ERROR_UNKNOWN)
        self.assertEqual("error", unknownErr)
        self.assertEqual(pref.Success.code, err.code)
    def test_setAttr(self):
        err = pref.setAttr(pref.CONFIG_LOGIN_ENDPOINT, "/login2")
        self.assertEqual(pref.Success.code, err.code)

        err, login = pref.get(pref.CONFIG_LOGIN_ENDPOINT)
        self.assertEqual("/login2", login)
        self.assertEqual(pref.Success.code, err.code)
Esempio n. 4
0
def apiRequest():
    '''
    API Request /api
    used for all operations between frontend and backend
      ie
        RUN_SCRIPT
        MANAGE_SCRIPT
        MANAGE_COMPUTERS
        MANAGE_SCRIPT_LOGS
        SCHEDULE_SCRIPT
        GET_FILE
    request:
      {
        op: <operation:string>
        data: <opData:dict>
      }
    return:
      {
        Error:
      }
    '''
    logger.info("api request: {}".format(request.json))
    # if not("userID" in session):
    #     session.pop("userID", None)

    #Makes sure user is logged in if not redirect to login
    userID = None
    try:
        userID = session[pref.getNoCheck(pref.REQ_VAR_USER_ID)]
    except:
        return redirect(pref.getNoCheck("/#/"))

    err = pref.Success

    #names of request vars
    bodyName = pref.getNoCheck(pref.REQ_VAR_BODY)
    dataName = pref.getNoCheck(pref.REQ_VAR_DATA)
    jsonOpName = pref.getNoCheck(pref.REQ_VAR_OP)

    try:
        opName = pref.CONFIG_OPERATIONS + ":" + request.json[bodyName][
            jsonOpName]
        data = request.json[bodyName][dataName]
    except:
        err = pref.getError(pref.ERROR_INVALID_REQUEST, args=(request.json))
        logger.error(err)

    returnValue = None

    if (err == pref.Success):
        err, op = pref.get(opName)

    if (err == pref.Success):
        apiFtn = OPS[op]
        returnValue = apiFtn(data)
    else:
        logger.error(err)
        returnValue = jsonify(Error=err.toJson(), data={})
    return (returnValue, 200)
Esempio n. 5
0
def loginRequest():
    logger.info("login request")

    #names of request vars
    bodyName = pref.getNoCheck(pref.REQ_VAR_BODY)
    dataName = pref.getNoCheck(pref.REQ_VAR_DATA)
    jsonOpName = pref.getNoCheck(pref.REQ_VAR_OP)

    opName = pref.CONFIG_LOGIN_OPERATION + ":" + request.json[bodyName][
        jsonOpName]
    data = request.json[bodyName][dataName]

    returnValue = None

    err, op = pref.get(opName)
    if (err == pref.Success):
        loginFtn = LOGIN_OPS[op]
        returnValue = loginFtn(data)
    else:
        logger.error(err)
        returnValue = jsonify(Error=err.toJson(), data={})
    return (returnValue, 200)
 def test_getNoCheckInvalidKey(self):
     err, dne = pref.get("DNE")
     self.assertEqual(None, dne)
 def test_getInvalidKey(self):
     err, dne = pref.get("DNE")
     self.assertEqual(None, dne)
     self.assertEqual(
         pref.getError(pref.ERROR_ATTRIBUTE_NOT_FOUND).code, err.code)
 def test_get(self):
     err, login = pref.get(pref.CONFIG_LOGIN_ENDPOINT)
     self.assertEqual("/login", login)
     self.assertEqual(pref.Success.code, err.code)
Esempio n. 9
0
def loginRequest():
    logger.info("login request")

    #names of request vars
    bodyName = pref.getNoCheck(pref.REQ_VAR_BODY)
    dataName = pref.getNoCheck(pref.REQ_VAR_DATA)
    jsonOpName = pref.getNoCheck(pref.REQ_VAR_OP)

    opName = pref.CONFIG_LOGIN_OPERATION + ":" + request.json[bodyName][
        jsonOpName]
    data = request.json[bodyName][dataName]

    returnValue = None

    err, op = pref.get(opName)
    if (err == pref.Success):
        loginFtn = LOGIN_OPS[op]
        returnValue = loginFtn(data)
    else:
        logger.error(err)
        returnValue = jsonify(Error=err.toJson(), data={})
    return (returnValue, 200)


if __name__ == '__main__':
    err, port = pref.get(pref.CONFIG_PORT)
    if (err.code == 0):
        app.run(debug=True, port=port)
    else:
        logger.critical(err)