def test_fill_dict_with_requirement_ok(self): dict_response = {} dict_response["code"] = CODE_POST_OK dict_response["message"] = MSG_POST_OK dict_response = Response.fill_dict(self.data, dict_response, self.requirement) self.assertEqual(dict_response["requirements"], self.data)
def syncro_mongodb(): status_code = CODE_PUT_OK message = MSG_PUT_OK try: if (__correct_token()): dataDict = json.loads(request.data) Syncro().syncro_MongoDB(dataDict.get('token')) except EpepinException as ex: status_code = ex.get_status_code() message = ex.get_error_message() return Response.json_data(status_code, message, None, None)
def delete_requirement(requirement_id): status_code = CODE_DELETE_OK message = MSG_DELETE_OK try: if (__correct_token()): db = database_connection() connection = db.connection() db.delete_requirement(connection, requirement_id) except EpepinException as ex: status_code = ex.get_status_code() message = ex.get_error_message() return Response.json_data(status_code, message, None, requirement_id)
def get_comments(): status_code = CODE_GET_OK message = MSG_GET_OK reviewers = None try: db = database_connection() connection = db.connection() reviewers = db.get_comments(connection) except EpepinException as ex: status_code = ex.get_status_code() message = ex.get_error_message() return Response.json_data(status_code, message, reviewers, None)
def get_requirements(): status_code = CODE_GET_OK message = MSG_GET_OK requirements = None try: if (__correct_token()): db = database_connection() connection = db.connection() requirements = db.get_requirements(connection) except EpepinException as ex: status_code = ex.get_status_code() message = ex.get_error_message() return Response.json_data(status_code, message, requirements, None)
def updateReviewers(): status_code = CODE_POST_OK message = MSG_POST_OK token = None content = request.get_json() try: if (__correct_token()): db = database_connection() connection = db.connection() db.updateReviewer(connection, content['id_req'], content['id_user'], content['action']) except EpepinException as ex: status_code = ex.get_status_code() message = ex.get_error_message() return Response.json_token(status_code, message, str(token))
def update_requirement(requirement_id): status_code = CODE_PUT_OK message = MSG_PUT_OK try: if (__correct_token()): data = request.get_json() input_data = copy.deepcopy(data) validate(data, 'requirement.json') db = database_connection() connection = db.connection() db.update_requirement(connection, requirement_id, data) except EpepinException as ex: status_code = ex.get_status_code() message = ex.get_error_message() return Response.json_data(status_code, message, input_data, requirement_id)
def create_comment(): status_code = CODE_POST_OK message = MSG_POST_OK token = None comment = None try: if (__correct_token()): data = request.get_json() db = database_connection() connection = db.connection() comment = db.insert_comment(connection, data) except EpepinException as ex: status_code = ex.get_status_code() message = ex.get_error_message() return Response.json_data(status_code, message, None, None)
def login(): status_code = CODE_POST_OK message = MSG_POST_OK token = None content = request.get_json() cfg = utils.get_config() try: data = { 'username': content['username'], 'password': content['password'] } reqdata = urlencode(data) req = urllib2.Request(cfg.epepin_auth_url, reqdata) #response = urllib2.urlopen(req) token = jwt.encode( { 'exp': datetime.utcnow() + timedelta(seconds=1800), 'username': content['username'] + str(datetime.now().microsecond) }, Authetication.get_key(), algorithm=Authetication.get_algorithm()) #token = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256') Authetication.put_token(str(token)) current_app.logger.info('%s logged in successfully', content['username']) except jwt.ExpiredSignatureError as ex: status_code = '401' message = 'HTTP 401 Unauthorized. Expired Time.' except jwt.PyJWTError as exx: current_app.logger.info("\n User not logged in: " + content['username'] + "\n. Exception:" + exx.message) except EpepinException as ex: status_code = ex.get_status_code() message = ex.get_error_message() return Response.json_token(status_code, message, str(token))
def test_fill_dict_without_requirement_ok(self): dict_response = {} dict_response["code"] = CODE_GET_OK dict_response["message"] = MSG_GET_OK dict_response = Response.fill_dict(self.data_list, dict_response, None) self.assertEqual(len(dict_response["requirements"]), 2)