Exemplo n.º 1
0
    def test_fail_participant(self, db_session):
        net = models.Network()
        db_session.add(net)
        participant = models.Participant(
            recruiter_id="hotair",
            worker_id=str(1),
            hit_id=str(1),
            assignment_id=str(1),
            mode="test",
        )
        db_session.add(participant)
        db_session.commit()
        node = models.Node(network=net, participant=participant)
        db_session.add(node)
        question = models.Question(participant=participant,
                                   number=1,
                                   question="what?",
                                   response="???")
        db_session.add(question)

        assert len(participant.nodes()) == 1
        assert len(participant.questions()) == 1
        assert participant.failed is False

        participant.fail()

        assert participant.failed is True
        assert len(participant.nodes()) == 0
        assert len(participant.nodes(failed=True)) == 1
        assert len(participant.questions()) == 1
        assert participant.questions()[0].failed is True
Exemplo n.º 2
0
def create_question(participant_id):
    """Send a POST request to the question table.

    Questions store information at the participant level, not the node
    level.
    You should pass the question (string) number (int) and response
    (string) as arguments.
    """
    # Get the participant.
    try:
        ppt = models.Participant.query.filter_by(id=participant_id).one()
    except NoResultFound:
        return error_response(error_type="/question POST no participant found",
                              status=403)

    # Make sure the participant status is "working" or we're in debug mode
    if ppt.status != "working" and config.get('mode', None) != 'debug':
        error_type = "/question POST, status = {}".format(ppt.status)
        return error_response(error_type=error_type, participant=ppt)

    question = request_parameter(parameter="question")
    response = request_parameter(parameter="response")
    number = request_parameter(parameter="number", parameter_type="int")
    for x in [question, response, number]:
        if type(x) == Response:
            return x

    try:
        # execute the request
        models.Question(participant=ppt,
                        question=question,
                        response=response,
                        number=number)
        session.commit()
    except Exception:
        return error_response(error_type="/question POST server error",
                              status=403)

    # return the data
    return success_response(request_type="question post")