def test_get_feeds_by_destination(hallo_getter): hallo, test_server, test_channel, test_user = hallo_getter({"subscriptions"}) serv1 = ServerMock(hallo) serv1.name = "test_serv1" serv2 = ServerMock(hallo) serv2.name = "test_serv2" chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1") user2 = serv1.get_user_by_address("test_user2", "test_user2") chan3 = serv2.get_channel_by_address("test_chan3".lower(), "test_chan3") # Setup a feed list rfl = SubscriptionRepo() rf1 = RssSource("http://spangle.org.uk/hallo/test_rss.xml?1", "feed 1") sub1 = Subscription(serv1, chan1, rf1, timedelta(days=1), None, None) rfl.add_sub(sub1) rf2 = RssSource("http://spangle.org.uk/hallo/test_rss.xml?2", "feed 2") sub2 = Subscription(serv1, user2, rf2, timedelta(days=1), None, None) rfl.add_sub(sub2) rf3 = RssSource("http://spangle.org.uk/hallo/test_rss.xml?3", "feed 3") sub3 = Subscription(serv2, chan3, rf3, timedelta(days=1), None, None) rfl.add_sub(sub3) rf4 = RssSource("http://spangle.org.uk/hallo/test_rss.xml?4", "feed 4") sub4 = Subscription(serv2, chan3, rf4, timedelta(days=1), None, None) rfl.add_sub(sub4) rf5 = RssSource( "http://spangle.org.uk/hallo/test_rss.xml?5", feed_title="feed 5", ) sub5 = Subscription(serv2, chan3, rf5, timedelta(days=1), None, None) rfl.add_sub(sub5) # Check function feed_list = rfl.get_subs_by_destination(chan3) assert len(feed_list) == 3 assert sub4 in feed_list assert sub3 in feed_list assert sub5 in feed_list
def test_current_state(): rf = RssSource(TEST_RSS) state = rf.current_state() assert isinstance(state, list) assert len(state) == 3 assert isinstance(state[0], ElementTree.Element) assert state[0].find("title").text == "Item 3" assert state[0].find("link").text == "http://example.com/item3"
def test_item_to_key__no_guid(): rss_data = ( """<item> <title>Item title</title> <link>http://example.com/item</link> </item>""" ) rss_elem = ElementTree.fromstring(rss_data) rf = RssSource(TEST_RSS) assert rf.item_to_key(rss_elem) == "http://example.com/item"
def test_item_to_key__no_guid_or_link(): rss_data = ( """<item> <title>Item title</title> </item>""" ) rss_elem = ElementTree.fromstring(rss_data) rf = RssSource(TEST_RSS) assert rf.item_to_key(rss_elem) != "Item title" key1 = rf.item_to_key(rss_elem) key2 = rf.item_to_key(rss_elem) assert key1 == key2
def test_from_input(hallo_getter): hallo, test_server, test_channel, test_user = hallo_getter({"subscriptions"}) sub_repo = SubscriptionRepo() rf = RssSource.from_input(TEST_RSS, test_user, sub_repo) assert rf.url == TEST_RSS assert rf.feed_title == "Example rss feed"
def test_json(hallo_getter): hallo, test_server, test_channel, test_user = hallo_getter({"subscriptions"}) sub_repo = SubscriptionRepo() rf = RssSource(TEST_RSS) rf.last_keys = ["item3", "item2", "item1"] rf_json = rf.to_json() assert "type" in rf_json assert "last_keys" in rf_json assert "url" in rf_json assert "title" in rf_json rf2 = RssSource.from_json(rf_json, test_channel, sub_repo) assert rf2.url == TEST_RSS assert rf2.feed_title == rf.feed_title assert rf2.last_keys == rf.last_keys
def test_init(): rf = RssSource(TEST_RSS) keys = [ "feed_title", "url", "last_keys", ] for key in keys: assert key in rf.__dict__, "Key is missing from RssFeed object: " + key
def test_init__with_name(): # Ensure it doesn't call somewhere, by giving a fake url rf = RssSource("example.rss", "feed title") keys = [ "feed_title", "url", "last_keys", ] for key in keys: assert key in rf.__dict__, "Key is missing from RssFeed object: " + key
def test_item_to_event(hallo_getter): hallo, test_server, test_chat, test_user = hallo_getter({"subscriptions"}) rf = RssSource(TEST_RSS, "feed title") rss_data = ( """<item> <title>Item title</title> <link>http://example.com/item</link> </item>""" ) rss_elem = ElementTree.fromstring(rss_data) event = rf.item_to_event(test_server, test_chat, None, rss_elem) assert event.server == test_server assert event.channel == test_chat assert event.user is None assert "\"feed title\"" in event.text assert "Item title" in event.text assert "http://example.com/item" in event.text
def test_remove_feed(hallo_getter): hallo, test_server, test_channel, test_user = hallo_getter({"subscriptions"}) # Setup a feed list sub_repo = SubscriptionRepo() rf1 = RssSource( "http://spangle.org.uk/hallo/test_rss.xml?1", "title1" ) sub1 = Subscription(test_server, test_channel, rf1, timedelta(days=1), None, None) sub_repo.add_sub(sub1) rf2 = RssSource( "http://spangle.org.uk/hallo/test_rss.xml?2", "title2" ) sub2 = Subscription(test_server, test_channel, rf2, timedelta(days=1), None, None) sub_repo.add_sub(sub2) assert len(sub_repo.sub_list) == 2 # Remove an item from the feed list sub_repo.remove_sub(sub1) assert len(sub_repo.sub_list) == 1 assert sub_repo.sub_list[0] == sub2
def test_add_feed(hallo_getter): hallo, test_server, test_channel, test_user = hallo_getter({"subscriptions"}) sub_repo = SubscriptionRepo() assert sub_repo.sub_list == [] # Create example rss feed rf = RssSource("http://spangle.org.uk/hallo/test_rss.xml", "feed title") sub = Subscription(test_server, test_channel, rf, timedelta(days=1), None, None) sub_repo.add_sub(sub) assert len(sub_repo.sub_list) == 1 assert sub_repo.sub_list[0] == sub
def test_json(hallo_getter): hallo, test_server, test_channel, test_user = hallo_getter({"subscriptions"}) # Setup a feed list sub_repo = SubscriptionRepo() rf1 = RssSource( "http://spangle.org.uk/hallo/test_rss.xml?1", feed_title="test_feed1", ) sub1 = Subscription(test_server, test_channel, rf1, timedelta(days=1), None, None) sub_repo.add_sub(sub1) rf2 = RssSource( "http://spangle.org.uk/hallo/test_rss.xml?2", feed_title="test_feed2", ) sub2 = Subscription(test_server, test_user, rf2, timedelta(days=1), None, None) sub_repo.add_sub(sub2) rf3 = RssSource( "http://spangle.org.uk/hallo/test_rss.xml?3", feed_title="test_feed3", ) sub3 = Subscription(test_server, test_channel, rf3, timedelta(hours=1), None, None) sub_repo.add_sub(sub3) # Save to JSON and load try: try: os.rename("store/subscriptions.json", "store/subscriptions.json.tmp") except OSError: pass sub_repo.save_json() new_rfl = SubscriptionRepo.load_json(hallo) assert len(new_rfl.sub_list) == 3 finally: try: os.remove("store/subscriptions.json") except OSError: pass try: os.rename("store/subscriptions.json.tmp", "store/subscriptions.json") except OSError: pass
def get_source_objects(self) -> List[Source]: fa_key = FAKey(self.test_user, self.cookie_a, self.cookie_b) sub_objs = list() sub_objs.append(E621Source("cabinet")) sub_objs.append(E621TaggingSource("cabinet", ["door"])) sub_objs.append(RssSource("http://spangle.org.uk/hallo/test_rss.xml")) sub_objs.append(FANotesSource(fa_key, FANotesInboxSource(fa_key), FANotesOutboxSource(fa_key))) sub_objs.append(FAFavsSource(fa_key, "zephyr42")) sub_objs.append(FAUserWatchersSource(fa_key, "zephyr42")) sub_objs.append(FAWatchersSource(fa_key)) sub_objs.append(FAFavNotificationsSource(fa_key)) sub_objs.append(FACommentNotificationsSource( fa_key, FASubmissionCommentSource(fa_key), FAJournalCommentSource(fa_key), FAShoutSource(fa_key) )) sub_objs.append(RedditSource("deer")) # sub_objs.append(TwitterSource("telegram", None)) return sub_objs
def test_title(): rf = RssSource(TEST_RSS) assert TEST_RSS in rf.title assert "Example rss feed" in rf.title
def test_matches_name(): rf = RssSource(TEST_RSS) assert rf.matches_name(TEST_RSS) assert rf.matches_name("example rss feed")