コード例 #1
0
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
コード例 #2
0
 def test_list_feeds(self):
     another_chan = self.server.get_channel_by_address("another_channel")
     # Get feed list
     rss_check_class = self.function_dispatcher.get_function_by_name(
         "check subscription")
     rss_check_obj = self.function_dispatcher.get_function_object(
         rss_check_class)  # type: SubscriptionCheck
     rfl = rss_check_obj.get_sub_repo(self.hallo)
     # Add RSS feeds to feed list
     rf1 = E621Source("cabinet")
     sub1 = Subscription(self.server, self.test_chan, rf1,
                         timedelta(days=1), None, None)
     rfl.add_sub(sub1)
     rf2 = E621Source("clefable")
     sub2 = Subscription(self.server, another_chan, rf2, timedelta(days=1),
                         None, None)
     rfl.add_sub(sub2)
     rf3 = E621Source("fez")
     sub3 = Subscription(self.server, self.test_chan, rf3,
                         timedelta(days=1), None, None)
     rfl.add_sub(sub3)
     # Run FeedList and check output
     self.function_dispatcher.dispatch(
         EventMessage(self.server, self.test_chan, self.test_user,
                      "e621 sub list"))
     data = self.server.get_send_data(1, self.test_chan, EventMessage)
     data_split = data[0].text.split("\n")
     assert ("subscriptions posting" in data_split[0].lower()
             ), "Missing title. Response data: " + str(data[0].text)
     assert "cabinet" in data_split[1].lower(
     ) or "cabinet" in data_split[2].lower()
     assert ("clefable" not in data_split[1].lower()
             and "clefable" not in data_split[2].lower())
     assert "fez" in data_split[1].lower() or "fez" in data_split[2].lower()
コード例 #3
0
 def test_remove_by_search(self):
     another_chan = self.server.get_channel_by_address("another_channel")
     # Get subscription list
     e621_check_class = self.function_dispatcher.get_function_by_name(
         "check subscription")
     e621_check_obj = self.function_dispatcher.get_function_object(
         e621_check_class)  # type: SubscriptionCheck
     sub_repo = e621_check_obj.get_sub_repo(self.hallo)
     # Add E621 searches to subscription list
     rf1 = E621Source("cabinet")
     sub1 = Subscription(self.server, self.test_chan, rf1,
                         timedelta(days=1), None, None)
     sub_repo.add_sub(sub1)
     rf2 = E621Source("clefable")
     sub2 = Subscription(self.server, another_chan, rf2, timedelta(days=1),
                         None, None)
     sub_repo.add_sub(sub2)
     rf3 = E621Source("fez")
     sub3 = Subscription(self.server, self.test_chan, rf3,
                         timedelta(days=1), None, None)
     sub_repo.add_sub(sub3)
     # Remove test search
     self.function_dispatcher.dispatch(
         EventMessage(self.server, self.test_chan, self.test_user,
                      "e621 sub remove cabinet"))
     data = self.server.get_send_data(1, self.test_chan, EventMessage)
     assert "removed subscription" in data[0].text.lower()
     assert "e621" in data[0].text.lower()
     assert "\"cabinet\"" in data[0].text.lower()
     assert sub1 not in sub_repo.sub_list
     assert sub2 in sub_repo.sub_list
     assert sub3 in sub_repo.sub_list
コード例 #4
0
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
コード例 #5
0
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
コード例 #6
0
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
コード例 #7
0
 def test_remove_multiple_matching_searches(self):
     another_chan = self.server.get_channel_by_address("another_channel")
     # Get subscription list
     e621_check_class = self.function_dispatcher.get_function_by_name(
         "check subscription")
     e621_check_obj = self.function_dispatcher.get_function_object(
         e621_check_class)  # type: SubscriptionCheck
     rfl = e621_check_obj.get_sub_repo(self.hallo)
     # Add E621 searches to subscription list
     rf1 = E621Source("cabinet")
     sub1 = Subscription(self.server, self.test_chan, rf1,
                         timedelta(days=1), None, None)
     rfl.add_sub(sub1)
     rf2 = E621Source("clefable")
     sub2 = Subscription(self.server, another_chan, rf2, timedelta(days=1),
                         None, None)
     rfl.add_sub(sub2)
     rf3 = E621Source("cabinet")
     sub3 = Subscription(self.server, self.test_chan, rf3,
                         timedelta(days=1), None, None)
     rfl.add_sub(sub3)
     # Remove test feed
     self.function_dispatcher.dispatch(
         EventMessage(self.server, self.test_chan, self.test_user,
                      "e621 sub remove cabinet"))
     data = self.server.get_send_data(1, self.test_chan, EventMessage)
     assert ("removed 2 subscriptions" in data[0].text.lower(
     )), "Response did not contain expected string. Response was {}".format(
         data[0].text)
     assert ("cabinet" in data[0].text.lower(
     )), "Response did not contain expected string. Response was {}".format(
         data[0].text)
     assert ("e621" in data[0].text.lower(
     )), "Response did not contain expected string. Response was {}".format(
         data[0].text)
     assert sub1 not in rfl.sub_list
     assert sub2 in rfl.sub_list
     assert sub3 not in rfl.sub_list
コード例 #8
0
 def test_run_all(self):
     # Set up test servers and channels
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     chan1 = serv1.get_channel_by_address("test_chan1".lower(),
                                          "test_chan1")
     chan2 = serv1.get_channel_by_address("test_chan2".lower(),
                                          "test_chan2")
     serv2 = ServerMock(self.hallo)
     serv2.name = "test_serv2"
     chan3 = serv2.get_channel_by_address("test_chan1".lower(),
                                          "test_chan1")
     try:
         self.hallo.add_server(serv1)
         self.hallo.add_server(serv2)
         # Set up rss feeds
         sub_repo = SubscriptionRepo()
         rf1 = E621Source("cabinet")
         sub1 = Subscription(serv1, chan1, rf1, timedelta(days=1), None,
                             None)
         sub_repo.add_sub(sub1)
         rf2 = E621Source("clefable")
         sub2 = Subscription(serv1, chan2, rf2, timedelta(days=1), None,
                             None)
         sub_repo.add_sub(sub2)
         rf3 = E621Source("fez")
         sub3 = Subscription(serv2, chan3, rf3, timedelta(days=1), None,
                             None)
         sub_repo.add_sub(sub3)
         # Splice this rss feed list into the function dispatcher's rss check object
         e621_sub_check = self.function_dispatcher.get_function_by_name(
             "check subscription")
         e621_sub_obj = self.function_dispatcher.get_function_object(
             e621_sub_check)  # type: SubscriptionCheck
         e621_sub_obj.subscription_repo = sub_repo
         # Test running all feed updates
         self.function_dispatcher.dispatch(
             EventMessage(self.server, self.test_chan, self.test_user,
                          "e621 sub check all"))
         # Check original calling channel data
         serv0_data = self.server.get_send_data(1, self.test_chan,
                                                EventMessage)
         assert (
             "subscription updates were found"
             in serv0_data[0].text.lower()), "Actual message: {}".format(
                 serv0_data[0].text)
         # Check test server 1 data
         serv1_data = serv1.get_send_data(100)
         chan1_count = 0
         chan2_count = 0
         for data_line in serv1_data:
             if data_line.channel == chan1:
                 chan1_count += 1
             if data_line.channel == chan2:
                 chan2_count += 1
         assert chan1_count == 50
         assert chan2_count == 50
         # Check test server 2 data
         serv2.get_send_data(50, chan3, EventMessage)
         # Test running with no new updates.
         self.function_dispatcher.dispatch(
             EventMessage(self.server, self.test_chan, self.test_user,
                          "e621 sub check all"))
         data = self.server.get_send_data(1, self.test_chan, EventMessage)
         assert "no updates" in data[
             0].text, "No further updates should be found."
     finally:
         self.hallo.remove_server(serv2)
         self.hallo.remove_server(serv1)
コード例 #9
0
 def test_run_passive(self):
     # Set up test servers and channels
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     chan1 = serv1.get_channel_by_address("test_chan1".lower(),
                                          "test_chan1")
     chan2 = serv1.get_channel_by_address("test_chan2".lower(),
                                          "test_chan2")
     serv2 = ServerMock(self.hallo)
     serv2.name = "test_serv2"
     chan3 = serv2.get_channel_by_address("test_chan1".lower(),
                                          "test_chan1")
     try:
         self.hallo.add_server(serv1)
         self.hallo.add_server(serv2)
         # Set up rss feeds
         sub_repo = SubscriptionRepo()
         rf1 = E621Source("cabinet")
         sub1 = Subscription(serv1, chan1, rf1, timedelta(days=1), None,
                             None)
         sub_repo.add_sub(sub1)
         rf2 = E621Source("clefable")
         sub2 = Subscription(serv1, chan2, rf2, timedelta(days=1), None,
                             None)
         sub_repo.add_sub(sub2)
         rf3 = E621Source("fez")
         sub3 = Subscription(serv2, chan3, rf3, timedelta(days=1), None,
                             None)
         sub_repo.add_sub(sub3)
         # Splice this rss feed list into the function dispatcher's rss check object
         rss_check_class = self.function_dispatcher.get_function_by_name(
             "check subscription")
         rss_check_obj = self.function_dispatcher.get_function_object(
             rss_check_class)  # type: SubscriptionCheck
         rss_check_obj.subscription_repo = sub_repo
         # Test passive feed updates
         self.function_dispatcher.dispatch_passive(EventMinute())
         # Check test server 1 data
         serv1_data = serv1.get_send_data(100)
         chan1_count = 0
         chan2_count = 0
         for data_line in serv1_data:
             if data_line.channel == chan1:
                 chan1_count += 1
             if data_line.channel == chan2:
                 chan2_count += 1
         assert chan1_count == 50
         assert chan2_count == 50
         # Check test server 2 data
         serv2.get_send_data(50, chan3, EventMessage)
         # 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(EventMinute())
         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(EventMinute())
         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)
コード例 #10
0
 def test_run_by_search(self):
     # Set up test servers and channels
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     chan1 = serv1.get_channel_by_address("test_chan1".lower(),
                                          "test_chan1")
     chan2 = serv1.get_channel_by_address("test_chan2".lower(),
                                          "test_chan2")
     user1 = serv1.get_user_by_address("test_user1", "test_user1")
     serv2 = ServerMock(self.hallo)
     serv2.name = "test_serv2"
     chan3 = serv2.get_channel_by_address("test_chan1".lower(),
                                          "test_chan1")
     try:
         self.hallo.add_server(serv1)
         self.hallo.add_server(serv2)
         # Set up rss feeds
         sub_repo = SubscriptionRepo()
         rf1 = E621Source("cabinet")
         sub1 = Subscription(serv1, chan1, rf1, timedelta(days=1), None,
                             None)
         sub_repo.add_sub(sub1)
         rf2 = E621Source("clefable")
         sub2 = Subscription(serv1, chan2, rf2, timedelta(days=1), None,
                             None)
         sub_repo.add_sub(sub2)
         rf3 = E621Source("fez")
         sub3 = Subscription(serv2, chan3, rf3, timedelta(days=1), None,
                             None)
         sub_repo.add_sub(sub3)
         # Splice this rss feed list into the function dispatcher's rss check object
         rss_check_class = self.function_dispatcher.get_function_by_name(
             "check subscription")
         rss_check_obj = self.function_dispatcher.get_function_object(
             rss_check_class)  # type: SubscriptionCheck
         rss_check_obj.subscription_repo = sub_repo
         # Invalid title
         self.function_dispatcher.dispatch(
             EventMessage(
                 self.server,
                 self.test_chan,
                 self.test_user,
                 "e621 sub check Not a valid search",
             ))
         data = self.server.get_send_data(1, self.test_chan, EventMessage)
         assert "error" in data[0].text.lower()
         # Correct title but wrong channel
         self.function_dispatcher.dispatch(
             EventMessage(serv1, chan1, user1, "e621 sub check clefable"))
         data = serv1.get_send_data(1, chan1, EventMessage)
         assert "error" in data[0].text.lower()
         # Correct title check update
         self.function_dispatcher.dispatch(
             EventMessage(serv1, chan2, user1, "e621 sub check clefable"))
         data = serv1.get_send_data(51, chan2, EventMessage)
         has_photo_id = 0
         for x in range(50):
             assert "update on" in data[x].text.lower()
             if hasattr(data[x],
                        "photo_id") and data[x].photo_id is not None:
                 has_photo_id += 1
             assert "clefable" in data[x].text
         assert has_photo_id > 40, "Almost all subscription updates should have a photo"
         assert ("subscription updates were found"
                 in data[50].text.lower()), "Actual message: {}".format(
                     data[0].text)
         # No updates
         self.function_dispatcher.dispatch(
             EventMessage(serv1, chan2, user1, "e621 sub check clefable"))
         data = serv1.get_send_data(1, chan2, EventMessage)
         assert "no updates" in data[
             0].text, "No further updates should be found."
     finally:
         self.hallo.remove_server(serv2)
         self.hallo.remove_server(serv1)