def test_questioner_includes_the_winners_name_when_they_answer_correctly_immediately(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     mock_connection = Connection()
     mock_connection.last_response = ("happy_lass", "OMG Han! Chewie! They're all here!")
     s = Subject(mock_connection, question, Questions_Asked(), Player_Scores(), Timer())
     s.go()
     self.assertTrue(mock_connection.last_response[0] in mock_connection._message)
 def test_questioner_ignores_incorect_answers_from_connection(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     mock_connection = Connection()
     mock_connection.last_response = ("trivvy_fan", "The Wrong Answer")
     s = Subject(mock_connection, question, Questions_Asked(), Player_Scores(), Timer())
     s.go()
     self.assertTrue(mock_connection._message in Chat.unanswered_questions)
 def test_questioner_records_the_winner_when_they_answer_correctly(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     mock_connection = Connection()
     mock_player_scores = Player_Scores()
     mock_connection.last_response = ("happy_lass", "OMG Han! Chewie! They're all here!")
     s = Subject(mock_connection, question, Questions_Asked(), mock_player_scores, Timer())
     s.go()
     self.assertEqual(mock_connection.last_response[0], mock_player_scores._score)
 def test_questioner_does_not_record_the_player_when_they_answer_incorrectly(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     mock_connection = Connection()
     mock_player_scores = Player_Scores()
     mock_connection.last_response = ("wrong_man", "a model representing a scene with three-dimensional figures")
     s = Subject(mock_connection, question, Questions_Asked(), mock_player_scores, Timer())
     s.go()
     self.assertEqual("Not Yet Called.", mock_player_scores._score)
Exemplo n.º 5
0
    def test_game_runs_through_a_tiny_game_flow_example(self):
        questions = [{
            'Round': 1,
            'Ask': "What also floats in water?",
            'Answer': "A Duck!"
        }, {
            'Round': 2,
            'Ask':
            "What is the average airspeed velocity of an unladen swallow?",
            'Answer': "What do you mean? African or European?"
        }]
        mock_connection = Connection()
        mock_player_scores = Player_Scores()
        mock_questions_asked = Questions_Asked()
        s = Subject(mock_connection, questions, mock_questions_asked,
                    mock_player_scores, Timer())

        with ThreadPoolExecutor(max_workers=2) as e:
            e.submit(s.go)
            e.submit(self.chat_thread, mock_connection)

        self.assertTrue(mock_player_scores._top_players[0][0] in
                        mock_connection._message_list[0])
        self.assertTrue(
            str(questions[0]["Round"]) in mock_connection._message_list[1])
        self.assertTrue(
            str(questions[1]["Ask"] not in mock_connection._message_list))
        self.assertTrue(mock_player_scores._game_winners[0][0] not in
                        mock_connection._message)

        mock_connection._message_list = []
        with ThreadPoolExecutor(max_workers=2) as e:
            e.submit(s.go)
            e.submit(self.chat_thread, mock_connection)

        self.assertTrue(
            str(questions[1]["Round"]) in mock_connection._message_list[1])
        self.assertTrue(
            mock_player_scores._game_winners[0][0] in mock_connection._message)

        mock_connection._message_list = []
        with ThreadPoolExecutor(max_workers=2) as e:
            e.submit(s.go)
            e.submit(self.chat_thread, mock_connection)

        self.assertTrue(mock_player_scores._top_players[0][0] in
                        mock_connection._message_list[0])
        self.assertTrue(
            str(questions[0]["Round"]) in mock_connection._message_list[1])
        self.assertTrue(
            str(questions[1]["Ask"] not in mock_connection._message_list))
        self.assertTrue(mock_player_scores._game_winners[0][0] not in
                        mock_connection._message)
Exemplo n.º 6
0
    def test_commander_logs_when_a_non_admin_attempts_a_stop_command(self):
        command_string = "!stop"
        test_response = ("not_an_admin", command_string)
        no_admins = []
        dont_sleep = Time(dont_print).sleep
        mock_connection = Connection()
        spy = Spy_Log()
        commands = [(command_string, Spy_Command().ping, ["admin_only"])]
        s = Subject(commands, no_admins, mock_connection, spy.log, dont_sleep)

        mock_connection.last_response = test_response
        s.check_connection_last_message()

        expected_log = Log.bad_admin(test_response[0], test_response[1])
        self.assertEqual(spy._history[-1], expected_log)
Exemplo n.º 7
0
 def test_round_tells_player_scores_to_reset_scores_for_a_new_round_at_the_end_of_its_go(
         self):
     questions = [
         {
             'Round': 2,
             'Ask': 'What is your name?',
             'Answer': 'Sir Lancelot of Camelot'
         },
         {
             'Round': 2,
             'Ask': 'What is your quest?',
             'Answer': 'To seek the Holy Grail'
         },
         {
             'Round': 2,
             'Ask': 'What is your favorite color?',
             'Answer': 'Blue'
         },
     ]
     mock_player_scores = Player_Scores()
     s = Subject(Connection(), questions, Questions_Asked(),
                 mock_player_scores, Timer())
     s.end()
     self.assertEqual(mock_player_scores._next_round_called,
                      "Round Scores Reset")
 def test_questioner_gives_its_ask(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     subject = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     self.assertEqual(subject.ask, "What's a Diorama?")
    def test_graceful_shutdown_sends_the_chat_a_goodnight_message(self):
        mock_connection = Connection()
        _message = "irrelevant in this instance"

        stop.graceful_shutdown(mock_connection, _message)

        self.assertEqual(mock_connection._message, Chat.good_night)
Exemplo n.º 10
0
    def test_commander_can_still_recieve_commands_while_a_long_running_process_runs(
            self):
        test_responses = self.chat_messages()
        expected_penultimate_message = test_responses[0]
        expected_last_command_message = test_responses[-1]
        long_command = expected_penultimate_message[1]
        short_command = expected_last_command_message[1]

        no_admins = []
        dont_sleep = Time(dont_print).sleep
        mock_connection = Connection()
        spy = Spy_Command()
        no_validations = []
        commands = [
            (long_command, spy.long_run, no_validations),
            (short_command, spy.ping, no_validations),
        ]
        s = Subject(commands, no_admins, mock_connection, dont_print,
                    dont_sleep)

        with ThreadPoolExecutor(max_workers=2) as e:
            e.submit(s.listen_for_commands)
            e.submit(self.chat_room, mock_connection)

        self.assertEqual(spy._history[-3], expected_penultimate_message)
        self.assertEqual(spy._history[-2], expected_last_command_message)
        self.assertEqual(spy._history[-1],
                         (expected_penultimate_message[1], "completed"))
        self.assertEqual(len(spy._history), 3)
Exemplo n.º 11
0
    def test_round_lets_the_chat_know_when_the_round_is_over_by_listing_round_winners(
            self):
        questions = [
            {
                'Round': 2,
                'Ask': 'What is your name?',
                'Answer': 'Sir Lancelot of Camelot'
            },
            {
                'Round': 2,
                'Ask': 'What is your quest?',
                'Answer': 'To seek the Holy Grail'
            },
            {
                'Round': 2,
                'Ask': 'What is your favorite color?',
                'Answer': 'Blue'
            },
        ]
        mock_connection = Connection()
        mock_player_scores = Player_Scores()
        gold = f"{mock_player_scores._round_winners[0][0]}: {mock_player_scores._round_winners[0][1]}"
        silver = f"{mock_player_scores._round_winners[1][0]}: {mock_player_scores._round_winners[1][1]}"
        bronze = f"{mock_player_scores._round_winners[2][0]}: {mock_player_scores._round_winners[2][1]}"

        s = Subject(mock_connection, questions, Questions_Asked(),
                    mock_player_scores, Timer())
        s.go()

        self.assertTrue(gold in mock_connection._message)
        self.assertTrue(silver in mock_connection._message)
        self.assertTrue(bronze in mock_connection._message)
Exemplo n.º 12
0
    def test_commander_does_not_call_command_when_a_non_admin_attempts_an_admin_only_command(
            self):
        command_string = "!arbitrary_admin_command"
        test_response = ("not_an_admin", command_string)
        no_admins = []
        dont_sleep = Time(dont_print).sleep
        mock_connection = Connection()
        spy = Spy_Command()
        commands = [(command_string, spy.ping, ["admin_only"])]
        s = Subject(commands, no_admins, mock_connection, dont_print,
                    dont_sleep)

        mock_connection.last_response = test_response
        s.check_connection_last_message()

        self.assertEqual(len(spy._history), 0)
 def test_questioner_first_hint_returns_2_out_of_3_chars_in_answer(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     s = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     actual = s.first_hint()
     self.assertEqual(actual, "O__ __n__C__w__!__h__'__ __l__e__!")
 def test_questioner_second_hint_returns_no_vowels_in_answer(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     s = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     actual = s.second_hint()
     self.assertEqual(actual, "_MG H_n! Ch_w__! Th_y'r_ _ll h_r_!")
 def test_questioner_doesnt_care_if_there_are_extra_fields(self):
     question = {
         'Round': 1,
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!",
         'Answer2': 'D\'oh!'
     }
     Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
    def test_graceful_shutdown_sets_connection_to_stop_running(self):
        mock_connection = Connection()
        _message = "irrelevant in this instance"

        self.assertTrue(mock_connection.keep_IRC_running)
        stop.graceful_shutdown(mock_connection, _message)

        self.assertFalse(mock_connection.keep_IRC_running)
Exemplo n.º 17
0
    def test_game_init_rounds_returns_an_empty_array_if_no_questions_are_given(
            self):
        initial_questions = []

        s = Subject(Connection(), initial_questions, Questions_Asked(),
                    Player_Scores(), Timer())
        actual_questions = s.init_rounds()

        self.assertEqual(actual_questions, initial_questions)
 def test_questioner_identifies_a_correct_answer_inside_a_message(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     s = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     participant_answer = "I would say OMG Han! Chewie! They're all here! what do you think?"
     actual = s.check_answer(participant_answer)
     self.assertEqual(actual, True)
 def test_questioner_lets_the_chat_know_its_moving_on(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     mock_connection = Connection()
     s = Subject(mock_connection, question, Questions_Asked(), Player_Scores(), Timer())
     s.go()
     self.assertTrue(mock_connection._message in Chat.unanswered_questions)
 def test_questioner_identifies_a_correct_answer_ignoring_case(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     s = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     participant_answer = "OmG hAn! CheWIe! theY're all hEre!"
     actual = s.check_answer(participant_answer)
     self.assertEqual(actual, True)
 def test_questioner_identifies_a_correct_answer_ignoring_internal_whitespace(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     s = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     participant_answer = " \t \rOMGHan!   Chewie! \t They're all here!\r \n "
     actual = s.check_answer(participant_answer)
     self.assertEqual(actual, True)
 def test_questioner_knows_itself_and_expects_strings_as_input(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     s = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     self.assertEqual(s.ask, "What's a Diorama?")
     self.assertEqual(type(s.ask), str)
     self.assertEqual(type(s.ask), str)
 def test_questioner_logs_that_it_is_done_with_its_question(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     mock_questions_asked = Questions_Asked()
     s = Subject(Connection(), question, mock_questions_asked, Player_Scores(), Timer())
     s.end()
     self.assertEqual(mock_questions_asked._log[0], question)
 def test_questioner_identifies_a_correct_answer_even_with_garbage_characters_interleaved(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     participant_answer = "O!M@G#H$a%n^?&C*(h)e_w-i+e=!{T}[h]e|y'r\\e:a;l\"l'<h>e,r.e/"
     s = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     actual = s.check_answer(participant_answer)
     self.assertEqual(actual, True)
 def test_questioner_identifies_an_incorrect_answer(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     s = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     participant_answer = "I don't know, some kind of goblin-man."
     actual = s.check_answer(participant_answer)
     self.assertEqual(actual, False)
 def test_questioner_asks_a_question_to_the_chat_to_start(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     mock_connection = Connection()
     s = Subject(mock_connection, question, Questions_Asked(), Player_Scores(), Timer())
     s.start()
     self.assertEqual(mock_connection._message, "What's a Diorama?")
Exemplo n.º 27
0
 def test_game_does_not_load_questions_in_the_questions_asked_list_to_rounds(
         self):
     initial_questions = [{
         'Round': 1,
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }, {
         'Round': 2,
         'Ask': 'What is your name?',
         'Answer': 'Sir Lancelot of Camelot'
     }, {
         'Round': 2,
         'Ask': 'What is your quest?',
         'Answer': 'To seek the Holy Grail'
     }, {
         'Round': 2,
         'Ask': 'What is your favorite color?',
         'Answer': 'Blue'
     }, {
         'Round': 3,
         'Ask': 'Are you a god?',
         'Answer': 'YES!'
     }]
     mock_questions_asked = Questions_Asked()
     mock_questions_asked._log = [{
         'Round':
         1,
         'Ask':
         "What's a Diorama?",
         'Answer':
         "OMG Han! Chewie! They're all here!"
     }, {
         'Round': 2,
         'Ask': 'What is your name?',
         'Answer': 'Sir Lancelot of Camelot'
     }]
     expected_questions = [
         [{
             'Round': 2,
             'Ask': 'What is your quest?',
             'Answer': 'To seek the Holy Grail'
         }, {
             'Round': 2,
             'Ask': 'What is your favorite color?',
             'Answer': 'Blue'
         }],
         [{
             'Round': 3,
             'Ask': 'Are you a god?',
             'Answer': 'YES!'
         }],
     ]
     s = Subject(Connection(), initial_questions, mock_questions_asked,
                 Player_Scores(), Timer())
     actual_questions = s.list_by_rounds(initial_questions)
     self.assertEqual(actual_questions, expected_questions)
    def go_command_skips_running_the_next_trivia_round_if_theres_an_error(
            self):
        s = Go("mocks/config.txt", "mocks/bad_triviaset.csv",
               Questions_Asked(), Player_Scores(), dont_print)

        mock_connection = Connection()
        _message = "irrelevant in this instance"
        s.run_the_next_trivia_round(mock_connection, _message)

        self.assertEqual(mock_connection._message, 'No message recieved.')
    def test_go_command_logs_if_theres_an_error(self):
        spy = Spy_Log()
        s = Go("mocks/config.txt", "mocks/bad_triviaset.csv",
               Questions_Asked(), Player_Scores(), spy.log)

        mock_connection = Connection()
        _message = "irrelevant in this instance"
        s.run_the_next_trivia_round(mock_connection, _message)

        self.assertTrue("Ask" in spy._history[0] and "4" in spy._history[0])
Exemplo n.º 30
0
    def test_game_clears_logs_if_it_reaches_the_end_of_the_game(self):
        questions = [{'Round': 3, 'Ask': 'Are you a god?', 'Answer': 'YES!'}]
        mock_questions_asked = Questions_Asked()

        s = Subject(Connection(), questions, mock_questions_asked,
                    Player_Scores(), Timer())
        s.start()
        s.end()

        self.assertEqual(mock_questions_asked._clear_received, True)