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_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 chan1.add_user(user1) user2 = serv1.get_user_by_address("test_user2".lower(), "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()
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_address("test_chan1".lower(), "test_chan1") perm2 = PermissionMask() chan1.permission_mask = perm2 user1 = serv1.get_user_by_address("test_user1", "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(EventMessage(serv1, chan1, user1, "permissions server=test_serv1 channel=test_chan1 " + test_right+" off")) data = serv1.get_send_data(1, chan1, EventMessage) assert "error" not in data[0].text.lower() assert "set "+test_right+" to false" in data[0].text.lower() assert test_right in perm2.rights_map assert not perm2.rights_map[test_right]
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()
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_address("test_chan1".lower(), "test_chan1") perm2 = PermissionMask() chan1.permission_mask = perm2 user1 = serv1.get_user_by_address("test_user1", "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(EventMessage(serv1, chan1, user1, "permissions server=test_serv1 "+test_right+" yellow")) data = serv1.get_send_data(1, chan1, EventMessage) assert "error" in data[0].text.lower() assert "don't understand your boolean value" in data[0].text.lower() assert test_right in perm1.rights_map assert perm1.rights_map[test_right]
def test_run_add_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" 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]
def test_run_fail_args(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, user1, chan1) data = serv1.get_send_data(1, chan1, Server.MSG_MSG) assert "error" in data[0][0].lower() assert "a location, a right and the value" in data[0][0].lower() assert test_right in perm1.rights_map assert perm1.rights_map[test_right]
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 = self.empty # Only the required modules, only 1 (mock) server # Todo: specify modules by test? self.function_dispatcher = FunctionDispatcher({"AsciiArt", "Bio", "ChannelControl", "Convert", "Euler", "HalloControl", "Math", "PermissionControl", "Random", "ServerControl", "Silly", "Subscriptions"}, 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.hallo_user = self.server.get_user_by_address(self.server.get_nick().lower(), self.server.get_nick()) self.test_user = self.server.get_user_by_address("test", "test") """ :type : Destination.User""" self.test_user.online = True self.test_chan = self.server.get_channel_by_address("#test", "#test") self.test_chan.in_channel = True self.test_chan.add_user(self.hallo_user) self.test_chan.add_user(self.test_user) # 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() print("Finished test: "+self.id()+". Test took: "+str(time.time()-self.start_time)+" seconds.") def empty(self, var1=None, var2=None, var3=None, var4=None): pass @classmethod def tearDownClass(cls): del cls gc.collect()
def test_1_channel(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 # Get permissions of current channel data = self.perm_cont.find_permission_mask(["channel"], user1, chan1) assert data == perm1, "Did not find the correct permission mask."
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."
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."
def test_1_user_group_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) # Get permissions of specified user group data = self.perm_cont.find_permission_mask(["user_group=test_group1"], user1, chan1) assert data == perm4, "Did not find the correct permission mask."
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_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 # 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()
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_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 # 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()
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()
def test_output_item(self): # Create example rss item element example_url = "http://spangle.org.uk/hallo/test_rss.xml" 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 serv1 = ServerMock(self.hallo) serv1.name = "test_serv1" self.hallo.add_server(serv1) chan1 = serv1.get_channel_by_address("test_chan1") rf1 = RssSub(serv1, chan1, example_url, title=feed_title, update_frequency=Commons.load_time_delta("P1TS")) rf1.send_item(item_elem) data = serv1.get_send_data(1, chan1, EventMessage) assert feed_title in data[0].text assert item_title in data[0].text assert item_link in data[0].text # Check output works with given server not channel serv2 = ServerMock(self.hallo) serv2.name = "test_serv2" self.hallo.add_server(serv2) chan2 = serv2.get_channel_by_address("test_chan2") rf2 = RssSub(serv2, chan2, example_url, title=feed_title, update_frequency=Commons.load_time_delta("P1TS")) rf2.send_item(item_elem) data = serv2.get_send_data(1, chan2, EventMessage) assert feed_title in data[0].text assert item_title in data[0].text assert item_link in data[0].text # Check output works with given server not user serv3 = ServerMock(self.hallo) serv3.name = "test_serv3" self.hallo.add_server(serv3) user3 = serv3.get_user_by_address("test_user3") rf3 = RssSub(serv3, user3, example_url, title=feed_title, update_frequency=Commons.load_time_delta("P1TS")) rf3.send_item(item_elem) data = serv3.get_send_data(1, user3, EventMessage) assert feed_title in data[0].text assert item_title in data[0].text assert item_link in data[0].text # Check output works without given server with given channel hallo4 = Hallo() serv4 = ServerMock(hallo4) serv4.name = "test_serv4" hallo4.add_server(serv4) chan4 = serv4.get_channel_by_address("test_chan4") rf4 = RssSub(serv4, chan4, example_url, title=feed_title, update_frequency=Commons.load_time_delta("P1TS")) rf4.send_item(item_elem) data = serv4.get_send_data(1, chan4, EventMessage) assert feed_title in data[0].text assert item_title in data[0].text assert item_link in data[0].text # Check output works without given server with given user hallo5 = Hallo() serv5 = ServerMock(hallo5) serv5.name = "test_serv5" hallo5.add_server(serv5) chan5 = serv5.get_channel_by_address("test_chan5") rf5 = RssSub(serv5, chan5, example_url, title=feed_title, update_frequency=Commons.load_time_delta("P1TS")) rf5.send_item(item_elem) data = serv5.get_send_data(1, chan5, EventMessage) assert feed_title in data[0].text assert item_title in data[0].text assert item_link in data[0].text # Check output works without given server or channel to channel hallo6 = Hallo() serv6 = ServerMock(hallo6) serv6.name = "test_serv6" hallo6.add_server(serv6) chan6 = serv6.get_channel_by_address("test_chan6") rf6 = RssSub(serv6, chan6, example_url, title=feed_title, update_frequency=Commons.load_time_delta("P1TS")) rf6.send_item(item_elem) data = serv6.get_send_data(1, chan6, EventMessage) assert feed_title in data[0].text assert item_title in data[0].text assert item_link in data[0].text # Check output works without given server or channel to user hallo7 = Hallo() serv7 = ServerMock(hallo7) serv7.name = "test_serv7" hallo7.add_server(serv7) user7 = serv7.get_user_by_address("test_user7") rf7 = RssSub(serv7, user7, example_url, title=feed_title, update_frequency=Commons.load_time_delta("P1TS")) rf7.send_item(item_elem) data = serv7.get_send_data(1, user7, EventMessage) assert feed_title in data[0].text assert item_title in data[0].text assert item_link in data[0].text
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()