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
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
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
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"
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"
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