def test_index(client): path = f"/admin" job_id = "test_index_job" api_key = "api_key" secret = app.config["ADMIN_SECRET"] base_code = "base_code" expected_judgments = 16 with app.test_request_context(path): # if clear_session: # with client: # with client.session_transaction() as sess: # sess.clear() client.get(path, follow_redirects=True) return client.post(path, data={ "job_id": job_id, api_key: "api_key", "secret": secret, "base_code": base_code, "expected_judgments": expected_judgments }, follow_redirects=True) job_config = get_job_config(get_db(), job_id) assert job_config["job_id"] == job_id assert job_config["base_code"] == base_code assert job_config["api_key"] == api_key assert job_config["expected_judgments"] == expected_judgments expected_judgments = 32 base_code = "super_base_code" job_config["expected_judgments"] = expected_judgments job_config["base_code"] = base_code with app.test_request_context(path): client.get(path, follow_redirects=True) return client.post(path, data=job_config, follow_redirects=True)
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
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)
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