"""content/ holds the study wording. A half-filled folder must never block a pilot run, and must never show a participant a placeholder.""" import content_items as CI import questionnaires as Q def _write(tmp_path, monkeypatch, name, text): monkeypatch.setattr(CI, "CONTENT", str(tmp_path)) (tmp_path / name).write_text(text, encoding="utf-8") def test_placeholder_files_read_as_not_supplied(tmp_path, monkeypatch): monkeypatch.setattr(CI, "CONTENT", str(tmp_path)) (tmp_path / "consent.md").write_text("PLACEHOLDER - replace me", encoding="utf-8") (tmp_path / "tripm.txt").write_text("# PLACEHOLDER", encoding="utf-8") assert CI.consent_text() == "" assert CI.tripm_items() == [] def test_missing_files_are_not_an_error(tmp_path, monkeypatch): monkeypatch.setattr(CI, "CONTENT", str(tmp_path)) assert CI.consent_text() == "" assert CI.tripm_items() == [] assert CI.demographics_items() == [] assert set(CI.missing()) == {"consent.md", "consent_dyad.md", "demographics.txt", "tripm.txt"} def test_tripm_items_are_numbered_in_file_order(tmp_path, monkeypatch): _write(tmp_path, monkeypatch, "tripm.txt", "# a comment\nFirst item.\n\nSecond item.\n") assert CI.tripm_items() == [("tripm_1", "First item."), ("tripm_2", "Second item.")] def test_demographics_parses_types_and_drops_malformed_lines(tmp_path, monkeypatch): _write(tmp_path, monkeypatch, "demographics.txt", "key | question | type | options\n" "age | How old are you? | number |\n" "gender | Your gender? | choice | Woman;Man;Prefer not to say\n" "broken line\n" "notype | missing a type |\n" "badtype | unknown type | telepathy |\n" "nochoice | choice with no options | choice |\n") items = CI.demographics_items() assert [i["key"] for i in items] == ["age", "gender"] assert items[1]["options"] == ["Woman", "Man", "Prefer not to say"] def test_header_row_is_not_treated_as_a_question(tmp_path, monkeypatch): _write(tmp_path, monkeypatch, "demographics.txt", "key | question | type | options\nage | How old? | number |\n") assert [i["key"] for i in CI.demographics_items()] == ["age"] async def test_consent_passes_when_no_form_is_on_file(tmp_path, monkeypatch): """A missing consent form means the stage does not exist yet. It must not read as a refusal, or an unfilled content folder would silently end every session at the first screen. """ monkeypatch.setattr(CI, "CONTENT", str(tmp_path)) monkeypatch.setattr(Q.app, "storage", type("S", (), {"user": {}})()) assert await Q.consent_screen(container=None) is True # --- the real study content, once supplied -------------------------------- def test_shipped_content_is_complete(): """All three content files must be real, not placeholders.""" assert CI.consent_text(), "consent.md is still a placeholder" assert len(CI.tripm_items()) == 58, "TriPM should have 58 items" assert len(CI.demographics_items()) >= 10 def test_every_demographic_key_has_a_csv_column(): """A key with no column is silently dropped at export.""" import csv import questionnaires as Q with open("qualtrics_template.csv", newline="", encoding="utf-8") as f: cols = set(next(csv.reader(f))) missing = [] for it in CI.demographics_items(): if it["key"] not in cols: missing.append(it["key"]) if it["type"] == "multi": missing += [f"{it['key']}__{Q._slug(o)}" for o in it["options"] if f"{it['key']}__{Q._slug(o)}" not in cols] assert not missing, f"no CSV column for: {missing}" def test_tripm_items_have_a_scoring_key(): """Items alone cannot be scored -- the key carries scale and reverse-keying.""" import csv import os path = os.path.join(CI.CONTENT, "tripm_key.csv") with open(path, newline="", encoding="utf-8") as f: rows = list(csv.DictReader(f)) assert len(rows) == 58 assert {r["Scale"] for r in rows} == {"Boldness", "Meanness", "Disinhibition"} assert {r["Keying"] for r in rows} == {"+", "-"} def test_multi_select_options_get_distinct_column_suffixes(): import questionnaires as Q race = [i for i in CI.demographics_items() if i["type"] == "multi"][0] slugs = [Q._slug(o) for o in race["options"]] assert len(set(slugs)) == len(slugs), f"slug collision: {slugs}" def test_neutral_consent_has_no_child_wording(): """The SONA sample has no child. Telling an undergraduate that "whether or not you and your child take part is up to you" is wrong, so the neutral form must not carry the dyadic study's family wording. The mandated-reporter clause is a real legal notice and stays. """ text = CI.consent_text(dyad=False) offending = [l for l in text.splitlines() if "child" in l.lower() and "mandated reporter" not in l.lower()] assert not offending, offending def test_dyad_consent_keeps_the_child_wording(): text = CI.consent_text(dyad=True) assert "you and your child" in text def test_missing_dyad_form_does_not_fall_back_to_the_neutral_one(tmp_path, monkeypatch): """A parent must not be consented on a form that never mentions their child.""" monkeypatch.setattr(CI, "CONTENT", str(tmp_path)) (tmp_path / "consent.md").write_text("Neutral form.", encoding="utf-8") assert CI.consent_text(dyad=False) == "Neutral form." assert CI.consent_text(dyad=True) == "" def test_the_consent_says_a_name_and_email_are_collected_for_payment(): """The 22 September protocol added "we will be collecting contact information (name and email addresses) for these payment purposes" and deleted "For the SONA pilot study, no identifiable information will be collected from subjects." The consent form was one revision behind and still promised no name would be collected, so the two approved documents contradicted each other. Matches SONA Pilot Consent 09-28-2026.docx. Amended 2026-10-03: payment is arranged outside the app, so the form now says when and how the ask happens. The commitments are the ones the protocol makes; only the mechanism sentence moved. Amended 2026-10-14: the same ask includes the reference code shown on the last screen, which is what tells the RA which session to pay and how much.""" s = open("content/consent.md").read() assert "We will not collect your name or any other information" not in s assert "to ask for your name, an email address, and the reference code" in s assert "kept separate from the rest of your study data" in s # The ask is a later SONA contact, not a form at the end of the task. # Nothing in either app collects a name or an email. assert "contact you through SONA after the study" in s assert "we will ask for your name and an email address at the end" not in s def test_the_sona_id_promise_is_unchanged(): """It stays true because the stored pid is a one-way pseudonym. Changing the payment wording must not have touched it.""" s = open("content/consent.md").read() assert ("The research team receives only your SONA ID for the purpose of " "granting credit, and this is not stored alongside your survey " "responses.") in s def test_the_consent_names_the_task_the_participant_starts_with(): """The order is randomised, and the form used to state one. Half the sample read "the first task is a treasure hunt" and then opened the corn harvest. The sentence is filled from the order this session already resolved, and a session with no order says so. """ pe = CI.consent_text(first_task="pe") sl = CI.consent_text(first_task="sl") assert "corn harvest first and the treasure hunt second" in pe assert "treasure hunt first and the corn harvest second" in sl assert "decided at random" in CI.consent_text() # No form reaches a participant with an unfilled slot in it, on any route. for text in (pe, sl, CI.consent_text(), CI.consent_text(dyad=True)): assert CI.TASK_ORDER_SLOT not in text assert "{" not in text # And neither form claims an order of its own any more. for text in (pe, sl, CI.consent_text(dyad=True)): assert "The first task is" not in text assert "The second task is" not in text def test_the_consent_names_only_the_payment_methods_we_have(): """Venmo was never set up. A form that offers it promises something the study cannot do, in both versions.""" for text in (CI.consent_text(first_task="pe"), CI.consent_text(dyad=True)): assert "venmo" not in text.lower() assert "Amazon gift card or PayPal" in text def test_the_consent_says_what_the_reference_code_is_for(): """Participants are shown a code on the last screen and asked for it by email, so the form has to say that is coming. It said only that we would ask for a name and an email address, which read as the whole of it.""" text = CI.consent_text(first_task="pe") assert text.lower().count("reference code") >= 2 def test_the_second_task_says_the_partner_is_a_different_person(monkeypatch): """A participant arriving from the other task has just spent half an hour with one partner. Nothing said this was a second stranger, so the two tasks were not visibly measuring two independent people.""" import effort_stages as E store = {"theme": "harvest"} monkeypatch.setattr(E.app, "storage", type("S", (), {"user": store})()) monkeypatch.setattr(E.TH.app, "storage", type("S", (), {"user": store})()) assert "different" not in E.mission_text() store["task_position"] = 2 second = E.mission_text() assert "new game" in second and "different" in second assert "not in this one" in second