Пример #1
0
 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)
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
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)
Пример #5
0
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)
Пример #6
0
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))
Пример #7
0
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)
Пример #8
0
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)
Пример #9
0
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))
Пример #10
0
 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)