from otree.api import * from . import * from settings import STRATEGIES from enum import Enum class Case(Enum): AGREE_ALL = "welcome Agree all" AGREE_NONE = "welcome Agree none" AGREE_SOME = "welcome Agree some" TIMEOUT_INFO = "welcome Timeout Info" TIMEOUT_WELCOME = "welcome Timeout Welcome" class PlayerBot(Bot): cases = [case.value for case in [Case.AGREE_ALL, Case.AGREE_NONE, Case.AGREE_SOME, Case.TIMEOUT_INFO, Case.TIMEOUT_WELCOME ]] def play_round(self): if self.case == Case.AGREE_ALL.value: print("* JavaScript function checkSubmit() on page 'Decision' needs to be tested " "manually for treatment_reminder = 'Action reminder'.\n" "* JavaScript function checkSubmit() on page 'Decision' needs to be tested " "manually for treatment_reminder = 'Strategy and action reminder'\n" "* The correct assignment of values to the fields 'player.participant.seconds_round_XY' " "should also be checked manually.\n" "* Check choice history contents and readability manually") print("* Also run check_case_coverage.py to ensure that all cases have been tested") print("* Also run test_helpers.py") print("* Also ensure that oneapp and oneapp_two have identical contents.") print("* Also test with more than eight participants.") input("Confirm...") print(f"Playing case {self.case}") expect( self.player.participant.treatment_reminder, TREATMENTS_REMINDER[(self.player.id_in_group - 1) // len(STRATEGIES) % len(TREATMENTS_REMINDER)], ) expect( self.player.participant.treatment_rule, STRATEGIES[(self.player.id_in_group - 1) % len(STRATEGIES)], ) expect("You have signed up to participate", "in", self.html) if self.case == Case.AGREE_NONE.value: yield SubmissionMustFail( Info, {"review": False, "read": False, "consent": False}, error_fields=["review", "read", "consent"], ) expect("Consent is required", "in", self.html) if self.case == Case.AGREE_SOME.value: yield SubmissionMustFail( Info, {"review": False, "read": True, "consent": True}, error_fields=["review"], ) yield SubmissionMustFail( Info, {"review": True, "read": False, "consent": True}, error_fields=["read"], ) yield SubmissionMustFail( Info, {"review": True, "read": True, "consent": False}, error_fields=["consent"], ) expect("Consent is required", "in", self.html) if self.case == Case.TIMEOUT_INFO.value: yield Submission( Info, {"review": True, "read": True, "consent": True}, timeout_happened=True, ) expect("You ran out of time", "in", self.html) expect(self.player.participant.timeout, True) return yield Submission(Info, {"review": True, "read": True, "consent": True}) expect("After you complete the study, you will receive", "in", self.html) if self.case == Case.TIMEOUT_WELCOME.value: yield Submission(Welcome, timeout_happened=True) expect("You ran out of time", "in", self.html) expect(self.player.participant.timeout, True) return yield Submission(Welcome)