コード例 #1
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()
コード例 #2
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
コード例 #3
0
def test_from_input(hallo_getter):
    hallo, test_server, test_channel, test_user = hallo_getter({"subscriptions"})
    sub_repo = SubscriptionRepo()

    rf = E621Source.from_input("cabinet", test_user, sub_repo)

    assert rf.search == "cabinet"
コード例 #4
0
def test_init():
    rf = E621Source("cabinet")
    keys = [
        "search",
        "last_keys"
    ]
    for key in keys:
        assert key in rf.__dict__, "Key is missing from E621Sub object: " + key
コード例 #5
0
def test_json(hallo_getter):
    hallo, test_server, test_channel, test_user = hallo_getter({"subscriptions"})
    sub_repo = SubscriptionRepo()
    test_e621_search = "cabinet"
    # Create example source
    rf = E621Source(test_e621_search)
    rf.last_keys = [1234, 2345, 3456]
    # Save to json and load up new E621Sub
    rf_json = rf.to_json()

    assert "type" in rf_json
    assert "last_keys" in rf_json
    assert "search" in rf_json
    assert rf_json["type"] == E621Source.type_name

    rf2 = E621Source.from_json(rf_json, test_channel, sub_repo)

    assert rf2.search == test_e621_search
    assert rf2.last_keys == rf.last_keys
コード例 #6
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
コード例 #7
0
def test_item_to_event__no_url(hallo_getter):
    hallo, test_server, test_chat, test_user = hallo_getter({"subscriptions"})
    rf = E621Source("cabinet")
    item = {"id": 1234, "rating": "s", "file": {"ext": "png", "url": None}}

    event = rf.item_to_event(test_server, test_chat, None, item)

    assert isinstance(event, EventMessage)
    assert not isinstance(event, EventMessageWithPhoto)
    assert event.server == test_server
    assert event.channel == test_chat
    assert event.user is None
    assert "\"cabinet\"" in event.text
    assert "1234" in event.text
    assert "Safe" in event.text
コード例 #8
0
def test_current_state():
    rf = E621Source("cabinet")

    state = rf.current_state()

    assert isinstance(state, list)
    assert len(state) > 0
    last_id = None
    for post in state:
        # Check tag is in tags
        assert "cabinet" in [x for v in post["tags"].values() for x in v]
        # Check id is decreasing
        if last_id is None:
            last_id = post["id"]
            continue
        assert last_id > post["id"]
        last_id = post["id"]
コード例 #9
0
 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
コード例 #10
0
def test_item_to_key():
    rf = E621Source("cabinet")
    item = {"id": 1234, "rating": "s", "file": {"ext": "png", "url": "example.png"}}

    assert rf.item_to_key(item) == 1234
コード例 #11
0
def test_title():
    rf = E621Source("cabinet")

    assert "\"cabinet\"" in rf.title
コード例 #12
0
def test_matches_name():
    rf = E621Source("Cabinet ")

    assert rf.matches_name("cabinet")
コード例 #13
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)
コード例 #14
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)
コード例 #15
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)