Ejemplo n.º 1
0
 def test_check_response(self):
     # Setup common testing objects
     serv1 = ServerMock(None)
     serv1.name = "test_serv1"
     chan1 = serv1.get_channel_by_name("test_chan1")
     user1 = serv1.get_user_by_name("test_user1")
     # Test basic response works
     rm1 = ReplyMessage("test")
     rm1.add_response("response")
     assert rm1.check_response("just a test", user1, chan1) == "response"
     # Test regex pattern match
     rm2 = ReplyMessage("\\btest[0-9]+\\b")
     rm2.add_response("response")
     assert rm2.check_response("random testing", user1, chan1) is None
     assert rm2.check_response("random test here", user1, chan1) is None
     assert rm2.check_response("this is test3 I think", user1, chan1) == "response"
     assert rm2.check_response("this is test4", user1, chan1) == "response"
     # Test multi-response works
     rm3 = ReplyMessage("test")
     rm3.add_response("response1")
     rm3.add_response("response2")
     rm3.add_response("response3")
     found_responses = set()
     for _ in range(50):
         response = rm3.check_response("another test", user1, chan1)
         found_responses.add(response)
         assert response in ["response1", "response2", "response3"]
     assert len(found_responses) > 1
     # Test replacements
     rm4 = ReplyMessage("test")
     rm4.add_response("response {USER} {CHANNEL} {SERVER}")
     assert rm4.check_response("test", user1, chan1) == "response test_user1 test_chan1 test_serv1"
Ejemplo n.º 2
0
 def test_1_user_group_no_name(self):
     # Set up a test server and channel and user
     hallo1 = Hallo()
     perm3 = PermissionMask()
     hallo1.permission_mask = perm3
     serv1 = ServerMock(hallo1)
     serv1.name = "test_serv1"
     perm0 = PermissionMask()
     serv1.permission_mask = perm0
     hallo1.add_server(serv1)
     chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
     perm1 = PermissionMask()
     chan1.permission_mask = perm1
     user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
     perm2 = PermissionMask()
     user1.permission_mask = perm2
     group1 = UserGroup("test_group1", hallo1)
     perm4 = PermissionMask()
     group1.permission_mask = perm4
     hallo1.add_user_group(group1)
     # Try to get permissions of non-existent user group
     try:
         data = self.perm_cont.find_permission_mask(["user_group=test_group2"], user1, chan1)
         assert False, "Find permission mask should have failed."
     except modules.PermissionControl.PermissionControlException as e:
         assert "error" in str(e).lower()
         assert "no user group exists by that name" in str(e).lower()
Ejemplo n.º 3
0
    def test_one_server(self):
        # Add one server
        serv1 = ServerMock(self.hallo)

        serv1.name = "server_list_test"
        self.hallo.add_server(serv1)
        # Send command
        self.function_dispatcher.dispatch(EventMessage(self.server, self.test_chan, self.test_user, "list servers"))
        data = self.server.get_send_data(1, self.test_chan, EventMessage)
        # Check response
        server_list_text = data[0].text.split(":")[1]
        server_list = server_list_text.split("], ")
        assert len(server_list) == 1
        assert serv1.name in server_list[0], "Server name not found in output.\n" \
                                             "Server name: " + serv1.name + "\n" \
                                             "Command output: " + server_list[0]
        assert "type=" + serv1.type in server_list[0], "Server type not found in output.\n" \
                                                       "Server type: " + serv1.type + "\n" \
                                                       "Command output: " + server_list[0]
        assert "state=" + serv1.state in server_list[0], "Server state not found in output.\n" \
                                                         "Server name: " + serv1.state + "\n" \
                                                         "Command output: " + server_list[0]
        assert "nick=" + serv1.get_nick() in server_list[0], "Server nick not found in output.\n" \
                                                             "Server nick: " + serv1.get_nick() + "\n" \
                                                             "Command output: " + server_list[0]
        assert "auto_connect=" + str(serv1.auto_connect) in \
               server_list[0], "Server auto connect not found in output.\n" \
                               "Server auto connect: " + \
                               str(serv1.auto_connect) + "\n" \
                                                         "Command output: " + server_list[0]
Ejemplo n.º 4
0
 def test_invite_2_user_user_already_there(self):
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     serv1.type = Server.TYPE_IRC
     self.hallo.add_server(serv1)
     chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
     chan1.in_channel = True
     chan2 = serv1.get_channel_by_address("test_chan2".lower(), "test_chan2")
     chan2.in_channel = True
     user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
     user2 = serv1.get_user_by_address("test_user2".lower(), "test_user2")
     user_hallo = serv1.get_user_by_address(serv1.get_nick().lower(), serv1.get_nick())
     chan1.add_user(user1)
     chan1_user1 = chan1.get_membership_by_user(user1)
     chan1_user1.is_op = False
     chan1.add_user(user_hallo)
     chan1_hallo = chan1.get_membership_by_user(user_hallo)
     chan1_hallo.is_op = True
     chan2.add_user(user2)
     chan2_user1 = chan2.get_membership_by_user(user2)
     chan2_user1.is_op = False
     chan2.add_user(user_hallo)
     chan2_hallo = chan2.get_membership_by_user(user_hallo)
     chan2_hallo.is_op = True
     try:
         self.function_dispatcher.dispatch(EventMessage(serv1, chan1, user1, "invite test_user2 test_chan2"))
         data = serv1.get_send_data(1, chan1, EventMessage)
         assert "error" in data[0].text.lower()
         assert "test_user2 is already in test_chan2" in data[0].text.lower()
     finally:
         self.hallo.remove_server(serv1)
Ejemplo n.º 5
0
 def test_invite_2_user(self):
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     serv1.type = Server.TYPE_IRC
     self.hallo.add_server(serv1)
     chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
     chan1.in_channel = True
     chan2 = serv1.get_channel_by_address("test_chan2".lower(), "test_chan2")
     chan2.in_channel = True
     user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
     user2 = serv1.get_user_by_address("test_user2".lower(), "test_user2")
     user_hallo = serv1.get_user_by_address(serv1.get_nick().lower(), serv1.get_nick())
     chan1.add_user(user1)
     chan1_user1 = chan1.get_membership_by_user(user1)
     chan1_user1.is_op = False
     chan1.add_user(user_hallo)
     chan1_hallo = chan1.get_membership_by_user(user_hallo)
     chan1_hallo.is_op = True
     chan2.add_user(user_hallo)
     chan2_hallo = chan2.get_membership_by_user(user_hallo)
     chan2_hallo.is_op = True
     try:
         self.function_dispatcher.dispatch(EventMessage(serv1, chan1, user1, "invite test_user2 test_chan2"))
         data = serv1.get_send_data(2)
         assert "error" not in data[1].text.lower()
         assert data[0].channel == chan2
         assert data[1].channel == chan1
         assert data[0].__class__ == EventInvite
         assert data[1].__class__ == EventMessage
         assert data[0].invited_user == user2
         assert "invite sent" in data[1].text.lower()
     finally:
         self.hallo.remove_server(serv1)
Ejemplo n.º 6
0
 def test_invite_1_chan_user_already_there(self):
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     serv1.type = Server.TYPE_IRC
     self.hallo.add_server(serv1)
     chan1 = serv1.get_channel_by_name("test_chan1")
     chan1.in_channel = True
     chan2 = serv1.get_channel_by_name("test_chan2")
     chan2.in_channel = True
     user1 = serv1.get_user_by_name("test_user1")
     user2 = serv1.get_user_by_name("test_user2")
     user_hallo = serv1.get_user_by_name(serv1.get_nick())
     chan1.add_user(user1)
     chan1.add_user(user_hallo)
     chan2.add_user(user1)
     chan2.add_user(user_hallo)
     chan1_user1 = chan1.get_membership_by_user(user1)
     chan1_user1.is_op = False
     chan1_hallo = chan1.get_membership_by_user(user_hallo)
     chan1_hallo.is_op = True
     chan2_user1 = chan2.get_membership_by_user(user1)
     chan2_user1.is_op = False
     chan2_hallo = chan2.get_membership_by_user(user_hallo)
     chan2_hallo.is_op = True
     try:
         self.function_dispatcher.dispatch("invite test_chan2", user1, chan1)
         data = serv1.get_send_data(1, chan1, Server.MSG_MSG)
         assert "error" in data[0][0].lower()
         assert "test_user1 is already in test_chan2" in data[0][0].lower()
     finally:
         self.hallo.remove_server(serv1)
Ejemplo n.º 7
0
 def test_invite_2_user(self):
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     serv1.type = Server.TYPE_IRC
     self.hallo.add_server(serv1)
     chan1 = serv1.get_channel_by_name("test_chan1")
     chan1.in_channel = True
     chan2 = serv1.get_channel_by_name("test_chan2")
     chan2.in_channel = True
     user1 = serv1.get_user_by_name("test_user1")
     user2 = serv1.get_user_by_name("test_user2")
     user_hallo = serv1.get_user_by_name(serv1.get_nick())
     chan1.add_user(user1)
     chan1_user1 = chan1.get_membership_by_user(user1)
     chan1_user1.is_op = False
     chan1.add_user(user_hallo)
     chan1_hallo = chan1.get_membership_by_user(user_hallo)
     chan1_hallo.is_op = True
     chan2.add_user(user_hallo)
     chan2_hallo = chan2.get_membership_by_user(user_hallo)
     chan2_hallo.is_op = True
     try:
         self.function_dispatcher.dispatch("invite test_user2 test_chan2", user1, chan1)
         data = serv1.get_send_data(2)
         assert "error" not in data[0][0].lower()
         assert data[0][1] is None
         assert data[1][1] == chan1
         assert data[0][2] == Server.MSG_RAW
         assert data[1][2] == Server.MSG_MSG
         assert data[0][0][:6] == "INVITE"
         assert user2.name+" "+chan2.name in data[0][0]
         assert "invite sent" in data[1][0].lower()
     finally:
         self.hallo.remove_server(serv1)
Ejemplo n.º 8
0
 def test_op_1_user_no_power(self):
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     serv1.type = Server.TYPE_IRC
     self.hallo.add_server(serv1)
     chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
     chan1.in_channel = True
     user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
     user2 = serv1.get_user_by_address("test_user2".lower(), "test_user2")
     user_hallo = serv1.get_user_by_address(serv1.get_nick().lower(), serv1.get_nick())
     chan1.add_user(user1)
     chan1_user1 = chan1.get_membership_by_user(user1)
     chan1_user1.is_op = False
     chan1.add_user(user_hallo)
     chan1_hallo = chan1.get_membership_by_user(user_hallo)
     chan1_hallo.is_op = False
     chan1.add_user(user2)
     chan1_user2 = chan1.get_membership_by_user(user2)
     chan1_user2.is_op = False
     try:
         self.function_dispatcher.dispatch(EventMessage(serv1, chan1, user1, "op test_user2"))
         data = serv1.get_send_data(1, chan1, EventMessage)
         assert "error" in data[0].text.lower()
         assert "don't have power" in data[0].text.lower()
     finally:
         self.hallo.remove_server(serv1)
Ejemplo n.º 9
0
 def test_mute_0(self):
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     serv1.type = Server.TYPE_IRC
     self.hallo.add_server(serv1)
     chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
     chan1.in_channel = True
     user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
     user_hallo = serv1.get_user_by_address(serv1.get_nick().lower(), serv1.get_nick())
     chan1.add_user(user1)
     chan1.add_user(user_hallo)
     chan1_user1 = chan1.get_membership_by_user(user1)
     chan1_user1.is_op = False
     chan1_hallo = chan1.get_membership_by_user(user_hallo)
     chan1_hallo.is_op = True
     try:
         self.function_dispatcher.dispatch(EventMessage(serv1, chan1, user1, "mute"))
         data = serv1.get_send_data(2)
         assert "error" not in data[1].text.lower()
         assert data[0].channel == chan1
         assert data[1].channel == chan1
         assert data[0].__class__ == EventMode
         assert data[1].__class__ == EventMessage
         assert data[0].mode_changes == "+m"
         assert "set mute in "+chan1.name in data[1].text.lower()
     finally:
         self.hallo.remove_server(serv1)
Ejemplo n.º 10
0
 def test_run_by_title(self):
     # Set up test servers and channels
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     chan1 = serv1.get_channel_by_name("test_chan1")
     chan2 = serv1.get_channel_by_name("test_chan2")
     serv2 = ServerMock(self.hallo)
     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
         # Invalid title
         self.function_dispatcher.dispatch("rss check Not a valid feed", self.test_user, self.test_chan)
         data = self.server.get_send_data(1, self.test_chan, Server.MSG_MSG)
         assert "error" in data[0][0].lower()
         # Correct title but wrong channel
         self.function_dispatcher.dispatch("rss check test_feed2", self.test_user, chan1)
         data = serv1.get_send_data(1, chan1, Server.MSG_MSG)
         assert "error" in data[0][0].lower()
         # Correct title check update
         self.function_dispatcher.dispatch("rss check test_feed2", self.test_user, chan2)
         data = serv1.get_send_data(1, chan2, Server.MSG_MSG)
         assert "feed updates were found" in data[0][0].lower()
         assert len(data[0][0].lower().split("\n")) == 4
         # No updates
         rf2.title = "test_feed2"
         self.function_dispatcher.dispatch("rss check test_feed2", self.test_user, chan2)
         data = serv1.get_send_data(1, chan2, Server.MSG_MSG)
         assert "no updates" in data[0][0], "No further updates should be found."
     finally:
         self.hallo.remove_server(serv2)
         self.hallo.remove_server(serv1)
Ejemplo n.º 11
0
 def test_deop_2_user_not_op(self):
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     serv1.type = Server.TYPE_IRC
     self.hallo.add_server(serv1)
     chan1 = serv1.get_channel_by_name("test_chan1")
     chan1.in_channel = True
     chan2 = serv1.get_channel_by_name("test_chan2")
     chan2.in_channel = True
     user1 = serv1.get_user_by_name("test_user1")
     user2 = serv1.get_user_by_name("test_user2")
     user_hallo = serv1.get_user_by_name(serv1.get_nick())
     chan1.add_user(user1)
     chan1_user1 = chan1.get_membership_by_user(user1)
     chan1_user1.is_op = False
     chan1.add_user(user_hallo)
     chan1_hallo = chan1.get_membership_by_user(user_hallo)
     chan1_hallo.is_op = True
     chan2.add_user(user2)
     chan2_user2 = chan2.get_membership_by_user(user2)
     chan2_user2.is_op = False
     chan2.add_user(user_hallo)
     chan2_hallo = chan2.get_membership_by_user(user_hallo)
     chan2_hallo.is_op = True
     try:
         self.function_dispatcher.dispatch("deop test_user2 test_chan2", user1, chan1)
         data = serv1.get_send_data(1, chan1, Server.MSG_MSG)
         assert "error" in data[0][0].lower()
         assert "doesn't have op" in data[0][0].lower()
     finally:
         self.hallo.remove_server(serv1)
Ejemplo n.º 12
0
 def test_devoice_1priv(self):
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     serv1.type = Server.TYPE_IRC
     self.hallo.add_server(serv1)
     chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
     chan1.in_channel = True
     user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
     user_hallo = serv1.get_user_by_address(serv1.get_nick().lower(), serv1.get_nick())
     chan1.add_user(user1)
     chan1.add_user(user_hallo)
     chan1_user1 = chan1.get_membership_by_user(user1)
     chan1_user1.is_voice = True
     chan1_hallo = chan1.get_membership_by_user(user_hallo)
     chan1_hallo.is_op = True
     try:
         self.function_dispatcher.dispatch(EventMessage(serv1, None, user1, "devoice test_chan1"))
         data = serv1.get_send_data(2)
         assert "error" not in data[1].text.lower()
         assert data[0].channel == chan1
         assert data[1].user == user1
         assert data[0].__class__ == EventMode
         assert data[1].__class__ == EventMessage
         assert "-v "+user1.name in data[0].mode_changes
         assert "status taken" in data[1].text.lower()
     finally:
         self.hallo.remove_server(serv1)
Ejemplo n.º 13
0
class TestBase(unittest.TestCase):

    def setUp(self):
        print("Starting test: "+self.id())
        self.start_time = time.time()
        # Create a Hallo
        self.hallo = Hallo()
        # Swap out raw printer function for empty
        self.hallo.printer.output_raw = self.empty
        # Only the required modules, only 1 (mock) server
        # Todo: specify modules by test?
        self.function_dispatcher = FunctionDispatcher({"AsciiArt", "Bio", "ChannelControl", "Euler", "Furry",
                                                       "HalloControl", "Math", "PermissionControl", "Rss",
                                                       "ServerControl", "Silly", "SillyEtd"},
                                                      self.hallo)
        self.hallo.function_dispatcher = self.function_dispatcher
        print("Running test: "+self.id()+". Init took: "+str(time.time()-self.start_time)+" seconds.")
        self.server = ServerMock(self.hallo)
        self.server.name = "mock-server"
        # self.server = unittest.mock.Mock()
        self.hallo.add_server(self.server)
        # send shit in, check shit out
        self.hallo_thread = Thread(target=self.hallo.start,)
        self.hallo_thread.start()
        self.test_user = self.server.get_user_by_name("test")
        self.test_user.online = True
        self.test_chan = self.server.get_channel_by_name("#test")
        self.test_chan.in_channel = True
        # Wait until hallo is open
        count = 0
        while not self.hallo.open:
            time.sleep(0.1)
            count += 1
            assert count < 100, "Hallo took too long to start."
            if count > 100:
                break
        # Clear any data in the server
        self.server.get_send_data()
        # Print test startup time
        print("Running test: "+self.id()+". Startup took: "+str(time.time()-self.start_time)+" seconds.")
        self.start_time = time.time()

    def tearDown(self):
        print("Finishing test: "+self.id()+". Test took: "+str(time.time()-self.start_time)+" seconds.")
        self.hallo.close()
        self.hallo_thread.join()

    def empty(self, var1=None, var2=None, var3=None, var4=None):
        pass

    @classmethod
    def tearDownClass(cls):
        del cls
        gc.collect()
Ejemplo n.º 14
0
 def test_2_server_chan(self):
     # Set up a test server and channel
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     self.hallo.add_server(serv1)
     chan1 = serv1.get_channel_by_name("test_chan1")
     perm1 = PermissionMask()
     chan1.permission_mask = perm1
     # Get permission mask of given channel
     data = self.perm_cont.find_permission_mask(["server=test_serv1", "channel=test_chan1"],
                                                self.test_user, self.test_chan)
     assert perm1 == data, "Did not find the correct permission mask."
Ejemplo n.º 15
0
 def test_2_server_user(self):
     # Set up a test server and user
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     self.hallo.add_server(serv1)
     user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
     perm1 = PermissionMask()
     user1.permission_mask = perm1
     # Get permission mask of given channel
     data = self.perm_cont.find_permission_mask(["server=test_serv1", "user=test_user1"],
                                                self.test_user, self.test_chan)
     assert perm1 == data, "Did not find the correct permission mask."
Ejemplo n.º 16
0
 def test_run_by_title(self):
     # Set up test servers and channels
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     chan1 = serv1.get_channel_by_address("test_chan1")
     chan2 = serv1.get_channel_by_address("test_chan2")
     user1 = serv1.get_user_by_address("test_user1")
     serv2 = ServerMock(self.hallo)
     serv2.name = "test_serv2"
     chan3 = serv2.get_channel_by_address("test_chan1")
     try:
         self.hallo.add_server(serv1)
         self.hallo.add_server(serv2)
         # Set up rss feeds
         rfl = SubscriptionRepo()
         rf1 = RssSub(chan1.server, chan1, "http://spangle.org.uk/hallo/test_rss.xml?1",
                      title="test_feed1", update_frequency=Commons.load_time_delta("PT3600S"))
         rfl.add_sub(rf1)
         rf2 = RssSub(chan2.server, chan2, "http://spangle.org.uk/hallo/test_rss.xml?2",
                      title="test_feed2", update_frequency=Commons.load_time_delta("PT3600S"))
         rfl.add_sub(rf2)
         rf3 = RssSub(chan3.server, chan3, "http://spangle.org.uk/hallo/test_rss.xml?3",
                      title="test_feed1", update_frequency=Commons.load_time_delta("PT3600S"))
         rfl.add_sub(rf3)
         # 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 = rfl
         # Invalid title
         self.function_dispatcher.dispatch(EventMessage(self.server, self.test_chan, self.test_user,
                                                        "rss check Not a valid feed"))
         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, "rss check test_feed2"))
         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, "rss check test_feed2"))
         data = serv1.get_send_data(4, chan2, EventMessage)
         for x in range(3):
             assert "update on" in data[x].text.lower()
             assert "rss feed" in data[x].text.lower()
         assert "updates were found" in data[3].text.lower(), "Actual message: {}".format(data[0].text)
         # No updates
         rf2.title = "test_feed2"
         self.function_dispatcher.dispatch(EventMessage(serv1, chan2, user1, "rss check test_feed2"))
         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)
Ejemplo n.º 17
0
 def test_mute_privmsg(self):
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     serv1.type = Server.TYPE_IRC
     self.hallo.add_server(serv1)
     user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
     try:
         self.function_dispatcher.dispatch(EventMessage(serv1, None, user1, "mute"))
         data = serv1.get_send_data(1, user1, EventMessage)
         assert "error" in data[0].text.lower()
         assert "can't set mute on a private message" in data[0].text.lower()
     finally:
         self.hallo.remove_server(serv1)
Ejemplo n.º 18
0
 def test_mute_privmsg(self):
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     serv1.type = Server.TYPE_IRC
     self.hallo.add_server(serv1)
     user1 = serv1.get_user_by_name("test_user1")
     try:
         self.function_dispatcher.dispatch("mute", user1, user1)
         data = serv1.get_send_data(1, user1, Server.MSG_MSG)
         assert "error" in data[0][0].lower()
         assert "can't set mute on a private message" in data[0][0].lower()
     finally:
         self.hallo.remove_server(serv1)
Ejemplo n.º 19
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_name("test_chan1")
     chan2 = serv1.get_channel_by_name("test_chan2")
     serv2 = ServerMock(self.hallo)
     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 = E621SubList()
         rf1 = E621Sub()
         rf1.search = "butt"
         rf1.server_name = chan1.server.name
         rf1.channel_name = chan1.name
         rf1.update_frequency = Commons.load_time_delta("PT3600S")
         rfl.add_sub(rf1)
         rf2 = E621Sub()
         rf2.search = "deer"
         rf2.server_name = chan2.server.name
         rf2.channel_name = chan2.name
         rf2.update_frequency = Commons.load_time_delta("PT3600S")
         rfl.add_sub(rf2)
         rf3 = E621Sub()
         rf3.search = "dragon"
         rf3.server_name = chan3.server.name
         rf3.channel_name = chan3.name
         rf3.update_frequency = Commons.load_time_delta("PT3600S")
         rfl.add_sub(rf3)
         # Splice this rss feed list into the function dispatcher's rss check object
         rss_check_class = self.function_dispatcher.get_function_by_name("e621 sub check")
         rss_check_obj = self.function_dispatcher.get_function_object(rss_check_class)  # type: SubE621Check
         rss_check_obj.e621_sub_list = rfl
         # Invalid title
         self.function_dispatcher.dispatch("e621 sub check Not a valid search", self.test_user, self.test_chan)
         data = self.server.get_send_data(1, self.test_chan, Server.MSG_MSG)
         assert "error" in data[0][0].lower()
         # Correct title but wrong channel
         self.function_dispatcher.dispatch("e621 sub check deer", self.test_user, chan1)
         data = serv1.get_send_data(1, chan1, Server.MSG_MSG)
         assert "error" in data[0][0].lower()
         # Correct title check update
         self.function_dispatcher.dispatch("e621 sub check deer", self.test_user, chan2)
         data = serv1.get_send_data(1, chan2, Server.MSG_MSG)
         assert "search updates were found" in data[0][0].lower()
         assert len(data[0][0].lower().split("\n")) == 51
         # No updates
         self.function_dispatcher.dispatch("e621 sub check deer", self.test_user, chan2)
         data = serv1.get_send_data(1, chan2, Server.MSG_MSG)
         assert "no updates" in data[0][0], "No further updates should be found."
     finally:
         self.hallo.remove_server(serv2)
         self.hallo.remove_server(serv1)
Ejemplo n.º 20
0
 def test_deop_0(self):
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     serv1.type = Server.TYPE_IRC
     self.hallo.add_server(serv1)
     chan1 = serv1.get_channel_by_name("test_chan1")
     chan1.in_channel = True
     user1 = serv1.get_user_by_name("test_user1")
     user_hallo = serv1.get_user_by_name(serv1.get_nick())
     chan1.add_user(user1)
     chan1.add_user(user_hallo)
     chan1_user1 = chan1.get_membership_by_user(user1)
     chan1_user1.is_op = True
     chan1_hallo = chan1.get_membership_by_user(user_hallo)
     chan1_hallo.is_op = True
     try:
         self.function_dispatcher.dispatch("deop", user1, chan1)
         data = serv1.get_send_data(2)
         assert "error" not in data[0][0].lower()
         assert data[0][1] is None
         assert data[1][1] == chan1
         assert data[0][2] == Server.MSG_RAW
         assert data[1][2] == Server.MSG_MSG
         assert data[0][0][:4] == "MODE"
         assert chan1.name+" -o "+user1.name in data[0][0]
         assert "status taken" in data[1][0].lower()
     finally:
         self.hallo.remove_server(serv1)
Ejemplo n.º 21
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
         rfl = SubscriptionRepo()
         rf1 = RssSub(chan1.server, chan1, "http://spangle.org.uk/hallo/test_rss.xml?1",
                      title="test_feed1", update_frequency=Commons.load_time_delta("PT3600S"))
         rfl.add_sub(rf1)
         rf2 = RssSub(chan2.server, chan2, "http://spangle.org.uk/hallo/test_rss.xml?2",
                      title="test_feed2", update_frequency=Commons.load_time_delta("PT3600S"))
         rfl.add_sub(rf2)
         rf3 = RssSub(chan3.server, chan3, "http://spangle.org.uk/hallo/test_rss.xml?3",
                      title="test_feed1", update_frequency=Commons.load_time_delta("PT3600S"))
         rfl.add_sub(rf3)
         # 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 = rfl
         # Test running all feed updates
         self.function_dispatcher.dispatch(EventMessage(self.server, self.test_chan, self.test_user,
                                                        "rss 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
         # 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.channel == chan1:
                 chan1_count += 1
             if data_line.channel == chan2:
                 chan2_count += 1
         assert chan1_count == 3
         assert chan2_count == 3
         # Check test server 2 data
         serv2.get_send_data(3, chan3, EventMessage)
         # Test running with no new updates.
         self.function_dispatcher.dispatch(EventMessage(self.server, self.test_chan, self.test_user,
                                                        "rss 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)
Ejemplo n.º 22
0
 def test_reply_pew(self):
     reply_func = self.function_dispatcher.get_function_by_name("reply")
     reply_obj = self.function_dispatcher.get_function_object(reply_func)  # type: Reply
     # Check pewpew
     response = reply_obj.passive_run(Function.EVENT_MESSAGE, "pew",
                                      None, self.server, self.test_user, self.test_chan)
     assert response == "pew pew"
     # Check blacklist
     serv1 = ServerMock(None)
     serv1.name = "canternet"
     chan1 = serv1.get_channel_by_name("#ukofequestria")
     user1 = serv1.get_user_by_name("test_user")
     response = reply_obj.passive_run(Function.EVENT_MESSAGE, "pew",
                                      None, serv1, user1, chan1)
     assert response is None
Ejemplo n.º 23
0
 def test_server_specified_no_channel(self):
     # Set up test resources
     test_serv = ServerMock(self.hallo)
     test_serv.name = "TestServer1"
     self.hallo.add_server(test_serv)
     test_chan = test_serv.get_channel_by_address("#not_in_channel".lower(), "#not_in_channel")
     test_chan.in_channel = False
     # Send command
     self.function_dispatcher.dispatch(EventMessage(self.server, self.test_chan, self.test_user,
                                                    "leave server="+test_serv.name+" "+test_chan.name))
     # Check response data
     data = self.server.get_send_data(1, self.test_chan, EventMessage)
     self.server.get_left_channels(0)
     test_serv.get_left_channels(0)
     assert "error" in data[0].text.lower()
Ejemplo n.º 24
0
 def test_server_specified_first(self):
     # Set up test resources
     test_serv = ServerMock(self.hallo)
     test_serv.name = "TestServer1"
     self.hallo.add_server(test_serv)
     test_chan = test_serv.get_channel_by_name("#other_serv")
     test_chan.in_channel = True
     # Send command
     self.function_dispatcher.dispatch("leave server="+test_serv.name+" "+test_chan.name, self.test_user,
                                       self.test_chan)
     # Check response data
     data = self.server.get_send_data(1, self.test_chan, Server.MSG_MSG)
     self.server.get_left_channels(0)
     chans = test_serv.get_left_channels(1)
     assert chans[0] == test_chan
     assert "left" in data[0][0].lower()
     assert test_chan.name in data[0][0].lower()
Ejemplo n.º 25
0
 def test_server_specified_second(self):
     # Set up test resources
     test_serv = ServerMock(self.hallo)
     test_serv.name = "TestServer1"
     self.hallo.add_server(test_serv)
     test_chan = test_serv.get_channel_by_address("#other_serv".lower(), "#other_serv")
     test_chan.in_channel = True
     # Send command
     self.function_dispatcher.dispatch(EventMessage(self.server, self.test_chan, self.test_user,
                                                    "leave "+test_chan.name+" server="+test_serv.name))
     # Check response data
     data = self.server.get_send_data(1, self.test_chan, EventMessage)
     self.server.get_left_channels(0)
     chans = test_serv.get_left_channels(1)
     assert chans[0] == test_chan
     assert "left" in data[0].text.lower()
     assert test_chan.name in data[0].text.lower()
Ejemplo n.º 26
0
 def test_get_feeds_by_url(self):
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     serv2 = ServerMock(self.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 = RssSub(chan1.server, chan1, "http://spangle.org.uk/hallo/test_feed.xml?1", title="test_feed1")
     rfl.add_sub(rf1)
     rf2 = RssSub(user2.server, user2, "http://spangle.org.uk/hallo/test_feed.xml?2", title="test_feed2")
     rfl.add_sub(rf2)
     rf3 = RssSub(chan3.server, chan3, "http://spangle.org.uk/hallo/test_feed.xml?3", title="test_feed3")
     rfl.add_sub(rf3)
     rf4 = RssSub(chan3.server, chan3, "http://spangle.org.uk/hallo/test_feed.xml?4", title="test_feed4")
     rfl.add_sub(rf4)
     rf5 = RssSub(chan3.server, chan3, "http://spangle.org.uk/hallo/test_feed.xml?4", title="test_feed3")
     rfl.add_sub(rf5)
     # Check function
     feed_list = rfl.get_subs_by_name("http://spangle.org.uk/hallo/test_feed.xml?4", chan3)
     assert len(feed_list) == 2
     assert rf4 in feed_list
     assert rf5 in feed_list
Ejemplo n.º 27
0
 def test_help_mock_func_disp(self):
     # Set up mock objects
     mock_hallo = Hallo()
     mock_func_disp = FunctionDispatcher({}, mock_hallo)
     mock_hallo.function_dispatcher = mock_func_disp
     mock_func_disp.load_function(FunctionMock)
     mock_func_disp.load_function(FunctionMockNoDoc)
     mock_func_disp.load_function(Help)
     mock_server = ServerMock(mock_hallo)
     mock_server.name = "test_serv1"
     mock_user = mock_server.get_user_by_name("test_user1")
     # Test things
     mock_func_disp.dispatch("help", mock_user, mock_user)
     data = mock_server.get_send_data(1, mock_user, Server.MSG_MSG)
     assert "error" not in data[0][0].lower()
     assert "list of available functions:" in data[0][0].lower()
     assert "function mock" in data[0][0].lower()
     assert "function no doc" in data[0][0].lower()
Ejemplo n.º 28
0
 def test_connect_to_known_server(self):
     # Set up an example server
     server_name = "known_server_name"
     test_server = ServerMock(self.hallo)
     test_server.name = server_name
     test_server.auto_connect = False
     self.hallo.add_server(test_server)
     # Call connect function
     self.function_dispatcher.dispatch("connect "+server_name, self.test_user, self.test_chan)
     # Ensure response is correct
     data = self.server.get_send_data(1, self.test_chan, Server.MSG_MSG)
     assert "error" not in data[0][0].lower(), data[0][0].lower()
     assert "connected" in data[0][0].lower(), data[0][0].lower()
     assert server_name in data[0][0].lower(), data[0][0].lower()
     # Ensure auto connect was set
     assert test_server.auto_connect, "Auto connect should have been set to true."
     # Ensure server was ran
     assert test_server.open, "Test server was not started."
Ejemplo n.º 29
0
 def test_connect_to_known_server_fail_connected(self):
     # Set up example server
     server_name = "known_server_name"
     test_server = ServerMock(self.hallo)
     test_server.name = server_name
     test_server.auto_connect = False
     test_server.open = True
     self.hallo.add_server(test_server)
     # Call connect function
     self.function_dispatcher.dispatch("connect "+server_name, self.test_user, self.test_chan)
     # Ensure error response is given
     data = self.server.get_send_data(1, self.test_chan, Server.MSG_MSG)
     assert "error" in data[0][0].lower(), data[0][0].lower()
     assert "already connected" in data[0][0].lower(), data[0][0].lower()
     # Ensure auto connect was still set
     assert test_server.auto_connect, "Auto connect should have still been set to true."
     # Ensure server is still running
     assert test_server.open, "Test server should not have been shut down."
Ejemplo n.º 30
0
 def test_help_mock_func_disp(self):
     # Set up mock objects
     mock_hallo = Hallo()
     mock_func_disp = FunctionDispatcher(set(), mock_hallo)
     mock_hallo.function_dispatcher = mock_func_disp
     mock_func_disp.load_function(FunctionMock)
     mock_func_disp.load_function(FunctionMockNoDoc)
     mock_func_disp.load_function(Help)
     mock_server = ServerMock(mock_hallo)
     mock_server.name = "test_serv1"
     mock_user = mock_server.get_user_by_address("test_user1".lower(), "test_user1")
     # Test things
     mock_func_disp.dispatch(EventMessage(mock_server, None, mock_user, "help"))
     data = mock_server.get_send_data(1, mock_user, EventMessage)
     assert "error" not in data[0].text.lower()
     assert "list of available functions:" in data[0].text.lower()
     assert "function mock" in data[0].text.lower()
     assert "function no doc" in data[0].text.lower()