コード例 #1
0
def test_survey_unique(client, treatment):
    """
        test if the submissed is dropped without control on other fields when <drop> is set to "1"
    """
    with app.app_context():
        worker_id = generate_worker_id("survey")
        path = f"/survey/{treatment}/?job_id=test&worker_id={worker_id}"
        with app.test_request_context(path):
            form = MainForm()
            form_data = {key: "" for key in form._fields}
            form_data["drop"] = "1"
            res = client.post(path, data=form_data, follow_redirects=True)
            assert b"dropped" in res.data
        with app.test_request_context(path):
            form = MainForm()
            form_data = {key: "" for key in form._fields}
            form_data["drop"] = "0"
            res = client.post(path, data=form_data, follow_redirects=True)
            assert b"dropped" in res.data
コード例 #2
0
def test_survey_no_workerid(client, treatment):
    for _ in range(TASK_REPETITION_LOWER):
        with app.app_context():
            assignment_id = generate_worker_id().upper().replace("_", "")
            path = f"/survey/{treatment}/?assignment_id={assignment_id}&preview=true"
            with app.test_request_context(path):
                client.get(path, follow_redirects=True)
                form = MainForm()
                form_data = {}
                for field, item in form._fields.items():
                    if field in SURVEY_CONTROL_FIELDS:
                        form_data[field] = "correct"
                    elif field == SURVEY_MAIN_TASK_CODE_FIELD:
                        form_data[field] = "resp:"
                    elif field.startswith("code_"):
                        form_data[field] = get_completion_code(field)
                    elif field in SURVEY_CHOICE_FIELDS:
                        form_data[field] = random.choice(item.choices)[0]
                    else:
                        form_data[field] = "abc"
                res = client.post(path, data=form_data, follow_redirects=True)
                print("RESULT", res.data)
コード例 #3
0
def test_survey_prop(client, treatment):
    with app.app_context():
        worker_id = generate_worker_id("survey")
        assignment_id = worker_id.upper().replace("_", "")
        path = f"/survey/{treatment}/?job_id=test&worker_id={worker_id}&assignment_id={assignment_id}"
        with app.test_request_context(path):
            client.get(path, follow_redirects=True)
            form = MainForm()
            form_data = {}
            for field, item in form._fields.items():
                if field in SURVEY_CONTROL_FIELDS:
                    form_data[field] = "correct"
                elif field == SURVEY_MAIN_TASK_CODE_FIELD:
                    form_data[field] = "prop:"
                elif field.startswith("code_"):
                    form_data[field] = ""
                elif field in SURVEY_CHOICE_FIELDS:
                    form_data[field] = random.choice(item.choices)[0]
                else:
                    form_data[field] = "abc"
            res = client.post(path, data=form_data, follow_redirects=True)
            assert b"Your survey completion code is:" in res.data
            assert b"dropped" not in res.data