예제 #1
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)
예제 #2
0
 def test_1_user_just_name_privmsg(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_name("test_chan1")
     perm1 = PermissionMask()
     chan1.permission_mask = perm1
     user1 = serv1.get_user_by_name("test_user1")
     perm2 = PermissionMask()
     user1.permission_mask = perm2
     chan1.add_user(user1)
     user2 = serv1.get_user_by_name("test_user2")
     perm4 = PermissionMask()
     user2.permission_mask = perm4
     # Get permissions of specified user group
     try:
         data = self.perm_cont.find_permission_mask(["test_user2"], user1, None)
         assert False, "Find permission mask should have failed."
     except modules.PermissionControl.PermissionControlException as e:
         assert "error" in str(e).lower()
         assert "i can't find that permission mask" in str(e).lower()
예제 #3
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)
예제 #4
0
 def test_voice_1_user_is_voice(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")
     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
     chan1.add_user(user2)
     chan1_user2 = chan1.get_membership_by_user(user2)
     chan1_user2.is_op = False
     chan1_user2.is_voice = True
     try:
         self.function_dispatcher.dispatch("voice test_user2", user1, chan1)
         data = serv1.get_send_data(1, chan1, Server.MSG_MSG)
         assert "error" in data[0][0].lower()
         assert "already has voice" in data[0][0].lower()
     finally:
         self.hallo.remove_server(serv1)
예제 #5
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)
예제 #6
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_name("test_chan1")
     perm1 = PermissionMask()
     chan1.permission_mask = perm1
     user1 = serv1.get_user_by_name("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()
예제 #7
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"
예제 #8
0
 def test_deop_0_privmsg(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")
     user1 = serv1.get_user_by_name("test_user1")
     chan1.add_user(user1)
     chan1.add_user(serv1.get_user_by_name(serv1.get_nick()))
     try:
         self.function_dispatcher.dispatch("deop", user1, user1)
         data = serv1.get_send_data(1, user1, Server.MSG_MSG)
         assert "error" in data[0][0].lower()
         assert "in a private message" in data[0][0].lower()
     finally:
         self.hallo.remove_server(serv1)
예제 #9
0
 def test_run_fail_not_bool(self):
     # Set up a test hallo and server and channel and user
     hallo1 = Hallo()
     perm0 = PermissionMask()
     hallo1.permission_mask = perm0
     serv1 = ServerMock(hallo1)
     serv1.name = "test_serv1"
     perm1 = PermissionMask()
     serv1.permission_mask = perm1
     hallo1.add_server(serv1)
     chan1 = serv1.get_channel_by_name("test_chan1")
     perm2 = PermissionMask()
     chan1.permission_mask = perm2
     user1 = serv1.get_user_by_name("test_user1")
     perm3 = PermissionMask()
     user1.permission_mask = perm3
     # Get permission mask of given channel
     test_right = "test_right"
     perm1.set_right(test_right, True)
     self.function_dispatcher.dispatch("permissions server=test_serv1 "+test_right+" yellow", user1, chan1)
     data = serv1.get_send_data(1, chan1, Server.MSG_MSG)
     assert "error" in data[0][0].lower()
     assert "don't understand your boolean value" in data[0][0].lower()
     assert test_right in perm1.rights_map
     assert perm1.rights_map[test_right]
예제 #10
0
 def test_run_set_off(self):
     # Set up a test hallo and server and channel and user
     hallo1 = Hallo()
     perm0 = PermissionMask()
     hallo1.permission_mask = perm0
     serv1 = ServerMock(hallo1)
     serv1.name = "test_serv1"
     perm1 = PermissionMask()
     serv1.permission_mask = perm1
     hallo1.add_server(serv1)
     chan1 = serv1.get_channel_by_name("test_chan1")
     perm2 = PermissionMask()
     chan1.permission_mask = perm2
     user1 = serv1.get_user_by_name("test_user1")
     perm3 = PermissionMask()
     user1.permission_mask = perm3
     # Get permission mask of given channel
     test_right = "test_right"
     perm2.set_right(test_right, True)
     self.function_dispatcher.dispatch("permissions server=test_serv1 channel=test_chan1 "+test_right+" off",
                                       user1, chan1)
     data = serv1.get_send_data(1, chan1, Server.MSG_MSG)
     assert "error" not in data[0][0].lower()
     assert "set "+test_right+" to false" in data[0][0].lower()
     assert test_right in perm2.rights_map
     assert not perm2.rights_map[test_right]
예제 #11
0
 def test_deop_not_irc(self):
     serv1 = ServerMock(self.hallo)
     serv1.name = "test_serv1"
     serv1.type = "NOT_IRC"
     self.hallo.add_server(serv1)
     chan1 = serv1.get_channel_by_name("test_chan1")
     user1 = serv1.get_user_by_name("test_user1")
     chan1.add_user(user1)
     chan1.add_user(serv1.get_user_by_name(serv1.get_nick()))
     try:
         self.function_dispatcher.dispatch("deop", user1, chan1)
         data = serv1.get_send_data(1, chan1, Server.MSG_MSG)
         assert "error" in data[0][0].lower()
         assert "only available for irc" in data[0][0].lower()
     finally:
         self.hallo.remove_server(serv1)
예제 #12
0
 def test_deop_0_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_name("test_chan1")
     chan1.in_channel = True
     user1 = serv1.get_user_by_name("test_user1")
     chan1.add_user(user1)
     chan1.add_user(serv1.get_user_by_name(serv1.get_nick()))
     try:
         self.function_dispatcher.dispatch("deop", user1, chan1)
         data = serv1.get_send_data(1, chan1, Server.MSG_MSG)
         assert "error" in data[0][0].lower()
         assert "don't have power" in data[0][0].lower()
     finally:
         self.hallo.remove_server(serv1)
예제 #13
0
 def test_deop_1priv_user_not_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
     user1 = serv1.get_user_by_name("test_user1")
     user_hallo = serv1.get_user_by_name(serv1.get_nick())
     chan1.add_user(user_hallo)
     chan1_hallo = chan1.get_membership_by_user(user_hallo)
     chan1_hallo.is_op = True
     try:
         self.function_dispatcher.dispatch("deop test_chan1", user1, user1)
         data = serv1.get_send_data(1, user1, Server.MSG_MSG)
         assert "error" in data[0][0].lower()
         assert "test_user1 is not in test_chan1" in data[0][0].lower()
     finally:
         self.hallo.remove_server(serv1)
예제 #14
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()
예제 #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_name("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."
예제 #16
0
 def test_invite_0_fail(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 = False
     chan1_hallo = chan1.get_membership_by_user(user_hallo)
     chan1_hallo.is_op = True
     try:
         self.function_dispatcher.dispatch("invite", user1, chan1)
         data = serv1.get_send_data(1, chan1, Server.MSG_MSG)
         assert "error" in data[0][0].lower()
         assert "specify a user to invite and/or a channel" in data[0][0].lower()
     finally:
         self.hallo.remove_server(serv1)
예제 #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_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)
예제 #18
0
 def test_1_user_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_name("test_chan1")
     perm1 = PermissionMask()
     chan1.permission_mask = perm1
     user1 = serv1.get_user_by_name("test_user1")
     perm2 = PermissionMask()
     user1.permission_mask = perm2
     user2 = serv1.get_user_by_name("test_user2")
     perm4 = PermissionMask()
     user2.permission_mask = perm4
     # Get permissions of specified user
     data = self.perm_cont.find_permission_mask(["user=test_user2"], user1, chan1)
     assert data == perm4, "Did not find the correct permission mask."
예제 #19
0
 def test_mute_1_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_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 = False
     chan1_hallo = chan1.get_membership_by_user(user_hallo)
     chan1_hallo.is_op = False
     try:
         self.function_dispatcher.dispatch("mute test_chan1", user1, user1)
         data = serv1.get_send_data(1, user1, Server.MSG_MSG)
         assert "error" in data[0][0].lower()
         assert "don't have power" in data[0][0].lower()
     finally:
         self.hallo.remove_server(serv1)
예제 #20
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
예제 #21
0
 def test_get_feeds_by_title(self):
     serv1 = ServerMock(None)
     serv1.name = "test_serv1"
     serv2 = ServerMock(None)
     serv2.name = "test_serv2"
     chan1 = serv1.get_channel_by_name("test_chan1")
     user2 = serv1.get_user_by_name("test_user2")
     chan3 = serv2.get_channel_by_name("test_chan3")
     # Setup a feed list
     rfl = RssFeedList()
     rf1 = RssFeed()
     rf1.url = "http://spangle.org.uk/hallo/test_feed.xml?1"
     rf1.title = "test_feed1"
     rf1.server_name = chan1.server.name
     rf1.channel_name = chan1.name
     rfl.add_feed(rf1)
     rf2 = RssFeed()
     rf2.url = "http://spangle.org.uk/hallo/test_feed.xml?2"
     rf2.title = "test_feed2"
     rf2.server_name = user2.server.name
     rf2.user_name = user2.name
     rfl.add_feed(rf2)
     rf3 = RssFeed()
     rf3.url = "http://spangle.org.uk/hallo/test_feed.xml?3"
     rf3.title = "test_feed3"
     rf3.server_name = chan3.server.name
     rf3.channel_name = chan3.name
     rfl.add_feed(rf3)
     rf4 = RssFeed()
     rf4.url = "http://spangle.org.uk/hallo/test_feed.xml?4"
     rf4.title = "test_feed4"
     rf4.server_name = chan3.server.name
     rf4.channel_name = chan3.name
     rfl.add_feed(rf4)
     rf5 = RssFeed()
     rf5.url = "http://spangle.org.uk/hallo/test_feed.xml?5"
     rf5.title = "test_feed3"
     rf5.server_name = chan3.server.name
     rf5.channel_name = chan3.name
     rfl.add_feed(rf5)
     # Check function
     feed_list = rfl.get_feeds_by_title("test_feed3", chan3)
     assert len(feed_list) == 2
     assert rf3 in feed_list
     assert rf5 in feed_list
예제 #22
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()
예제 #23
0
 def test_get_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")
     # Basic ReplyMessageList get_response() test
     rml1 = ReplyMessageList()
     rm1 = ReplyMessage("test1")
     rm1.add_response("response1")
     rm2 = ReplyMessage("test2")
     rm2.add_response("response2")
     rml1.add_reply_message(rm1)
     rml1.add_reply_message(rm2)
     # Check response 1 works
     assert rml1.get_response("test1", user1, chan1) == "response1"
     assert rml1.get_response("test2", user1, chan1) == "response2"
     assert rml1.get_response("test3", user1, chan1) is None
     # Check blacklists
     rml2 = ReplyMessageList()
     rm1 = ReplyMessage("test")
     rm1.add_response("response1")
     rm1.add_blacklist(serv1.name, chan1.name)
     rm2 = ReplyMessage("test")
     rm2.add_response("response2")
     rml2.add_reply_message(rm1)
     rml2.add_reply_message(rm2)
     assert rml2.get_response("test", user1, chan1) == "response2"
     # Check whitelists
     rml3 = ReplyMessageList()
     rm1 = ReplyMessage("test")
     rm1.add_response("response1")
     rm1.add_whitelist(serv1.name, "not_chan_1")
     rm2 = ReplyMessage("test")
     rm2.add_response("response2")
     rml3.add_reply_message(rm1)
     rml3.add_reply_message(rm2)
     assert rml3.get_response("test", user1, chan1) == "response2"
     # Check replacements
     rml4 = ReplyMessageList()
     rm1 = ReplyMessage("test")
     rm1.add_response("response {USER} {CHANNEL} {SERVER}")
     rml4.add_reply_message(rm1)
     assert rml4.get_response("test", user1, chan1) == "response test_user1 test_chan1 test_serv1"
예제 #24
0
 def test_2_server_no_chan_user(self):
     # Set up a test server and channel and user
     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
     user1 = serv1.get_user_by_name("test_user1")
     perm2 = PermissionMask()
     user1.permission_mask = perm2
     # Get permission mask of given channel
     try:
         data = self.perm_cont.find_permission_mask(["server=test_serv1", "core"],
                                                    user1, chan1)
         assert False, "Should have failed to find any permission mask."
     except modules.PermissionControl.PermissionControlException as e:
         assert "error" in str(e).lower()
         assert "server but not channel or user" in str(e).lower()
예제 #25
0
 def test_1_hallo(self):
     # Set up a test hallo and 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_name("test_chan1")
     perm1 = PermissionMask()
     chan1.permission_mask = perm1
     user1 = serv1.get_user_by_name("test_user1")
     perm2 = PermissionMask()
     user1.permission_mask = perm2
     # Get permission of hallo
     data = self.perm_cont.find_permission_mask(["hallo"], user1, chan1)
     assert data == perm3, "Did not find the correct permission mask."
예제 #26
0
 def test_reply_haskell(self):
     reply_func = self.function_dispatcher.get_function_by_name("reply")
     reply_obj = self.function_dispatcher.get_function_object(reply_func)  # type: Reply
     # Check haskell.jpg
     response = reply_obj.passive_run(Function.EVENT_MESSAGE, "haskell.jpg",
                                      None, self.server, self.test_user, self.test_chan)
     assert response is None
     # Check on correct channel
     serv1 = ServerMock(None)
     serv1.name = "shadowworld"
     chan1 = serv1.get_channel_by_name("#ecco-the-dolphin")
     user1 = serv1.get_user_by_name("test_user")
     response = reply_obj.passive_run(Function.EVENT_MESSAGE, "haskell.jpg",
                                      None, serv1, user1, chan1)
     assert "http" in response.lower()
     assert "haskell.jpg" in response.lower()
     # Check image exists
     page_request = urllib.request.Request(response)
     page_opener = urllib.request.build_opener()
     response_data = page_opener.open(page_request).read()
     assert len(response_data) > 0, "haskell.jpg image does not exist."
예제 #27
0
 def test_1_server_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_name("test_chan1")
     perm1 = PermissionMask()
     chan1.permission_mask = perm1
     user1 = serv1.get_user_by_name("test_user1")
     perm2 = PermissionMask()
     user1.permission_mask = perm2
     # Get permissions of current server
     try:
         data = self.perm_cont.find_permission_mask(["server=test_serv2"], user1, chan1)
         assert False, "Find permission mask should have failed."
     except modules.PermissionControl.PermissionControlException as e:
         assert "error" in str(e).lower()
         assert "no server exists by that name" in str(e).lower()
예제 #28
0
 def test_1_channel_privmsg(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_name("test_chan1")
     perm1 = PermissionMask()
     chan1.permission_mask = perm1
     user1 = serv1.get_user_by_name("test_user1")
     perm2 = PermissionMask()
     user1.permission_mask = perm2
     # Try to get permissions of current channel from a privmsg
     try:
         data = self.perm_cont.find_permission_mask(["channel"], user1, None)
         assert False, "Should not have managed to get permission mask."
     except modules.PermissionControl.PermissionControlException as e:
         assert "error" in str(e).lower()
         assert "can't set generic channel permissions in a privmsg" in str(e).lower()
예제 #29
0
 def test_output_item(self):
     # Create example rss item element
     item_title = "test_title1"
     item_link = "http://example.com/item1"
     feed_title = "feed_title1"
     rss_data = "<channel><item><title>" + item_title + "</title><link>" + item_link + "</link></item></channel>"
     rss_elem = ElementTree.fromstring(rss_data)
     item_elem = rss_elem.find("item")
     # Check output works with given server and channel
     rf1 = RssFeed()
     rf1.update_frequency = Commons.load_time_delta("P1TS")
     rf1.title = feed_title
     serv1 = ServerMock(None)
     serv1.name = "test_serv1"
     chan1 = serv1.get_channel_by_name("test_chan1")
     rf1.output_item(item_elem, None, serv1, chan1)
     data = serv1.get_send_data(1, chan1, Server.MSG_MSG)
     assert feed_title in data[0][0]
     assert item_title in data[0][0]
     assert item_link in data[0][0]
     # Check output works with given server not channel
     rf2 = RssFeed()
     rf2.update_frequency = Commons.load_time_delta("P1TS")
     rf2.title = feed_title
     rf2.channel_name = "test_chan2"
     serv2 = ServerMock(None)
     serv2.name = "test_serv2"
     chan2 = serv2.get_channel_by_name("test_chan2")
     rf2.output_item(item_elem, None, serv2)
     data = serv2.get_send_data(1, chan2, Server.MSG_MSG)
     assert feed_title in data[0][0]
     assert item_title in data[0][0]
     assert item_link in data[0][0]
     # Check output works with given server not user
     rf3 = RssFeed()
     rf3.update_frequency = Commons.load_time_delta("P1TS")
     rf3.title = feed_title
     rf3.user_name = "test_user3"
     serv3 = ServerMock(None)
     serv3.name = "test_serv3"
     user3 = serv3.get_user_by_name("test_user3")
     rf3.output_item(item_elem, None, serv3)
     data = serv3.get_send_data(1, user3, Server.MSG_MSG)
     assert feed_title in data[0][0]
     assert item_title in data[0][0]
     assert item_link in data[0][0]
     # Check output works without given server with given channel
     rf4 = RssFeed()
     rf4.update_frequency = Commons.load_time_delta("P1TS")
     rf4.title = feed_title
     rf4.server_name = "test_serv4"
     serv4 = ServerMock(None)
     serv4.name = "test_serv4"
     hallo4 = Hallo()
     hallo4.add_server(serv4)
     chan4 = serv4.get_channel_by_name("test_chan4")
     rf4.output_item(item_elem, hallo4, None, chan4)
     data = serv4.get_send_data(1, chan4, Server.MSG_MSG)
     assert feed_title in data[0][0]
     assert item_title in data[0][0]
     assert item_link in data[0][0]
     # Check output works without given server with given user
     rf5 = RssFeed()
     rf5.update_frequency = Commons.load_time_delta("P1TS")
     rf5.title = feed_title
     rf5.server_name = "test_serv5"
     serv5 = ServerMock(None)
     serv5.name = "test_serv5"
     hallo5 = Hallo()
     hallo5.add_server(serv5)
     chan5 = serv5.get_channel_by_name("test_chan5")
     rf5.output_item(item_elem, hallo5, None, chan5)
     data = serv5.get_send_data(1, chan5, Server.MSG_MSG)
     assert feed_title in data[0][0]
     assert item_title in data[0][0]
     assert item_link in data[0][0]
     # Check output works without given server or channel to channel
     rf6 = RssFeed()
     rf6.update_frequency = Commons.load_time_delta("P1TS")
     rf6.title = feed_title
     rf6.server_name = "test_serv6"
     rf6.channel_name = "test_chan6"
     serv6 = ServerMock(None)
     serv6.name = "test_serv6"
     hallo6 = Hallo()
     hallo6.add_server(serv6)
     chan6 = serv6.get_channel_by_name("test_chan6")
     rf6.output_item(item_elem, hallo6)
     data = serv6.get_send_data(1, chan6, Server.MSG_MSG)
     assert feed_title in data[0][0]
     assert item_title in data[0][0]
     assert item_link in data[0][0]
     # Check output works without given server or channel to user
     rf7 = RssFeed()
     rf7.update_frequency = Commons.load_time_delta("P1TS")
     rf7.title = feed_title
     rf7.server_name = "test_serv7"
     rf7.user_name = "test_user7"
     serv7 = ServerMock(None)
     serv7.name = "test_serv7"
     hallo7 = Hallo()
     hallo7.add_server(serv7)
     user7 = serv7.get_user_by_name("test_user7")
     rf7.output_item(item_elem, hallo7)
     data = serv7.get_send_data(1, user7, Server.MSG_MSG)
     assert feed_title in data[0][0]
     assert item_title in data[0][0]
     assert item_link in data[0][0]
     # Check invalid server output (server name is none)
     rf8 = RssFeed()
     rf8.update_frequency = Commons.load_time_delta("P1TS")
     rf8.title = feed_title
     hallo8 = Hallo()
     resp = rf8.output_item(item_elem, hallo8)
     assert "error" in resp.lower()
     assert "server" in resp.lower()
     # Check invalid server output ( server name is not in hallo obj)
     rf9 = RssFeed()
     rf9.update_frequency = Commons.load_time_delta("P1TS")
     rf9.title = feed_title
     rf9.server_name = "not_a_server"
     hallo9 = Hallo()
     resp = rf9.output_item(item_elem, hallo9)
     assert "error" in resp.lower()
     assert "server" in resp.lower()
     # Check invalid channel/user output (only possible if channel name and user name are none) (with given server)
     rf10 = RssFeed()
     rf10.update_frequency = Commons.load_time_delta("P1TS")
     rf10.title = feed_title
     serv10 = ServerMock(None)
     serv10.name = "test_serv10"
     hallo10 = Hallo()
     hallo10.add_server(serv10)
     resp = rf10.output_item(item_elem, hallo10, serv10)
     assert "error" in resp.lower()
     assert "destination" in resp.lower()
     # Check invalid channel/user output (only possible if channel name and user name are none) (with named server)
     rf11 = RssFeed()
     rf11.update_frequency = Commons.load_time_delta("P1TS")
     rf11.title = feed_title
     rf11.server_name = "test_serv11"
     serv11 = ServerMock(None)
     serv11.name = "test_serv11"
     hallo11 = Hallo()
     hallo11.add_server(serv11)
     resp = rf11.output_item(item_elem, hallo11)
     assert "error" in resp.lower()
     assert "destination" in resp.lower()
예제 #30
0
 def test_output_item(self):
     # Create example e621 sub element
     item_id = "652362"
     item_rate = "q"
     item_rating = "(Questionable)"
     item_elem = {"id":item_id, "rating":item_rate}
     # Check output works with given server and channel
     rf1 = E621Sub()
     rf1.update_frequency = Commons.load_time_delta("P1TS")
     serv1 = ServerMock(None)
     serv1.name = "test_serv1"
     chan1 = serv1.get_channel_by_name("test_chan1")
     rf1.output_item(item_elem, None, serv1, chan1)
     data = serv1.get_send_data(1, chan1, Server.MSG_MSG)
     assert item_id in data[0][0]
     assert item_rating in data[0][0]
     # Check output works with given server not channel
     rf2 = E621Sub()
     rf2.update_frequency = Commons.load_time_delta("P1TS")
     rf2.channel_name = "test_chan2"
     serv2 = ServerMock(None)
     serv2.name = "test_serv2"
     chan2 = serv2.get_channel_by_name("test_chan2")
     rf2.output_item(item_elem, None, serv2)
     data = serv2.get_send_data(1, chan2, Server.MSG_MSG)
     assert item_id in data[0][0]
     assert item_rating in data[0][0]
     # Check output works with given server not user
     rf3 = E621Sub()
     rf3.update_frequency = Commons.load_time_delta("P1TS")
     rf3.user_name = "test_user3"
     serv3 = ServerMock(None)
     serv3.name = "test_serv3"
     user3 = serv3.get_user_by_name("test_user3")
     rf3.output_item(item_elem, None, serv3)
     data = serv3.get_send_data(1, user3, Server.MSG_MSG)
     assert item_id in data[0][0]
     assert item_rating in data[0][0]
     # Check output works without given server with given channel
     rf4 = E621Sub()
     rf4.update_frequency = Commons.load_time_delta("P1TS")
     rf4.server_name = "test_serv4"
     serv4 = ServerMock(None)
     serv4.name = "test_serv4"
     hallo4 = Hallo()
     hallo4.add_server(serv4)
     chan4 = serv4.get_channel_by_name("test_chan4")
     rf4.output_item(item_elem, hallo4, None, chan4)
     data = serv4.get_send_data(1, chan4, Server.MSG_MSG)
     assert item_id in data[0][0]
     assert item_rating in data[0][0]
     # Check output works without given server with given user
     rf5 = E621Sub()
     rf5.update_frequency = Commons.load_time_delta("P1TS")
     rf5.server_name = "test_serv5"
     serv5 = ServerMock(None)
     serv5.name = "test_serv5"
     hallo5 = Hallo()
     hallo5.add_server(serv5)
     chan5 = serv5.get_channel_by_name("test_chan5")
     rf5.output_item(item_elem, hallo5, None, chan5)
     data = serv5.get_send_data(1, chan5, Server.MSG_MSG)
     assert item_id in data[0][0]
     assert item_rating in data[0][0]
     # Check output works without given server or channel to channel
     rf6 = E621Sub()
     rf6.update_frequency = Commons.load_time_delta("P1TS")
     rf6.server_name = "test_serv6"
     rf6.channel_name = "test_chan6"
     serv6 = ServerMock(None)
     serv6.name = "test_serv6"
     hallo6 = Hallo()
     hallo6.add_server(serv6)
     chan6 = serv6.get_channel_by_name("test_chan6")
     rf6.output_item(item_elem, hallo6)
     data = serv6.get_send_data(1, chan6, Server.MSG_MSG)
     assert item_id in data[0][0]
     assert item_rating in data[0][0]
     # Check output works without given server or channel to user
     rf7 = E621Sub()
     rf7.update_frequency = Commons.load_time_delta("P1TS")
     rf7.server_name = "test_serv7"
     rf7.user_name = "test_user7"
     serv7 = ServerMock(None)
     serv7.name = "test_serv7"
     hallo7 = Hallo()
     hallo7.add_server(serv7)
     user7 = serv7.get_user_by_name("test_user7")
     rf7.output_item(item_elem, hallo7)
     data = serv7.get_send_data(1, user7, Server.MSG_MSG)
     assert item_id in data[0][0]
     assert item_rating in data[0][0]
     # Check invalid server output (server name is none)
     rf8 = E621Sub()
     rf8.update_frequency = Commons.load_time_delta("P1TS")
     hallo8 = Hallo()
     resp = rf8.output_item(item_elem, hallo8)
     assert "error" in resp.lower()
     assert "server" in resp.lower()
     # Check invalid server output ( server name is not in hallo obj)
     rf9 = E621Sub()
     rf9.update_frequency = Commons.load_time_delta("P1TS")
     rf9.server_name = "not_a_server"
     hallo9 = Hallo()
     resp = rf9.output_item(item_elem, hallo9)
     assert "error" in resp.lower()
     assert "server" in resp.lower()
     # Check invalid channel/user output (only possible if channel name and user name are none) (with given server)
     rf10 = E621Sub()
     rf10.update_frequency = Commons.load_time_delta("P1TS")
     serv10 = ServerMock(None)
     serv10.name = "test_serv10"
     hallo10 = Hallo()
     hallo10.add_server(serv10)
     resp = rf10.output_item(item_elem, hallo10, serv10)
     assert "error" in resp.lower()
     assert "destination" in resp.lower()
     # Check invalid channel/user output (only possible if channel name and user name are none) (with named server)
     rf11 = E621Sub()
     rf11.update_frequency = Commons.load_time_delta("P1TS")
     rf11.server_name = "test_serv11"
     serv11 = ServerMock(None)
     serv11.name = "test_serv11"
     hallo11 = Hallo()
     hallo11.add_server(serv11)
     resp = rf11.output_item(item_elem, hallo11)
     assert "error" in resp.lower()
     assert "destination" in resp.lower()