Exemplo n.º 1
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.º 2
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.º 3
0
    def test_commander_ignores_case_of_message_senders(self):
        command_string = "!green_group_stay_close_to_homing_sector_MG-7"
        admins = ["admIral_akbar"]
        test_response = ("admiral_Akbar", command_string)
        dont_sleep = Time(dont_print).sleep
        mock_connection = Connection()
        spy = Spy_Command()
        commands = [(command_string, spy.ping, ["admin_only"])]
        s = Subject(commands, admins, mock_connection, dont_print, dont_sleep)

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

        self.assertEqual(spy._history[-1], test_response)
Exemplo n.º 4
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)
Exemplo n.º 5
0
    def test_commander_logs_when_an_admin_makes_an_admin_only_command(self):
        command_string = "!green_group_stay_close_to_homing_sector_MG-7"
        admins = ["admiral_akbar"]
        test_response = (admins[0], command_string)
        dont_sleep = Time(dont_print).sleep
        mock_connection = Connection()
        spy = Spy_Log()
        commands = [(command_string, Spy_Command().ping, ["admin_only"])]
        s = Subject(commands, admins, mock_connection, spy.log, dont_sleep)

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

        expected_log = Log.good_admin(admins[0], command_string)
        self.assertEqual(spy._history[-1], expected_log)
Exemplo n.º 6
0
    def test_commander_cares_about_exact_command_strings(self):
        command_string = "An Exact String To Match"
        test_response = ("not_an_admin", "!anExact_string-toMATCH")
        no_admins = []
        dont_sleep = Time(dont_print).sleep
        mock_connection = Connection()
        spy = Spy_Command()
        no_validations = []
        commands = [(command_string, 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_and_close, mock_connection, test_response)

        self.assertEqual(len(spy._history), 0)
Exemplo n.º 7
0
    def test_commander_calls_command_when_a_non_admin_attempts_an_open_command(
            self):
        command_string = "!arbitrary_open_command"
        test_response = ("not_an_admin", command_string)
        no_admins = []
        dont_sleep = Time(dont_print).sleep
        mock_connection = Connection()
        spy = Spy_Command()
        no_validations = []
        commands = [(command_string, 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_and_close, mock_connection, test_response)

        self.assertEqual(spy._history[-1], test_response)
Exemplo n.º 8
0
    def test_commander_logs_when_any_chat_participant_makes_an_open_command(
            self):
        command_string = "!everythings_fine_we're_all_fine_here_situation_normal"
        no_admins = []
        test_response = ("han_solo", command_string)
        dont_sleep = Time(dont_print).sleep
        mock_connection = Connection()
        spy = Spy_Log()
        no_validations = []
        commands = [(command_string, Spy_Command().ping, no_validations)]
        s = Subject(commands, no_admins, mock_connection, spy.log, dont_sleep)

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

        expected_log = Log.good_command(test_response[0], command_string)
        self.assertEqual(spy._history[-1], expected_log)
Exemplo n.º 9
0
    def test_commander_can_recieve_commands_from_connection_asynchronously(
            self):
        test_responses = self.chat_messages()
        command_string = test_responses[3][1]

        no_admins = []
        dont_sleep = Time(dont_print).sleep
        mock_connection = Connection()
        spy = Spy_Command()
        no_validations = []
        commands = [(command_string, 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[-1], test_responses[3])
        self.assertEqual(s.last_response, test_responses[-1])