class Test_commands(PluginTestCase):
    def setUp(self):
        super(Test_commands, self).setUp()
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""[commands]
vaccheck: 20
        """)
        self.p = VacbanPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        when(self.p)._query_service(
            anything()).thenReturn(vac_response_not_banned)
        self.moderator.connects("2")

    def test_vaccheck(self):
        # GIVEN
        self.moderator.message_history = []
        # WHEN
        with patch.object(
                self.p,
                '_checkConnectedPlayers') as mock_checkConnectedPlayers:
            self.moderator.says("!vaccheck")
        # THEN
        self.assertEqual(['checking players ...', 'done'],
                         self.moderator.message_history)
        self.assertEqual(1, mock_checkConnectedPlayers.call_count)
class Test_commands(PluginTestCase):
    def setUp(self):
        super(Test_commands, self).setUp()
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""[commands]
vaccheck: 20
        """)
        self.p = VacbanPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        when(self.p)._query_service(anything()).thenReturn(vac_response_not_banned)
        self.moderator.connects("2")



    def test_vaccheck(self):
        # GIVEN
        self.moderator.message_history = []
        # WHEN
        with patch.object(self.p, '_checkConnectedPlayers') as mock_checkConnectedPlayers:
            self.moderator.says("!vaccheck")
        # THEN
        self.assertEqual(['checking players ...', 'done'], self.moderator.message_history)
        self.assertEqual(1, mock_checkConnectedPlayers.call_count)
Пример #3
0
 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 setUp(self):
        super(Test_commands, self).setUp()
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""[commands]
vaccheck: 20
        """)
        self.p = VacbanPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        when(self.p)._query_service(
            anything()).thenReturn(vac_response_not_banned)
        self.moderator.connects("2")
Пример #5
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)
 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)
class Test_vac_service(PluginTestCase):
    def setUp(self):
        PluginTestCase.setUp(self)
        self.conf = CfgConfigParser()
        self.p = VacbanPlugin(self.console, self.conf)

    def test__checkClient__banned(self):
        # GIVEN
        when(self.p)._query_service(anything()).thenReturn(vac_response_banned)
        self.joe.connects("slot1")
        # WHEN
        with patch.object(self.p,
                          "_takeActionAgainst") as mock_takeActionAgainst:
            self.p._checkClient(self.joe)
        # THEN
        mock_takeActionAgainst.assert_called_with(self.joe)
        self.assertEqual(1, mock_takeActionAgainst.call_count)

    def test__checkClient__not_banned(self):
        # GIVEN
        when(self.p)._query_service(
            anything()).thenReturn(vac_response_not_banned)
        self.joe.connects("slot1")
        # WHEN
        with patch.object(self.p,
                          "_takeActionAgainst") as mock_takeActionAgainst:
            self.p._checkClient(self.joe)
        # THEN
        self.assertEqual(0, mock_takeActionAgainst.call_count)

    def test__checkClient__not_found(self):
        # GIVEN
        when(self.p)._query_service(
            anything()).thenReturn(vac_response_not_found)
        self.joe.connects("slot1")
        # WHEN
        with patch.object(self.p,
                          "_takeActionAgainst") as mock_takeActionAgainst:
            self.p._checkClient(self.joe)
        # THEN
        self.assertEqual(0, mock_takeActionAgainst.call_count)

    def test__checkClient__error(self):
        # GIVEN
        when(self.p)._query_service(anything()).thenRaise(
            NotImplementedError('foo'))
        self.joe.connects("slot1")
        # WHEN
        with patch.object(self.p,
                          "_takeActionAgainst") as mock_takeActionAgainst:
            self.p._checkClient(self.joe)
        # THEN
        self.assertEqual(0, mock_takeActionAgainst.call_count)
class Test_vac_service(PluginTestCase):

    def setUp(self):
        PluginTestCase.setUp(self)
        self.conf = CfgConfigParser()
        self.p = VacbanPlugin(self.console, self.conf)


    def test__checkClient__banned(self):
        # GIVEN
        when(self.p)._query_service(anything()).thenReturn(vac_response_banned)
        self.joe.connects("slot1")
        # WHEN
        with patch.object(self.p, "_takeActionAgainst") as mock_takeActionAgainst:
            self.p._checkClient(self.joe)
        # THEN
        mock_takeActionAgainst.assert_called_with(self.joe)
        self.assertEqual(1, mock_takeActionAgainst.call_count)


    def test__checkClient__not_banned(self):
        # GIVEN
        when(self.p)._query_service(anything()).thenReturn(vac_response_not_banned)
        self.joe.connects("slot1")
        # WHEN
        with patch.object(self.p, "_takeActionAgainst") as mock_takeActionAgainst:
            self.p._checkClient(self.joe)
        # THEN
        self.assertEqual(0, mock_takeActionAgainst.call_count)


    def test__checkClient__not_found(self):
        # GIVEN
        when(self.p)._query_service(anything()).thenReturn(vac_response_not_found)
        self.joe.connects("slot1")
        # WHEN
        with patch.object(self.p, "_takeActionAgainst") as mock_takeActionAgainst:
            self.p._checkClient(self.joe)
        # THEN
        self.assertEqual(0, mock_takeActionAgainst.call_count)



    def test__checkClient__error(self):
        # GIVEN
        when(self.p)._query_service(anything()).thenRaise(NotImplementedError('foo'))
        self.joe.connects("slot1")
        # WHEN
        with patch.object(self.p, "_takeActionAgainst") as mock_takeActionAgainst:
            self.p._checkClient(self.joe)
        # THEN
        self.assertEqual(0, mock_takeActionAgainst.call_count)
    def setUp(self):
        super(Test_commands, self).setUp()
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""[commands]
vaccheck: 20
        """)
        self.p = VacbanPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        when(self.p)._query_service(anything()).thenReturn(vac_response_not_banned)
        self.moderator.connects("2")
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)
Пример #11
0
 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)
Пример #12
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)
 def setUp(self):
     PluginTestCase.setUp(self)
     self.conf = CfgConfigParser()
     self.p = VacbanPlugin(self.console, self.conf)
Пример #14
0
 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)
Пример #15
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)
 def setUp(self):
     PluginTestCase.setUp(self)
     self.conf = CfgConfigParser()
     self.p = VacbanPlugin(self.console, self.conf)