Exemplo n.º 1
0
    def test_get_schema_raises_exception_when_no_schema_found(self):
        metadata = {
            "eq_id": "123",
            "form_type": "456"
        }

        with self.assertRaises(ValueError) as context:
            get_schema(metadata)

        self.assertTrue('No schema available' in context.exception.args)
Exemplo n.º 2
0
def login():
    """
    Initial url processing - expects a token parameter and then will authenticate this token. Once authenticated
    it will be placed in the users session
    :return: a 302 redirect to the next location for the user
    """
    logger.new()
    # logging in again clears any session state
    if session:
        session.clear()

    logger.debug("attempting token authentication")
    authenticator.jwt_login(request)
    logger.debug("token authenticated - linking to session")

    metadata = get_metadata(current_user)

    eq_id = metadata["eq_id"]
    form_type = metadata["form_type"]

    logger.bind(eq_id=eq_id, form_type=form_type)

    if not eq_id or not form_type:
        logger.error("missing eq id or form type in jwt")
        raise NotFound

    json = get_schema(metadata)

    navigator = PathFinder(json, get_answer_store(current_user), metadata)
    current_location = navigator.get_latest_location(
        get_completed_blocks(current_user))

    return redirect(current_location.url(metadata))
Exemplo n.º 3
0
def check_survey_state():
    metadata = get_metadata(current_user)
    logger.new(tx_id=metadata['tx_id'])
    g.schema_json = get_schema(get_metadata(current_user))
    values = request.view_args
    logger.debug('questionnaire request', eq_id=values['eq_id'], form_type=values['form_type'],
                 ce_id=values['collection_id'], method=request.method, url_path=request.full_path)

    _check_same_survey(values['eq_id'], values['form_type'], values['collection_id'])
Exemplo n.º 4
0
def login():
    """
    Initial url processing - expects a token parameter and then will authenticate this token. Once authenticated
    it will be placed in the users session
    :return: a 302 redirect to the next location for the user
    """

    # logging in again clears any session state
    if session:
        session.clear()

    authenticator = Authenticator()
    logger.debug("Attempting token authentication")

    authenticator.jwt_login(request)
    logger.debug("Token authenticated - linking to session")

    metadata = get_metadata(current_user)

    eq_id = metadata["eq_id"]
    collection_id = metadata["collection_exercise_sid"]
    form_type = metadata["form_type"]
    period_id = metadata["period_id"]

    logger.debug("Requested questionnaire %s for form type %s", eq_id, form_type)
    if not eq_id or not form_type:
        logger.error("Missing EQ id %s or form type %s in JWT", eq_id, form_type)
        raise NotFound

    json, schema = get_schema()
    questionnaire_manager = QuestionnaireManager(schema, json=json)

    navigator = questionnaire_manager.navigator
    current_location = navigator.get_latest_location(get_answers(current_user), get_completed_blocks(current_user))

    return redirect('/questionnaire/' + eq_id + '/' + form_type + '/' + period_id + '/' + collection_id + '/' + current_location)
Exemplo n.º 5
0
def check_survey_state():
    g.schema_json, g.schema = get_schema(get_metadata(current_user))
    values = request.view_args

    _check_same_survey(values['eq_id'], values['form_type'], values['collection_id'])
Exemplo n.º 6
0
def check_survey_state():
    json, schema = get_schema()
    g.questionnaire_manager = QuestionnaireManager(schema, json=json)
    values = request.view_args
    if not same_survey(values['eq_id'], values['form_type'], values['period_id'], values['collection_id']):
        return redirect(url_for('root.information', message_identifier='multiple-surveys'))