本文整理汇总了Python中test.ServerMock.ServerMock类的典型用法代码示例。如果您正苦于以下问题:Python ServerMock类的具体用法?Python ServerMock怎么用?Python ServerMock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ServerMock类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_check_response
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"
开发者ID:,项目名称:,代码行数:32,代码来源:
示例2: test_1_user_group_no_name
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()
开发者ID:joshcoales,项目名称:Hallo,代码行数:27,代码来源:testPermissionControl.py
示例3: test_one_server
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]
开发者ID:joshcoales,项目名称:Hallo,代码行数:30,代码来源:testListServers.py
示例4: test_invite_2_user_user_already_there
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)
开发者ID:joshcoales,项目名称:Hallo,代码行数:31,代码来源:testInvite.py
示例5: test_invite_2_user
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)
开发者ID:joshcoales,项目名称:Hallo,代码行数:33,代码来源:testInvite.py
示例6: test_invite_1_chan_user_already_there
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)
开发者ID:,项目名称:,代码行数:31,代码来源:
示例7: test_invite_2_user
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)
开发者ID:,项目名称:,代码行数:34,代码来源:
示例8: test_op_1_user_no_power
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)
开发者ID:joshcoales,项目名称:Hallo,代码行数:26,代码来源:testOperator.py
示例9: test_mute_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)
开发者ID:joshcoales,项目名称:Hallo,代码行数:27,代码来源:testMute.py
示例10: test_run_by_title
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)
开发者ID:,项目名称:,代码行数:60,代码来源:
示例11: test_deop_2_user_not_op
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)
开发者ID:,项目名称:,代码行数:31,代码来源:
示例12: test_devoice_1priv
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)
开发者ID:joshcoales,项目名称:Hallo,代码行数:27,代码来源:testDeVoice.py
示例13: TestBase
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()
开发者ID:,项目名称:,代码行数:54,代码来源:
示例14: test_2_server_chan
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."
开发者ID:,项目名称:,代码行数:12,代码来源:
示例15: test_2_server_user
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."
开发者ID:joshcoales,项目名称:Hallo,代码行数:12,代码来源:testPermissionControl.py
示例16: test_run_by_title
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)
开发者ID:joshcoales,项目名称:Hallo,代码行数:52,代码来源:testSubscriptionCheckRss.py
示例17: test_mute_privmsg
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)
开发者ID:joshcoales,项目名称:Hallo,代码行数:13,代码来源:testMute.py
示例18: test_mute_privmsg
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)
开发者ID:,项目名称:,代码行数:13,代码来源:
示例19: test_run_by_search
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)
开发者ID:,项目名称:,代码行数:56,代码来源:
示例20: test_deop_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)
开发者ID:,项目名称:,代码行数:28,代码来源:
注:本文中的test.ServerMock.ServerMock类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论