コード例 #1
0
class Test_client_connects(PluginTestCase):
    def setUp(self):
        super(Test_client_connects, self).setUp()
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""[foo]""")
        self.p = VacbanPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        when(self.p)._checkConnectedPlayers().thenReturn()
        self.p.onStartup()
        when(self.p)._query_service(
            anything()).thenReturn(vac_response_not_banned)

    def test_player_connects(self):
        # GIVEN
        with patch.object(self.p, '_checkClient') as mock_checkClient:
            # WHEN
            self.joe.connects("slot1")
            self.p.stop_worker()
            self.p._workerThread.join()
        # THEN
        mock_checkClient.assert_has_calls([call(self.joe)])
        self.assertEqual(1, mock_checkClient.call_count)

    def test_2_players_connect(self):
        # GIVEN
        with patch.object(self.p, '_checkClient') as mock_checkClient:
            # WHEN
            self.joe.connects("slot1")
            self.simon.connects("slot2")
            self.p.stop_worker()
            self.p._workerThread.join()
            # THEN
        mock_checkClient.assert_has_calls([call(self.joe), call(self.simon)])
        self.assertEqual(2, mock_checkClient.call_count)
コード例 #2
0
class Test_client_connects(PluginTestCase):

    def setUp(self):
        super(Test_client_connects, self).setUp()
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""[foo]""")
        self.p = VacbanPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        when(self.p)._checkConnectedPlayers().thenReturn()
        self.p.onStartup()
        when(self.p)._query_service(anything()).thenReturn(vac_response_not_banned)


    def test_player_connects(self):
        # GIVEN
        with patch.object(self.p, '_checkClient') as mock_checkClient:
            # WHEN
            self.joe.connects("slot1")
            self.p.stop_worker()
            self.p._workerThread.join()
        # THEN
        mock_checkClient.assert_has_calls([
            call(self.joe)
        ])
        self.assertEqual(1, mock_checkClient.call_count)



    def test_2_players_connect(self):
        # GIVEN
        with patch.object(self.p, '_checkClient') as mock_checkClient:
            # WHEN
            self.joe.connects("slot1")
            self.simon.connects("slot2")
            self.p.stop_worker()
            self.p._workerThread.join()
            # THEN
        mock_checkClient.assert_has_calls([
            call(self.joe),
            call(self.simon)
        ])
        self.assertEqual(2, mock_checkClient.call_count)
コード例 #3
0
class Test_config(PluginTestCase):

    def setUp(self):
        super(Test_config, self).setUp()
        self.conf = CfgConfigParser()
        self.p = VacbanPlugin(self.console, self.conf)
        logger = logging.getLogger('output')
        logger.setLevel(logging.INFO)

    def tearDown(self):
        self.p.stop_worker()


    def test_empty_config(self):
        self.conf.loadFromString("""
[foo]
        """)
        self.p.onLoadConfig()
        # should not raise any error


    #-------------------- load_config_preferences ------------------------

    def test_load_config_preferences__message_type__normal(self):
        # GIVEN
        self.conf.loadFromString("""
[preferences]
message_type: normal
        """)
        # WHEN
        self.p.load_config_preferences()
        # THEN
        self.assertEqual(self.console.say, self.p._message_method)


    def test_load_config_preferences__message_type__big(self):
        # GIVEN
        self.conf.loadFromString("""
[preferences]
message_type: big
        """)
        # WHEN
        self.p.load_config_preferences()
        # THEN
        self.assertEqual(self.console.saybig, self.p._message_method)


    def test_load_config_preferences__message_type__empty(self):
        # GIVEN
        self.conf.loadFromString("""
[preferences]
message_type:
        """)
        # WHEN
        self.p.load_config_preferences()
        # THEN
        self.assertEqual(self.p.info, self.p._message_method)


    def test_load_config_preferences__message_type__f00(self):
        # GIVEN
        self.conf.loadFromString("""
[preferences]
message_type: f00
        """)
        # WHEN
        self.p.load_config_preferences()
        # THEN
        self.assertEqual(self.p.info, self.p._message_method)



    #-------------------- load_config_preferences ------------------------

    def test_messages__ban_message(self):
        # GIVEN
        self.conf.loadFromString("""
[messages]
; You can use the following keywords in your messages :
;   $clientname
;   $clientguid

;ban_message will be displayed to all players when a player is VAC banned
ban_message: VACBAN $clientname ($clientguid) f00
        """)
        # WHEN
        msg = self.p._make_message_for(self.joe)
        # THEN
        self.assertEqual("VACBAN Joe (joe_guid) f00", msg)
コード例 #4
0
class Test_config(PluginTestCase):
    def setUp(self):
        super(Test_config, self).setUp()
        self.conf = CfgConfigParser()
        self.p = VacbanPlugin(self.console, self.conf)
        logger = logging.getLogger('output')
        logger.setLevel(logging.INFO)

    def tearDown(self):
        self.p.stop_worker()

    def test_empty_config(self):
        self.conf.loadFromString("""
[foo]
        """)
        self.p.onLoadConfig()
        # should not raise any error

    #-------------------- load_config_preferences ------------------------

    def test_load_config_preferences__message_type__normal(self):
        # GIVEN
        self.conf.loadFromString("""
[preferences]
message_type: normal
        """)
        # WHEN
        self.p.load_config_preferences()
        # THEN
        self.assertEqual(self.console.say, self.p._message_method)

    def test_load_config_preferences__message_type__big(self):
        # GIVEN
        self.conf.loadFromString("""
[preferences]
message_type: big
        """)
        # WHEN
        self.p.load_config_preferences()
        # THEN
        self.assertEqual(self.console.saybig, self.p._message_method)

    def test_load_config_preferences__message_type__empty(self):
        # GIVEN
        self.conf.loadFromString("""
[preferences]
message_type:
        """)
        # WHEN
        self.p.load_config_preferences()
        # THEN
        self.assertEqual(self.p.info, self.p._message_method)

    def test_load_config_preferences__message_type__f00(self):
        # GIVEN
        self.conf.loadFromString("""
[preferences]
message_type: f00
        """)
        # WHEN
        self.p.load_config_preferences()
        # THEN
        self.assertEqual(self.p.info, self.p._message_method)

    #-------------------- load_config_preferences ------------------------

    def test_messages__ban_message(self):
        # GIVEN
        self.conf.loadFromString("""
[messages]
; You can use the following keywords in your messages :
;   $clientname
;   $clientguid

;ban_message will be displayed to all players when a player is VAC banned
ban_message: VACBAN $clientname ($clientguid) f00
        """)
        # WHEN
        msg = self.p._make_message_for(self.joe)
        # THEN
        self.assertEqual("VACBAN Joe (joe_guid) f00", msg)