Пример #1
0
        def test_some_already_started(self):
            participants = self.session.get_participants()
            p1 = participants[0]

            bot = ParticipantBot(p1, load_player_bots=False)
            bot.open_start_url()
            self.advance_to_end()
Пример #2
0
    def test_bot_bad_post(self):
        """
        Test that posting bad data without using SubmitInvalid
        will raise an error.
        """

        session = otree.session.create_session(
            session_config_name='bots_bad_post',
            num_participants=1,
            use_cli_bots=True,
            bot_case_number=0,
        )

        bots = []
        for participant in session.get_participants():
            bot = ParticipantBot(participant)
            bots.append(bot)
            bot.open_start_url()

        bot_runner = SessionBotRunner(bots, session.code)

        with self.assertRaises(AssertionError):
            # need to disable log output, because this triggers an exception
            # that is logged to stdout
            logging.disable(logging.CRITICAL)
            bot_runner.play_until_end()
            logging.disable(logging.NOTSET)
Пример #3
0
        def test_some_already_started(self):
            participants = self.session.get_participants()
            p1 = participants[0]

            bot = ParticipantBot(p1, load_player_bots=False)
            bot.open_start_url()
            self.advance_to_end()
Пример #4
0
    def test_bots_check_html(self):

        session = otree.session.create_session(
            session_config_name='bots_check_html',
            num_participants=1,
            use_cli_bots=True,
            bot_case_number=0,
        )

        bots = []

        with self.settings(BOTS_CHECK_HTML=True):
            from django.conf import settings
            self.assertEqual(settings.BOTS_CHECK_HTML, True)
            for participant in session.get_participants():
                bot = ParticipantBot(participant)
                bots.append(bot)
                bot.open_start_url()

            bot_runner = SessionBotRunner(bots, session.code)

            try:
                bot_runner.play_until_end()
            except AssertionError as exc:
                # AssertionError should say something about check_html
                raises_correct_message = 'check_html' in str(exc)
            else:
                raises_correct_message = False
            if not raises_correct_message:
                raise AssertionError('bots check_html not working properly')
Пример #5
0
 def test_timeout_on_regular_page(self):
     participant = Participant.objects.get()
     bot = ParticipantBot(participant, load_player_bots=False)
     bot.open_start_url()
     bot.submit(Submission(views.Page1, {}, timeout_happened=True))
     # it should be OK to use timeout_happened=True, even if the page
     # has no timeout_seconds, because you can be simulating "advance slowest"
     bot.submit(Submission(views.PageWithoutTimeout, {}, timeout_happened=True))
Пример #6
0
def session_bot_runner_factory(session):
    bots = []
    for participant in session.get_participants():
        bot = ParticipantBot(participant)
        bots.append(bot)

    return SessionBotRunner(bots)
Пример #7
0
 def setUp(self):
     session = create_session('skip_wait_page', num_participants=2)
     bots = []
     for participant in session.get_participants():
         bot = ParticipantBot(participant, load_player_bots=False)
         bots.append(bot)
     self.bots = bots
Пример #8
0
    def test_all_blocks_found(self):
        session = otree.session.create_session(
            session_config_name='templates_app',
            num_participants=1,
            use_cli_bots=True,
            bot_case_number=0,
        )

        participant = session.get_participants()[0]
        bot = ParticipantBot(participant, load_player_bots=False)
        bot.open_start_url()
        for block_name in [
            'scripts', 'app_scripts', 'global_scripts',
            'styles', 'app_styles', 'global_styles',
        ]:
            self.assertIn('my_{}'.format(block_name), bot.html)
Пример #9
0
 def setUp(self):
     call_command('create_session', 'skip_wait_page', "2")
     session = Session.objects.get()
     bots = []
     for participant in session.get_participants():
         bot = ParticipantBot(participant, load_player_bots=False)
         bots.append(bot)
     self.bots = bots
Пример #10
0
    def test_bots_check_html(self):

        session = otree.session.create_session(
            session_config_name='bots_check_html',
            num_participants=3,
        )

        p1, p2, p3 = session.get_participants()

        with self.settings(BOTS_CHECK_HTML=True):
            with self.assertRaises(MissingHtmlFormFieldError):
                ParticipantBot(p1)._play_individually()

            with self.assertRaises(MissingHtmlButtonError):
                ParticipantBot(p2)._play_individually()

            # should run without problems
            ParticipantBot(p3)._play_individually()
Пример #11
0
 def test_timeout_on_regular_page(self):
     participant = Participant.objects.get()
     bot = ParticipantBot(participant, load_player_bots=False)
     bot.open_start_url()
     bot.submit(Submission(views.Page1, {}, timeout_happened=True))
     # it should be OK to use timeout_happened=True, even if the page
     # has no timeout_seconds, because you can be simulating "advance slowest"
     bot.submit(Submission(views.PageWithoutTimeout, {}, timeout_happened=True))
Пример #12
0
    def test_bot_runs(self):

        session = otree.session.create_session(
            session_config_name='bots',
            num_participants=2,
            use_cli_bots=True,
            bot_case_number=0,
        )

        bots = []
        for participant in session.get_participants():
            bot = ParticipantBot(participant)
            bots.append(bot)
            bot.open_start_url()

        bot_runner = SessionBotRunner(bots, session.code)

        with self.assertRaises(ZeroDivisionError):
            bot_runner.play_until_end()
Пример #13
0
 def start_some_players(self, should_be_stuck):
     bots = []
     for player in self.group1.get_players():
         bot = ParticipantBot(player.participant, load_player_bots=False)
         bots.append(bot)
     for bot in bots:
         bot.open_start_url()
     for bot in bots:
         bot.open_start_url()
         self.assertEqual(bot.on_wait_page(), should_be_stuck)
Пример #14
0
 def start_some_players(self, should_be_stuck):
     bots = []
     for player in self.group1.get_players():
         bot = ParticipantBot(player.participant, load_player_bots=False)
         bots.append(bot)
     for bot in bots:
         bot.open_start_url()
     for bot in bots:
         bot.open_start_url()
         self.assertEqual(bot.on_wait_page(), should_be_stuck)
Пример #15
0
 def submit_form(self, values, timeout_happened):
     participant = Participant.objects.get()
     bot = ParticipantBot(participant, load_player_bots=False)
     bot.open_start_url()
     bot.submit(
         Submission(views.Page1, values, timeout_happened=timeout_happened))
Пример #16
0
 def submit_form(self, values, timeout_happened):
     participant = Participant.objects.get()
     bot = ParticipantBot(participant, load_player_bots=False)
     bot.open_start_url()
     bot.submit(Submission(views.Page1, values, timeout_happened=timeout_happened))