def _initialize_blacklists(self): """ Set up blacklist managers for all the channels :return: """ for channel in self.settings.CHANNEL_LIST: manager = BlacklistManager(logger=self.logger) blacklist_model = self._get_model(channel, "blacklist") whitelist_model = self._get_model(channel, "whitelist") blacklist = list(blacklist_model.select()) whitelist = list(whitelist_model.select()) manager.set_data(blacklist, whitelist) self.blacklist_managers[channel] = manager
def test_is_blacklisted(self): blacklist = [ Model(1, "http://example.com/abc/*"), Model(2, "http://example.com/2/"), Model(3, "http://youtube.com") ] whitelist = [ Model(1, "http://example.com/abc/lietu"), Model(2, "http://youtube.com/watch?v=fu2bgwcv43o") ] manager = BlacklistManager(logger=logging.getLogger("foo")) manager.set_data(blacklist, whitelist) res, rid, t = manager.is_blacklisted("Visit " "http://example.com/abc/def !") assert res is True assert rid == 1 res, rid, t = manager.is_blacklisted("Visit http://example.com/abc/ !") assert res is True assert rid == 1 res, rid, t = manager.is_blacklisted("Visit http://example.com/2/ !") assert res is True assert rid == 2 res, rid, t = manager.is_blacklisted("http://youtube.com") assert res is True assert rid == 3 res, rid, t = manager.is_blacklisted("Visit " "http://example.com/lietu !") assert res is False res, rid, t = manager.is_blacklisted("http://example.com/abc/lietu") assert res is False res, rid, t = manager.is_blacklisted("http://google.com") assert res is False res, rid, t = manager.is_blacklisted("http://youtube.com/watch?v=" "fu2bgwcv43o") assert res is False