コード例 #1
0
ファイル: test_bot.py プロジェクト: EvaisaGiac/twitch-bot
    def test_blacklist_commands(self):
        dbPath = os.path.join(testPath, '__test_bot_blacklist_commands.sqlite')
        self._delete(dbPath)

        settings = Settings()
        settings.DATABASE_PATH = dbPath

        bot = Bot(settings,
                  None,
                  FakeWrapper,
                  logger=nullLogger,
                  wrap_irc=False)
        bot._initialize_models()
        bot._initialize_blacklists()

        lines = [
            "!blacklist foobar", "!blacklist --banTime=15m foobar2",
            "!unblacklist 1", "!unblacklist 2", "!whitelist foobar",
            "!unwhitelist 1"
        ]

        for line in lines:
            parts = line.split(" ")
            bot.irc_command("#tmp", "mod_user", parts[0][1:], parts[1:], 1)

        assert len(bot.blacklist_managers["#tmp"].blacklist) == 0
        assert len(bot.blacklist_managers["#tmp"].whitelist) == 0
コード例 #2
0
ファイル: test_bot.py プロジェクト: EvaisaGiac/twitch-bot
    def test_quote_suffix(self):
        dbPath = os.path.join(testPath, '__test_bot_quote_suffix.sqlite')
        self._delete(dbPath)

        settings = Settings()
        settings.QUOTE_AUTO_SUFFIX = True

        now = datetime.now()
        expected_suffix = " - {streamer} @ {year}-{month:02}-{day:02}".format(
            streamer=settings.CHANNEL_LIST["#tmp"],
            year=int(now.strftime("%Y")),
            month=int(now.strftime("%m")),
            day=int(now.strftime("%d")))

        bot = Bot(settings,
                  None,
                  FakeWrapper,
                  logger=nullLogger,
                  wrap_irc=False)
        bot._initialize_models()
        bot._add_quote("#tmp", "foobar", ["test"], timestamp=now)
        quote_id, quote = bot._get_model("#tmp", "quotes").get_random_quote()

        expected = "test" + expected_suffix

        assert quote == expected
コード例 #3
0
    def test_blacklist_commands(self):
        dbPath = os.path.join(testPath, '__test_bot_blacklist_commands.sqlite')
        self._delete(dbPath)

        settings = Settings()
        settings.DATABASE_PATH = dbPath

        bot = Bot(settings, None, FakeWrapper, logger=nullLogger,
                  wrap_irc=False)
        bot._initialize_models()
        bot._initialize_blacklists()

        lines = [
            "!blacklist foobar",
            "!blacklist --banTime=15m foobar2",
            "!unblacklist 1",
            "!unblacklist 2",
            "!whitelist foobar",
            "!unwhitelist 1"
        ]

        for line in lines:
            parts = line.split(" ")
            bot.irc_command("#tmp", "mod_user", parts[0][1:], parts[1:], 1)

        assert len(bot.blacklist_managers["#tmp"].blacklist) == 0
        assert len(bot.blacklist_managers["#tmp"].whitelist) == 0
コード例 #4
0
    def test_get_random_quote(self):
        dbPath = os.path.join(testPath, '__test_bot_get_random_quote.sqlite')
        self._delete(dbPath)

        settings = Settings()
        settings.DATABASE_PATH = dbPath

        bot = Bot(settings, None, FakeWrapper, logger=nullLogger,
                  wrap_irc=False)
        bot._initialize_models()
        quote_id, quote = bot._get_model("#tmp", "quotes").get_random_quote()

        assert quote_id is None
        assert quote is None
コード例 #5
0
    def test_update_global_value(self):
        dbPath = os.path.join(testPath,
                              '__test_bot_update_global_value.sqlite')
        self._delete(dbPath)

        settings = Settings()
        settings.DATABASE_PATH = dbPath

        bot = Bot(settings, None, FakeWrapper, logger=nullLogger,
                  wrap_irc=False)
        bot._initialize_models()
        bot.update_global_value("#tmp", "test", {"key1": "value1"})

        data = bot._load_channel_data("#tmp")

        assert data["test"]["key1"] == "value1"
コード例 #6
0
ファイル: test_bot.py プロジェクト: EvaisaGiac/twitch-bot
    def test_get_random_quote(self):
        dbPath = os.path.join(testPath, '__test_bot_get_random_quote.sqlite')
        self._delete(dbPath)

        settings = Settings()
        settings.DATABASE_PATH = dbPath

        bot = Bot(settings,
                  None,
                  FakeWrapper,
                  logger=nullLogger,
                  wrap_irc=False)
        bot._initialize_models()
        quote_id, quote = bot._get_model("#tmp", "quotes").get_random_quote()

        assert quote_id is None
        assert quote is None
コード例 #7
0
    def test__del_quote(self):
        dbPath = os.path.join(testPath, '__test_bot_del_quote.sqlite')
        self._delete(dbPath)

        settings = Settings()
        settings.DATABASE_PATH = dbPath

        bot = Bot(settings, None, FakeWrapper, logger=nullLogger,
                  wrap_irc=False)
        bot._initialize_models()
        bot._add_quote("#tmp", "foobar", ["test"])
        bot._add_quote("#tmp", "foobar", ["test2"])
        bot._del_quote("#tmp", "foobar", [1])

        quote_id, quote = bot._get_model("#tmp", "quotes").get_random_quote()

        assert str(quote) == "test2"
コード例 #8
0
ファイル: test_bot.py プロジェクト: EvaisaGiac/twitch-bot
    def test_update_global_value(self):
        dbPath = os.path.join(testPath,
                              '__test_bot_update_global_value.sqlite')
        self._delete(dbPath)

        settings = Settings()
        settings.DATABASE_PATH = dbPath

        bot = Bot(settings,
                  None,
                  FakeWrapper,
                  logger=nullLogger,
                  wrap_irc=False)
        bot._initialize_models()
        bot.update_global_value("#tmp", "test", {"key1": "value1"})

        data = bot._load_channel_data("#tmp")

        assert data["test"]["key1"] == "value1"
コード例 #9
0
ファイル: test_bot.py プロジェクト: EvaisaGiac/twitch-bot
    def test__del_quote(self):
        dbPath = os.path.join(testPath, '__test_bot_del_quote.sqlite')
        self._delete(dbPath)

        settings = Settings()
        settings.DATABASE_PATH = dbPath

        bot = Bot(settings,
                  None,
                  FakeWrapper,
                  logger=nullLogger,
                  wrap_irc=False)
        bot._initialize_models()
        bot._add_quote("#tmp", "foobar", ["test"])
        bot._add_quote("#tmp", "foobar", ["test2"])
        bot._del_quote("#tmp", "foobar", [1])

        quote_id, quote = bot._get_model("#tmp", "quotes").get_random_quote()

        assert str(quote) == "test2"
コード例 #10
0
    def test_quote_suffix(self):
        dbPath = os.path.join(testPath, '__test_bot_quote_suffix.sqlite')
        self._delete(dbPath)

        settings = Settings()
        settings.QUOTE_AUTO_SUFFIX = True

        now = datetime.now()
        expected_suffix = " - {streamer} @ {year}-{month:02}-{day:02}".format(
            streamer=settings.CHANNEL_LIST["#tmp"],
            year=int(now.strftime("%Y")),
            month=int(now.strftime("%m")),
            day=int(now.strftime("%d"))
        )

        bot = Bot(settings, None, FakeWrapper, logger=nullLogger,
                  wrap_irc=False)
        bot._initialize_models()
        bot._add_quote("#tmp", "foobar", ["test"], timestamp=now)
        quote_id, quote = bot._get_model("#tmp", "quotes").get_random_quote()

        expected = "test" + expected_suffix

        assert quote == expected