예제 #1
0
 def test_check_feed(self):
     # Check loading up an example feed
     test_rss_url = "http://spangle.org.uk/hallo/test_rss.xml"
     rf = RssFeed()
     rf.url = test_rss_url
     new_items = rf.check_feed()
     assert rf.title == "Example rss feed"
     assert len(new_items) == 3
     for new_item in new_items:
         format_item = rf.format_item(new_item)
         assert "Item 1" in format_item or \
                "Item 2" in format_item or \
                "Item 3" in format_item, "Item name not in formatted item: " + format_item
         assert "example.com/item1" in format_item or \
                "example.com/item2" in format_item or \
                "example.com/item3" in format_item, "Item link not in formatted item: " + format_item
     # Check that calling twice returns no more items
     next_items = rf.check_feed()
     assert len(next_items) == 0, "More items should not have been found."
예제 #2
0
 def test_xml(self):
     test_rss_url = "http://spangle.org.uk/hallo/test_rss.xml"
     test_seconds = 3600
     test_days = 0
     # Create example feed
     rf = RssFeed()
     rf.url = test_rss_url
     rf.update_frequency = Commons.load_time_delta("P"+str(test_days)+"T"+str(test_seconds)+"S")
     rf.server_name = "test_serv"
     rf.channel_name = "test_chan"
     # Clear off the current items
     rf.check_feed()
     # Ensure there are no new items
     new_items = rf.check_feed()
     assert len(new_items) == 0
     # Save to XML and load up new RssFeed
     rf_xml = rf.to_xml_string()
     rf2 = RssFeed.from_xml_string(rf_xml)
     # Ensure there's still no new items
     new_items = rf2.check_feed()
     assert len(new_items) == 0
     assert rf2.update_frequency.days == test_days
     assert rf2.update_frequency.seconds == test_seconds
예제 #3
0
 def test_run_passive(self):
     # Set up test servers and channels
     serv1 = ServerMock(None)
     serv1.name = "test_serv1"
     chan1 = serv1.get_channel_by_name("test_chan1")
     chan2 = serv1.get_channel_by_name("test_chan2")
     serv2 = ServerMock(None)
     serv2.name = "test_serv2"
     chan3 = serv2.get_channel_by_name("test_chan1")
     try:
         self.hallo.add_server(serv1)
         self.hallo.add_server(serv2)
         # Set up rss feeds
         rfl = RssFeedList()
         rf1 = RssFeed()
         rf1.url = "http://spangle.org.uk/hallo/test_rss.xml?1"
         rf1.title = "test_feed1"
         rf1.server_name = chan1.server.name
         rf1.channel_name = chan1.name
         rf1.update_frequency = Commons.load_time_delta("PT3600S")
         rfl.add_feed(rf1)
         rf2 = RssFeed()
         rf2.url = "http://spangle.org.uk/hallo/test_rss.xml?2"
         rf2.title = "test_feed2"
         rf2.server_name = chan2.server.name
         rf2.channel_name = chan2.name
         rf2.update_frequency = Commons.load_time_delta("PT3600S")
         rfl.add_feed(rf2)
         rf3 = RssFeed()
         rf3.url = "http://spangle.org.uk/hallo/test_rss.xml?3"
         rf3.title = "test_feed1"
         rf3.server_name = chan3.server.name
         rf3.channel_name = chan3.name
         rf3.update_frequency = Commons.load_time_delta("PT3600S")
         rfl.add_feed(rf3)
         # Splice this rss feed list into the function dispatcher's rss check object
         rss_check_class = self.function_dispatcher.get_function_by_name("rss check")
         rss_check_obj = self.function_dispatcher.get_function_object(rss_check_class)  # type: FeedCheck
         rss_check_obj.rss_feed_list = rfl
         # Test passive feed updates
         self.function_dispatcher.dispatch_passive(Function.EVENT_MINUTE, None, None, None, None)
         # Check test server 1 data
         serv1_data = serv1.get_send_data(6)
         chan1_count = 0
         chan2_count = 0
         for data_line in serv1_data:
             if data_line[1] == chan1:
                 chan1_count += 1
             if data_line[1] == chan2:
                 chan2_count += 1
         assert chan1_count == 3
         assert chan2_count == 3
         # Check test server 2 data
         serv2_data = serv2.get_send_data(3, chan3, Server.MSG_MSG)
         # Test that no updates are found the second run
         rf1.last_check = None
         rf2.last_check = None
         rf3.last_check = None
         self.function_dispatcher.dispatch_passive(Function.EVENT_MINUTE, None, None, None, None)
         serv1.get_send_data(0)
         serv2.get_send_data(0)
         # Test that no feeds are checked before timeout, set urls to none and see if anything explodes.
         self.failed = False
         rf1.check_feed = self.do_not_call
         rf2.check_feed = self.do_not_call
         rf3.check_feed = self.do_not_call
         self.function_dispatcher.dispatch_passive(Function.EVENT_MINUTE, None, None, None, None)
         serv1.get_send_data(0)
         serv2.get_send_data(0)
         assert not self.failed, "check_feed() should not have been called on any feed."
     finally:
         self.hallo.remove_server(serv2)
         self.hallo.remove_server(serv1)