def test_unexpected_exception(self):
     # GIVEN
     when(self.console.storage).getClient(anything()).thenRaise(NotImplementedError())
     joe = FakeClient(console=self.console, name="Joe", guid="joe_guid")
     # WHEN
     with patch.object(self.console, "error") as error_mock:
         joe.auth()
     # THEN
     error_mock.assert_called_with('Auth self.console.storage.getClient(client) - Client<@0:joe_guid|:"Joe":None>',
                                exc_info=ANY)
class Test_commands(CalladminTestCase):

    def setUp(self):
        CalladminTestCase.setUp(self)
        self.conf = CfgConfigParser()
        self.conf.loadFromString(dedent(r"""
            [teamspeak]
            ip: 127.0.0.1
            port: 10011
            serverid: 1
            username: fakeusername
            password: fakepassword
            msg_groupid: -1

            [settings]
            treshold: 3600
            useirc: no

            [commands]
            calladmin: user
        """))

        self.p = CalladminPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        with logging_disabled():
            from b3.fake import FakeClient

        self.mike = FakeClient(console=self.console, name="Mike", guid="mikeguid", groupBits=1)
        self.bill = FakeClient(console=self.console, name="Bill", guid="billguid", groupBits=16)

    ####################################################################################################################
    ##                                                                                                                ##
    ##  TEST EVT_CLIENT_CONNECT                                                                                       ##
    ##                                                                                                                ##
    ####################################################################################################################

    def test_admin_connect_with_active_request(self):
        # GIVEN
        self.p.send_teamspeak_message = Mock()
        self.mike.connects('1')
        self.mike.says('!calladmin test reason')
        # WHEN
        self.mike.clearMessageHistory()
        self.bill.connects('2')
        self.bill.auth()
        # THEN
        self.p.send_teamspeak_message.assert_has_calls([call('[B][ADMIN REQUEST][/B] [B]Mike[/B] requested an admin on [B]Test Server[/B] : [B]test reason[/B]')])
        self.p.send_teamspeak_message.assert_has_calls([call('[B][ADMIN REQUEST][/B] [B]Bill [40][/B] connected to [B]Test Server[/B]')])
        self.assertListEqual(['[ADMIN ONLINE] Bill [40]'], self.mike.message_history)
        self.assertIsNone(self.p.adminRequest)

    ####################################################################################################################
    ##                                                                                                                ##
    ##  TEST EVT_CLIENT_DISCONNECT                                                                                    ##
    ##                                                                                                                ##
    ####################################################################################################################

    def test_client_disconnect_with_active_request(self):
        # GIVEN
        self.p.send_teamspeak_message = Mock()
        self.mike.connects('1')
        self.mike.says('!calladmin test reason')
        # WHEN
        self.mike.disconnects()
        # THEN
        self.p.send_teamspeak_message.assert_has_calls([call('[B][ADMIN REQUEST][/B] [B]Mike[/B] disconnected from [B]Test Server[/B]')])
        self.assertIsNone(self.p.adminRequest)