Exemplo n.º 1
0
    def get():
        if not (jwt.requires_roles(User.EDITOR)
                or jwt.requires_roles(User.APPROVER)):
            return jsonify({
                "message":
                "Error: You do not have access to the Name Request queue."
            }), 403

        try:
            user = User.find_by_jwtToken(g.jwt_oidc_token_info)
            current_app.logger.debug('find user')
            if not user:
                user = User.create_from_jwtToken(g.jwt_oidc_token_info)
            nr = RequestDAO.get_queued_oldest(user)

        except SQLAlchemyError as err:
            # TODO should put some span trace on the error message
            current_app.logger.error(err.with_traceback(None))
            return jsonify({
                'message':
                'An error occurred getting the next Name Request.'
            }), 500
        except AttributeError as err:
            current_app.logger.error(err)
            return jsonify(
                {'message': 'There are no Name Requests to work on.'}), 404

        return jsonify(nameRequest='{}'.format(nr)), 200
Exemplo n.º 2
0
def test_get_queued_oldest_multirow(client, app):

    # add NR to database
    from namex.models import Request as RequestDAO, State, User
    nr_first = RequestDAO()
    nr_first.nrNum = 'NR 0000001'
    nr_first.stateCd = State.DRAFT
    nr_first.save_to_db()

    for i in range(2, 12):
        nr = RequestDAO()
        nr.nrNum = 'NR {0:07d}'.format(i)
        nr.stateCd = State.DRAFT
        nr.save_to_db()

    user = User(username='******',
                firstname='first',
                lastname='last',
                sub='idir/funcmunk',
                iss='keycloak')
    user.save_to_db()

    nr_oldest, new_req = RequestDAO.get_queued_oldest(user)

    # Tests ####
    assert nr_first.nrNum == nr_oldest.nrNum
    assert nr_oldest.json()
Exemplo n.º 3
0
def test_get_queued_empty_queue(client, app):

    # SETUP #####
    # add NR to database
    from namex.models import Request as RequestDAO, User
    from namex.exceptions import BusinessException

    user = User(username='******', firstname='first', lastname='last', sub='idir/funcmunk', iss='keycloak')
    user.save_to_db()

    with pytest.raises(BusinessException) as e_info:
        nr_oldest, new_req = RequestDAO.get_queued_oldest(user)
Exemplo n.º 4
0
def test_get_queued_oldest(client, app):

    # SETUP #####
    # add NR to database
    from namex.models import Request as RequestDAO, State, User
    nr = RequestDAO()
    nr.nrNum='NR 0000001'
    nr.stateCd = State.DRAFT
    nr.save_to_db()

    user = User(username='******', firstname='first', lastname='last', sub='idir/funcmunk', iss='keycloak')
    user.save_to_db()

    nr_oldest, new_req = RequestDAO.get_queued_oldest(user)

    # Tests ####
    assert nr.nrNum == nr_oldest.nrNum