def test_nickserv_password_inherit(self): # Set up test_nickserv_pass = "******" test_serv_irc = ServerIRC(self.hallo) test_serv_irc.prefix = "" test_serv_irc.name = "test_serv_irc" test_serv_irc.nickserv_pass = test_nickserv_pass test_chan_irc = test_serv_irc.get_channel_by_address( "test_chan".lower(), "test_chan" ) test_user_irc = test_serv_irc.get_user_by_address( "test_user".lower(), "test_user" ) # Run command self.function_dispatcher.dispatch( EventMessage( test_serv_irc, test_chan_irc, test_user_irc, "connect irc example.com:80", ) ) # Can't check response because I'm using a ServerIRC instead of a ServerMock # Find the right server assert ( len(self.hallo.server_list) == 2 ), "Incorrect number of servers in hallo instance." right_server = None # type: ServerIRC for server in self.hallo.server_list: if server is not self.server: right_server = server assert right_server is not None, "New server wasn't found." assert ( right_server.nickserv_pass == test_nickserv_pass ), "Nickserv password wasn't inherited"
def test_address_in_argument(self): test_url = "www.example.com" # Run command self.function_dispatcher.dispatch( EventMessage( self.server, self.test_chan, self.test_user, "connect irc " + test_url + " server_port=80", ) ) # Ensure correct response data = self.server.get_send_data(1, self.test_chan, EventMessage) assert ( "connected to new irc server" in data[0].text.lower() ), "Incorrect output: " + str(data[0].text) # Find the right server assert ( len(self.hallo.server_list) == 2 ), "Incorrect number of servers in hallo instance" right_server = None # type: ServerIRC for server in self.hallo.server_list: if server is not self.server: right_server = server assert right_server is not None, "New server wasn't found." assert right_server.server_address == test_url, "Address incorrect"
def test_full_name_inherit_string(self): # Set up test_name = "Hallo_Robot" self.server.full_name = test_name # Run command self.function_dispatcher.dispatch( EventMessage( self.server, self.test_chan, self.test_user, "connect irc www.example.com:80", ) ) # Ensure correct response data = self.server.get_send_data(1, self.test_chan, EventMessage) assert ( "connected to new irc server" in data[0].text.lower() ), "Incorrect output: " + str(data[0].text) # Find the right server assert ( len(self.hallo.server_list) == 2 ), "Incorrect number of servers in hallo instance." right_server = None # type: ServerIRC for server in self.hallo.server_list: if server is not self.server: right_server = server assert right_server is not None, "New server wasn't found." assert right_server.full_name == test_name, "Inherited full name was not used"
def test_nickserv_identity_resp_default(self): # Run command self.function_dispatcher.dispatch( EventMessage( self.server, self.test_chan, self.test_user, "connect irc www.example.com:80", ) ) # Ensure correct response data = self.server.get_send_data(1, self.test_chan, EventMessage) assert ( "connected to new irc server" in data[0].text.lower() ), "Incorrect output: " + str(data[0].text) # Find the right server assert ( len(self.hallo.server_list) == 2 ), "Incorrect number of servers in hallo instance." right_server = None # type: ServerIRC for server in self.hallo.server_list: if server is not self.server: right_server = server assert right_server is not None, "New server wasn't found." assert ( right_server.nickserv_ident_response == "^status [^ ]+ 3$" ), "Default nickserv identity response incorrect"
def test_devoice_2_user_not_in_channel(hallo_getter): hallo, test_server, test_chan, test_user = hallo_getter( {"channel_control"}) serv1 = ServerMock(hallo) serv1.name = "test_serv1" serv1.type = Server.TYPE_IRC 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 = False 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 try: hallo.function_dispatcher.dispatch( EventMessage(serv1, chan1, user1, "devoice test_user2 test_chan2")) data = serv1.get_send_data(1, chan1, EventMessage) assert "error" in data[0].text.lower() assert "i'm not in that channel" in data[0].text.lower() finally: hallo.remove_server(serv1)
def test_server_prefix_inherit_none(self): # Set up self.server.prefix = None self.hallo.default_prefix = "" # Run command self.function_dispatcher.dispatch( EventMessage( self.server, self.test_chan, self.test_user, "connect irc www.example.com:80", ) ) # Ensure correct response data = self.server.get_send_data(1, self.test_chan, EventMessage) assert ( "connected to new irc server" in data[0].text.lower() ), "Incorrect output: " + str(data[0].text) # Find the right server assert ( len(self.hallo.server_list) == 2 ), "Incorrect number of servers in hallo instance." right_server = None # type: ServerIRC for server in self.hallo.server_list: if server is not self.server: right_server = server assert right_server is not None, "New server wasn't found." assert right_server.prefix is None, "Prefix wasn't inherited as None"
def test_server_started(self): # Run command self.function_dispatcher.dispatch( EventMessage( self.server, self.test_chan, self.test_user, "connect irc www.example.com:80", ) ) # Ensure correct response data = self.server.get_send_data(1, self.test_chan, EventMessage) assert ( "connected to new irc server" in data[0].text.lower() ), "Incorrect output: " + str(data[0].text) # Find the right server assert ( len(self.hallo.server_list) == 2 ), "Incorrect number of servers in hallo instance." right_server = None # type: ServerIRC for server in self.hallo.server_list: if server is not self.server: right_server = server assert right_server is not None, "New server wasn't found." # Ensure new server is started assert right_server.state != Server.STATE_CLOSED, "New server was not started."
def test_devoice_1priv_not_known(hallo_getter): hallo, test_server, test_chan, test_user = hallo_getter( {"channel_control"}) serv1 = ServerMock(hallo) serv1.name = "test_serv1" serv1.type = Server.TYPE_IRC hallo.add_server(serv1) chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1") 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: hallo.function_dispatcher.dispatch( EventMessage(serv1, None, user1, "devoice other_channel")) data = serv1.get_send_data(1, user1, EventMessage) assert "error" in data[0].text.lower() assert "other_channel is not known" in data[0].text.lower() finally: hallo.remove_server(serv1)
def test_list_feeds(self): another_chan = self.server.get_channel_by_address("another_channel") # Get feed list rss_check_class = self.function_dispatcher.get_function_by_name( "check subscription") rss_check_obj = self.function_dispatcher.get_function_object( rss_check_class) # type: SubscriptionCheck rfl = rss_check_obj.get_sub_repo(self.hallo) # Add RSS feeds to feed list rf1 = E621Source("cabinet") sub1 = Subscription(self.server, self.test_chan, rf1, timedelta(days=1), None, None) rfl.add_sub(sub1) rf2 = E621Source("clefable") sub2 = Subscription(self.server, another_chan, rf2, timedelta(days=1), None, None) rfl.add_sub(sub2) rf3 = E621Source("fez") sub3 = Subscription(self.server, self.test_chan, rf3, timedelta(days=1), None, None) rfl.add_sub(sub3) # Run FeedList and check output self.function_dispatcher.dispatch( EventMessage(self.server, self.test_chan, self.test_user, "e621 sub list")) data = self.server.get_send_data(1, self.test_chan, EventMessage) data_split = data[0].text.split("\n") assert ("subscriptions posting" in data_split[0].lower() ), "Missing title. Response data: " + str(data[0].text) assert "cabinet" in data_split[1].lower( ) or "cabinet" in data_split[2].lower() assert ("clefable" not in data_split[1].lower() and "clefable" not in data_split[2].lower()) assert "fez" in data_split[1].lower() or "fez" in data_split[2].lower()
def test_thread_started(self): # Pre flight calc thread_count = threading.active_count() # Run command self.function_dispatcher.dispatch( EventMessage( self.server, self.test_chan, self.test_user, "connect irc www.example.com:80", ) ) # Ensure correct response data = self.server.get_send_data(1, self.test_chan, EventMessage) assert ( "connected to new irc server" in data[0].text.lower() ), "Incorrect output: " + str(data[0].text) # Find the right server assert ( len(self.hallo.server_list) == 2 ), "Incorrect number of servers in hallo instance." right_server = None # type: ServerIRC for server in self.hallo.server_list: if server is not self.server: right_server = server assert right_server is not None, "New server wasn't found." # Ensure thread count is up assert ( threading.active_count() == thread_count + 1 ), "Incorrect number of running threads."
def test_no_feeds(self): self.function_dispatcher.dispatch( EventMessage(self.server, self.test_chan, self.test_user, "e621 sub list")) data = self.server.get_send_data(1, self.test_chan, EventMessage) assert "no subscriptions" in data[0].text.lower( ), "Actual response: {}".format(data[0].text)
def test_remove_by_search(self): another_chan = self.server.get_channel_by_address("another_channel") # Get subscription list e621_check_class = self.function_dispatcher.get_function_by_name( "check subscription") e621_check_obj = self.function_dispatcher.get_function_object( e621_check_class) # type: SubscriptionCheck sub_repo = e621_check_obj.get_sub_repo(self.hallo) # Add E621 searches to subscription list rf1 = E621Source("cabinet") sub1 = Subscription(self.server, self.test_chan, rf1, timedelta(days=1), None, None) sub_repo.add_sub(sub1) rf2 = E621Source("clefable") sub2 = Subscription(self.server, another_chan, rf2, timedelta(days=1), None, None) sub_repo.add_sub(sub2) rf3 = E621Source("fez") sub3 = Subscription(self.server, self.test_chan, rf3, timedelta(days=1), None, None) sub_repo.add_sub(sub3) # Remove test search self.function_dispatcher.dispatch( EventMessage(self.server, self.test_chan, self.test_user, "e621 sub remove cabinet")) data = self.server.get_send_data(1, self.test_chan, EventMessage) assert "removed subscription" in data[0].text.lower() assert "e621" in data[0].text.lower() assert "\"cabinet\"" in data[0].text.lower() assert sub1 not in sub_repo.sub_list assert sub2 in sub_repo.sub_list assert sub3 in sub_repo.sub_list
def test_protein_simple(hallo_getter): hallo, test_server, test_chan, test_user = hallo_getter({"bio"}) hallo.function_dispatcher.dispatch( EventMessage(test_server, None, test_user, "protein ATTCATCGATCGCTA") ) data = test_server.get_send_data(1, test_user, EventMessage) assert "ile-his-arg-ser-leu" in data[0].text.lower(), "Protein construction failed."
def test_create_new_type_with_decimals(self): num_types = len(self.test_repo.type_list) self.function_dispatcher.dispatch( EventMessage( self.server, None, self.test_user, "convert add type new_type unit=unit2 decimals=5", )) data = self.server.get_send_data(1, self.test_user, EventMessage) assert ('created new type "new_type"' in data[0].text.lower()), "Should specify new type name" assert 'with base unit "unit2"' in data[ 0].text, "Should specify base unit" assert "and 5 decimal places" in data[ 0].text, "Didn't specify decimal places" assert len( self.test_repo.type_list) == num_types + 1, "Didn't add new type" new_type = self.test_repo.get_type_by_name("new_type") assert new_type is not None, "Can't find new type" assert new_type.base_unit is not None, "New type should have a base unit" assert len( new_type.base_unit.name_list) == 1, "Base unit should have 1 name" assert (new_type.base_unit.name_list[0] == "unit2" ), "Name should be in base unit name list" assert new_type.base_unit.value == 1, "Base unit should have value 1" assert new_type.decimals == 5, "Didn't correctly set decimals amount"
def test_inherit_port(self): # Set things up test_port = 80 test_serv_irc = ServerIRC(self.hallo) test_serv_irc.prefix = "" test_serv_irc.name = "test_serv_irc" test_serv_irc.server_port = test_port test_chan_irc = test_serv_irc.get_channel_by_address( "test_chan".lower(), "test_chan" ) test_user_irc = test_serv_irc.get_user_by_address( "test_user".lower(), "test_user" ) # Run command self.function_dispatcher.dispatch( EventMessage( test_serv_irc, test_chan_irc, test_user_irc, "connect irc example.com" ) ) # Can't check response because I'm using a ServerIRC instead of a ServerMock # Find the right server assert ( len(self.hallo.server_list) == 2 ), "Incorrect number of servers in hallo instance" right_server = None # type: ServerIRC for server in self.hallo.server_list: if server is not self.server: right_server = server assert right_server is not None, "New server wasn't found." assert right_server.server_port == test_port, "Port incorrect"
def test_inherit_user_groups_specify_nick(self): # Set up test_user = "******" test_user_group = UserGroup("test_group", self.hallo) self.test_user.add_user_group(test_user_group) # Run command self.function_dispatcher.dispatch( EventMessage( self.server, self.test_chan, self.test_user, "connect irc www.example.com:80 god=" + test_user, ) ) # Ensure correct response data = self.server.get_send_data(1, self.test_chan, EventMessage) assert ( "connected to new irc server" in data[0].text.lower() ), "Incorrect output: " + str(data[0].text) # Find the right server assert ( len(self.hallo.server_list) == 2 ), "Incorrect number of servers in hallo instance." right_server = None # type: ServerIRC for server in self.hallo.server_list: if server is not self.server: right_server = server assert right_server is not None, "New server wasn't found." # Check user groups new_user = right_server.get_user_by_address(test_user.lower(), test_user) assert test_user_group in new_user.user_group_list
def test_auto_connect_false(self): # Run command self.function_dispatcher.dispatch( EventMessage( self.server, self.test_chan, self.test_user, "connect irc www.example.com:80 auto_connect=false", ) ) # Ensure correct response data = self.server.get_send_data(1, self.test_chan, EventMessage) assert ( "connected to new irc server" in data[0].text.lower() ), "Incorrect output: " + str(data[0].text) # Find the right server assert ( len(self.hallo.server_list) == 2 ), "Incorrect number of servers in hallo instance." right_server = None # type: ServerIRC for server in self.hallo.server_list: if server is not self.server: right_server = server assert right_server is not None, "New server wasn't found." assert not right_server.auto_connect, "Auto connect didn't set to false"
def test_devoice_1_user(hallo_getter): hallo, test_server, test_chan, test_user = hallo_getter( {"channel_control"}) serv1 = ServerMock(hallo) serv1.name = "test_serv1" serv1.type = Server.TYPE_IRC 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 = True chan1.add_user(user2) chan1_user2 = chan1.get_membership_by_user(user2) chan1_user2.is_voice = True try: hallo.function_dispatcher.dispatch( EventMessage(serv1, chan1, user1, "devoice test_user2")) 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 "-v " + user2.name in data[0].mode_changes assert "status taken" in data[1].text.lower() finally: hallo.remove_server(serv1)
def test_nickserv_password_specify(self): # Set up test_nickserv_pass = "******" # Run command self.function_dispatcher.dispatch( EventMessage( self.server, self.test_chan, self.test_user, "connect irc www.example.com:80 nickserv_password="******"connected to new irc server" in data[0].text.lower() ), "Incorrect output: " + str(data[0].text) # Find the right server assert ( len(self.hallo.server_list) == 2 ), "Incorrect number of servers in hallo instance." right_server = None # type: ServerIRC for server in self.hallo.server_list: if server is not self.server: right_server = server assert right_server is not None, "New server wasn't found." assert ( right_server.nickserv_pass == test_nickserv_pass ), "Specified nickserv password wasn't set"
def test_passive_long_foof(self): self.roller.answer = 0 self.function_dispatcher.dispatch_passive( EventMessage(self.server, self.test_chan, self.test_user, "foooooooooooooooof")) data = self.server.get_send_data(1, self.test_chan, EventMessage) assert "doof" == data[0].text.lower(), "Should be short doof."
def run(self, event): line_clean = event.command_args.strip().lower() server_obj = event.server if line_clean == "": if event.channel is not None: server_obj.send( EventMessage(server_obj, event.channel, None, "*clap*", inbound=False)) time.sleep(0.5) server_obj.send( EventMessage(server_obj, event.channel, None, "*clap*", inbound=False)) time.sleep(2) return event.create_response("*clap.*") else: return event.create_response( "Error, you want me to slowclap yourself?") channel_obj = server_obj.get_channel_by_name(line_clean) if not channel_obj.in_channel: return event.create_response("Error, I'm not in that channel.") server_obj.send( EventMessage(server_obj, channel_obj, None, "*clap*", inbound=False)) time.sleep(0.5) server_obj.send( EventMessage(server_obj, channel_obj, None, "*clap*", inbound=False)) time.sleep(2) server_obj.send( EventMessage(server_obj, channel_obj, None, "*clap.*", inbound=False)) return event.create_response("done. :)")
def test_factors_float(hallo_getter): hallo, test_server, test_channel, test_user = hallo_getter({"math"}) hallo.function_dispatcher.dispatch( EventMessage(test_server, None, test_user, "fraction 17.5/2")) data = test_server.get_send_data(1, test_user, EventMessage) assert ("error" in data[0].text.lower() ), "Simplify fraction should return error when given a float." hallo.function_dispatcher.dispatch( EventMessage(test_server, None, test_user, "fraction 17/2.2")) data = test_server.get_send_data(1, test_user, EventMessage) assert ("error" in data[0].text.lower() ), "Simplify fraction should return error when given a float." hallo.function_dispatcher.dispatch( EventMessage(test_server, None, test_user, "fraction 6.6/2.2")) data = test_server.get_send_data(1, test_user, EventMessage) assert ("error" in data[0].text.lower() ), "Simplify fraction should return error when given a float."
def test_fraction_integer(hallo_getter): hallo, test_server, test_channel, test_user = hallo_getter({"math"}) hallo.function_dispatcher.dispatch( EventMessage(test_server, None, test_user, "fraction 22/2")) data = test_server.get_send_data(1, test_user, EventMessage) assert ( " 11." == data[0].text[-4:] ), "Simplify fraction should return integer when result is integer."
def test_fraction_complex(hallo_getter): hallo, test_server, test_channel, test_user = hallo_getter({"math"}) hallo.function_dispatcher.dispatch( EventMessage(test_server, None, test_user, "fraction 360679/22")) data = test_server.get_send_data(1, test_user, EventMessage) assert ( "32789/2." in data[0].text[-8:]), "Simplify fraction fails for large fractions."
def test_threads_simple(hallo_getter): hallo, test_server, test_channel, test_user = hallo_getter( {"hallo_control"}) hallo.function_dispatcher.dispatch( EventMessage(test_server, None, test_user, "active threads")) data = test_server.get_send_data(1, test_user, EventMessage) assert "i have" in data[0].text.lower() assert "active threads" in data[0].text.lower()
def test_number_european(hallo_getter): hallo, test_server, test_channel, test_user = hallo_getter({"math"}) hallo.function_dispatcher.dispatch( EventMessage(test_server, None, test_user, "number 1000000000 european")) data = test_server.get_send_data(1, test_user, EventMessage) assert ("one milliard." == data[0].text.lower() ), "Number word failing for european formatting."
def test_number_british(hallo_getter): hallo, test_server, test_channel, test_user = hallo_getter({"math"}) hallo.function_dispatcher.dispatch( EventMessage(test_server, None, test_user, "number 1000000000 british")) data = test_server.get_send_data(1, test_user, EventMessage) assert ("one thousand million." == data[0].text.lower() ), "Number word failing for british formatting."
def test_number_big(hallo_getter): hallo, test_server, test_channel, test_user = hallo_getter({"math"}) hallo.function_dispatcher.dispatch( EventMessage(test_server, None, test_user, "number 295228")) data = test_server.get_send_data(1, test_user, EventMessage) assert ( "two hundred and ninety-five thousand, two hundred and twenty-eight." == data[0].text.lower())
def test_long_simple(hallo_getter): hallo, test_server, test_chan, test_user = hallo_getter({"ascii_art"}) hallo.function_dispatcher.dispatch( EventMessage(test_server, None, test_user, "longcat") ) data = test_server.get_send_data() assert "error" not in data[0].text, "Longcat output should not produce errors." assert "\n" in data[0].text, "Longcat output should be multiple lines."
def test_logs_toggle(hallo_getter): hallo, test_server, test_chan, test_user = hallo_getter( {"channel_control"}) test_chan.logging = False hallo.function_dispatcher.dispatch( EventMessage(test_server, test_chan, test_user, "channel logging")) data = test_server.get_send_data(1, test_chan, EventMessage) assert "error" not in data[0].text.lower() assert "toggle" in data[0].text.lower() assert test_chan.logging # Try toggling again hallo.function_dispatcher.dispatch( EventMessage(test_server, test_chan, test_user, "channel logging")) data = test_server.get_send_data(1, test_chan, EventMessage) assert "error" not in data[0].text.lower() assert "toggle" in data[0].text.lower() assert not test_chan.logging