class mixin_cmd_headshots(object):
    def setUp(self):
        super(mixin_cmd_headshots, self).setUp()
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""
[settings]
reset_headshots: yes
min_level_headshots_cmd: 1
show_awards: yes
        """)
        self.p = HeadshotsurtPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        self.moderator.connects("2")


    def test_no_argument(self):
        self.moderator.message_history = []
        self.moderator.says("!headshots")
        self.assertEqual(['You made no headshot'], self.moderator.message_history)

    def test_unknown_player(self):
        self.moderator.message_history = []
        self.moderator.says("!headshots f00")
        self.assertEqual(['No players found matching f00'], self.moderator.message_history)

    def test_joe(self):
        self.joe.connects('3')
        self.moderator.message_history = []
        self.moderator.says("!headshots joe")
        self.assertEqual(['Joe made no headshot'], self.moderator.message_history)

    def test_alias(self):
        self.moderator.message_history = []
        self.moderator.says("!hs")
        self.assertEqual(['You made no headshot'], self.moderator.message_history)

    def test_has_1_headshots(self):
        self.joe.connects('3')
        with patch.object(self.p, "is_headshot", return_value=True):
            self.moderator.kills(self.joe)
        self.moderator.message_history = []
        self.moderator.says("!headshots")
        self.assertEqual(['You made 1 headshot'], self.moderator.message_history)

    def test_has_3_headshots(self):
        self.joe.connects('3')
        with patch.object(self.p, "is_headshot", return_value=True):
            self.moderator.kills(self.joe)
            self.moderator.kills(self.joe)
            self.moderator.kills(self.joe)
        with patch.object(self.p, "is_headshot", return_value=False):
            self.moderator.kills(self.joe)
        self.moderator.message_history = []
        self.moderator.says("!headshots")
        self.assertEqual(['You made 3 headshots'], self.moderator.message_history)
class mixin_conf(object):
    def setUp(self):
        super(mixin_conf, self).setUp()
        self.conf = CfgConfigParser()
        self.p = HeadshotsurtPlugin(self.console, self.conf)
        logger = logging.getLogger('output')
        logger.setLevel(logging.INFO)

    def test_empty_config(self):
        self.conf.loadFromString("""
[foo]
        """)
        self.p.onLoadConfig()  # should not raise any error
        self.assertFalse(self.p._reset_headshots_stats)
        self.assertEqual(0, self.p._min_level_headshots_cmd)
        self.assertFalse(self.p._show_awards)

    # reset_headshots

    def test_reset_headshots__empty(self):
        self.conf.loadFromString("""
[settings]
reset_headshots:
        """)
        self.p.onLoadConfig()
        self.assertFalse(self.p._reset_headshots_stats)

    def test_reset_headshots__yes(self):
        self.conf.loadFromString("""
[settings]
reset_headshots: yes
        """)
        self.p.onLoadConfig()
        self.assertTrue(self.p._reset_headshots_stats)

    def test_reset_headshots__no(self):
        self.conf.loadFromString("""
[settings]
reset_headshots: no
        """)
        self.p.onLoadConfig()
        self.assertFalse(self.p._reset_headshots_stats)

    def test_reset_headshots__junk(self):
        self.conf.loadFromString("""
[settings]
reset_headshots: f00
        """)
        self.p.onLoadConfig()
        self.assertFalse(self.p._reset_headshots_stats)

    # min_level_headshots_cmd

    def test_min_level_headshots_cmd__empty(self):
        self.conf.loadFromString("""
[settings]
min_level_headshots_cmd:
        """)
        self.p.onLoadConfig()
        self.assertEqual(0, self.p._min_level_headshots_cmd)

    def test_min_level_headshots_cmd__nominal(self):
        self.conf.loadFromString("""
[settings]
min_level_headshots_cmd: 2
        """)
        self.p.onLoadConfig()
        self.assertEqual(2, self.p._min_level_headshots_cmd)

        self.conf.loadFromString("""
[settings]
min_level_headshots_cmd: 40
        """)
        self.p.onLoadConfig()
        self.assertEqual(40, self.p._min_level_headshots_cmd)

    def test_min_level_headshots_cmd__junk(self):
        self.conf.loadFromString("""
[settings]
min_level_headshots_cmd: f00
        """)
        self.p.onLoadConfig()
        self.assertEqual(0, self.p._min_level_headshots_cmd)

    # show_awards

    def test_show_awards__empty(self):
        self.conf.loadFromString("""
[settings]
show_awards:
        """)
        self.p.onLoadConfig()
        self.assertFalse(self.p._show_awards)

    def test_show_awards__yes(self):
        self.conf.loadFromString("""
[settings]
show_awards: yes
        """)
        self.p.onLoadConfig()
        self.assertTrue(self.p._show_awards)

    def test_show_awards__no(self):
        self.conf.loadFromString("""
[settings]
show_awards: no
        """)
        self.p.onLoadConfig()
        self.assertFalse(self.p._show_awards)

    def test_show_awards__junk(self):
        self.conf.loadFromString("""
[settings]
show_awards: f00
        """)
        self.p.onLoadConfig()
        self.assertFalse(self.p._show_awards)
class mixin_cmd_headshots(object):
    def setUp(self):
        super(mixin_cmd_headshots, self).setUp()
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""
[settings]
reset_headshots: yes
min_level_headshots_cmd: 1
show_awards: yes
        """)
        self.p = HeadshotsurtPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        self.moderator.connects("2")

    def test_no_argument(self):
        self.moderator.message_history = []
        self.moderator.says("!headshots")
        self.assertEqual(['You made no headshot'],
                         self.moderator.message_history)

    def test_unknown_player(self):
        self.moderator.message_history = []
        self.moderator.says("!headshots f00")
        self.assertEqual(['No players found matching f00'],
                         self.moderator.message_history)

    def test_joe(self):
        self.joe.connects('3')
        self.moderator.message_history = []
        self.moderator.says("!headshots joe")
        self.assertEqual(['Joe made no headshot'],
                         self.moderator.message_history)

    def test_alias(self):
        self.moderator.message_history = []
        self.moderator.says("!hs")
        self.assertEqual(['You made no headshot'],
                         self.moderator.message_history)

    def test_has_1_headshots(self):
        self.joe.connects('3')
        with patch.object(self.p, "is_headshot", return_value=True):
            self.moderator.kills(self.joe)
        self.moderator.message_history = []
        self.moderator.says("!headshots")
        self.assertEqual(['You made 1 headshot'],
                         self.moderator.message_history)

    def test_has_3_headshots(self):
        self.joe.connects('3')
        with patch.object(self.p, "is_headshot", return_value=True):
            self.moderator.kills(self.joe)
            self.moderator.kills(self.joe)
            self.moderator.kills(self.joe)
        with patch.object(self.p, "is_headshot", return_value=False):
            self.moderator.kills(self.joe)
        self.moderator.message_history = []
        self.moderator.says("!headshots")
        self.assertEqual(['You made 3 headshots'],
                         self.moderator.message_history)
class mixin_conf(object):

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


    def test_empty_config(self):
        self.conf.loadFromString("""
[foo]
        """)
        self.p.onLoadConfig() # should not raise any error
        self.assertFalse(self.p._reset_headshots_stats)
        self.assertEqual(0, self.p._min_level_headshots_cmd)
        self.assertFalse(self.p._show_awards)


    # reset_headshots

    def test_reset_headshots__empty(self):
        self.conf.loadFromString("""
[settings]
reset_headshots:
        """)
        self.p.onLoadConfig()
        self.assertFalse(self.p._reset_headshots_stats)

    def test_reset_headshots__yes(self):
        self.conf.loadFromString("""
[settings]
reset_headshots: yes
        """)
        self.p.onLoadConfig()
        self.assertTrue(self.p._reset_headshots_stats)

    def test_reset_headshots__no(self):
        self.conf.loadFromString("""
[settings]
reset_headshots: no
        """)
        self.p.onLoadConfig()
        self.assertFalse(self.p._reset_headshots_stats)

    def test_reset_headshots__junk(self):
        self.conf.loadFromString("""
[settings]
reset_headshots: f00
        """)
        self.p.onLoadConfig()
        self.assertFalse(self.p._reset_headshots_stats)



    # min_level_headshots_cmd

    def test_min_level_headshots_cmd__empty(self):
        self.conf.loadFromString("""
[settings]
min_level_headshots_cmd:
        """)
        self.p.onLoadConfig()
        self.assertEqual(0, self.p._min_level_headshots_cmd)

    def test_min_level_headshots_cmd__nominal(self):
        self.conf.loadFromString("""
[settings]
min_level_headshots_cmd: 2
        """)
        self.p.onLoadConfig()
        self.assertEqual(2, self.p._min_level_headshots_cmd)

        self.conf.loadFromString("""
[settings]
min_level_headshots_cmd: 40
        """)
        self.p.onLoadConfig()
        self.assertEqual(40, self.p._min_level_headshots_cmd)

    def test_min_level_headshots_cmd__junk(self):
        self.conf.loadFromString("""
[settings]
min_level_headshots_cmd: f00
        """)
        self.p.onLoadConfig()
        self.assertEqual(0, self.p._min_level_headshots_cmd)



    # show_awards

    def test_show_awards__empty(self):
        self.conf.loadFromString("""
[settings]
show_awards:
        """)
        self.p.onLoadConfig()
        self.assertFalse(self.p._show_awards)

    def test_show_awards__yes(self):
        self.conf.loadFromString("""
[settings]
show_awards: yes
        """)
        self.p.onLoadConfig()
        self.assertTrue(self.p._show_awards)

    def test_show_awards__no(self):
        self.conf.loadFromString("""
[settings]
show_awards: no
        """)
        self.p.onLoadConfig()
        self.assertFalse(self.p._show_awards)

    def test_show_awards__junk(self):
        self.conf.loadFromString("""
[settings]
show_awards: f00
        """)
        self.p.onLoadConfig()
        self.assertFalse(self.p._show_awards)