本文整理汇总了Python中b3.fake.FakeClient.sendsPM方法的典型用法代码示例。如果您正苦于以下问题:Python FakeClient.sendsPM方法的具体用法?Python FakeClient.sendsPM怎么用?Python FakeClient.sendsPM使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类b3.fake.FakeClient
的用法示例。
在下文中一共展示了FakeClient.sendsPM方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Test_mysql
# 需要导入模块: from b3.fake import FakeClient [as 别名]
# 或者: from b3.fake.FakeClient import sendsPM [as 别名]
#.........这里部分代码省略.........
self.joe.says2team("hi")
# THEN
self.assertEqual(1, self.count_chatlog_lines())
self.assertEqual(0, self.count_cmdlog_lines())
self.assertDictEqual({'client_id': self.joe.id,
'client_name': 'Joe',
'client_team': self.joe.team,
'msg': 'hi',
'msg_type': 'TEAM',
'target_id': None,
'target_name': None,
'target_team': None},
self.get_all_chatlog_lines_from_db()[0])
@unittest.skipUnless(hasattr(FakeClient, "says2squad"), "FakeClient.says2squad not available in this version of B3")
def test_squad_chat_gets_saved_to_db(self):
# WHEN
self.joe.says2squad("hi")
# THEN
self.assertEqual(1, self.count_chatlog_lines())
self.assertEqual(0, self.count_cmdlog_lines())
self.assertDictEqual({'client_id': self.joe.id,
'client_name': 'Joe',
'client_team': self.joe.team,
'msg': 'hi',
'msg_type': 'SQUAD',
'target_id': None,
'target_name': None,
'target_team': None},
self.get_all_chatlog_lines_from_db()[0])
def test_private_chat_gets_saved_to_db(self):
# WHEN
self.joe.sendsPM("hi", self.simon)
# THEN
self.assertEqual(1, self.count_chatlog_lines())
self.assertEqual(0, self.count_cmdlog_lines())
self.assertDictEqual({'client_id': self.joe.id,
'client_name': 'Joe',
'client_team': self.joe.team,
'msg': 'hi',
'msg_type': 'PM',
'target_id': self.simon.id,
'target_name': "Simon",
'target_team': self.simon.team},
self.get_all_chatlog_lines_from_db()[0])
def test_command_gets_saved_to_db(self):
# WHEN
self.joe.says("!help")
# THEN
self.assertEqual(1, self.count_chatlog_lines())
self.assertEqual(1, self.count_cmdlog_lines())
self.assertDictEqual({'client_id': self.joe.id,
'client_name': 'Joe',
'client_team': self.joe.team,
'msg': '!help',
'msg_type': 'ALL',
'target_id': None,
'target_name': None,
'target_team': None},
self.get_all_chatlog_lines_from_db()[0])
self.assertDictEqual({'admin_id': 1,
'admin_name': 'Joe',
'command': 'help',
'data': '',
示例2: Test_chatlogfile
# 需要导入模块: from b3.fake import FakeClient [as 别名]
# 或者: from b3.fake.FakeClient import sendsPM [as 别名]
class Test_chatlogfile(ChatloggerTestCase):
def setUp(self):
ChatloggerTestCase.setUp(self)
with logging_disabled():
self.console.startup()
self.conf = CfgConfigParser()
self.p = ChatloggerPlugin(self.console, self.conf)
when(self.console.config).get('b3', 'time_zone').thenReturn('GMT')
self.conf.loadFromString(dedent("""
[general]
save_to_database: no
save_to_file: yes
[file]
logfile: @conf/chat.log
rotation_rate: D
[purge]
max_age: 0
hour: 0
min: 0
"""))
self.temp_conf_folder = mkdtemp(suffix="b3_conf")
when(b3).getConfPath(decode=ANY, conf=None).thenReturn(self.temp_conf_folder)
with logging_disabled():
self.p.onLoadConfig()
self.p.onStartup()
self.chat_log_file = os.path.join(self.temp_conf_folder, 'chat.log')
with logging_disabled():
self.joe = FakeClient(self.console, name="Joe", guid="joe_guid", team=TEAM_RED)
self.simon = FakeClient(self.console, name="Simon", guid="simon_guid", team=TEAM_BLUE)
self.joe.connects(1)
self.simon.connects(3)
def get_all_chatlog_lines_from_logfile(self):
lines = []
with codecs.open(self.chat_log_file, "r", encoding="utf-8") as f:
for l in f.readlines():
lines.append(l.strip())
return lines
def count_chatlog_lines(self):
return len(self.get_all_chatlog_lines_from_logfile())
def assert_log_line(self, line, expected):
"""
remove time stamp at the beginning of the line and compare the remainder
"""
clean_line = re.sub(r"^\d+-\d+-\d+ \d\d:\d\d:\d\d\t", "", line)
self.assertEqual(clean_line, expected)
def test_global_chat(self):
# WHEN
self.joe.says("hello")
# THEN
self.assertEqual(1, self.count_chatlog_lines())
self.assert_log_line(self.get_all_chatlog_lines_from_logfile()[0], "@1 [Joe] to ALL:\thello")
def test_team_chat(self):
# WHEN
self.joe.says2team("hello")
# THEN
self.assertEqual(1, self.count_chatlog_lines())
self.assert_log_line(self.get_all_chatlog_lines_from_logfile()[0], "@1 [Joe] to TEAM:\thello")
def test_squad_chat(self):
# WHEN
self.joe.says2squad("hi")
# THEN
self.assertEqual(1, self.count_chatlog_lines())
self.assert_log_line(self.get_all_chatlog_lines_from_logfile()[0], "@1 [Joe] to SQUAD:\thi")
def test_private_chat(self):
# WHEN
self.joe.sendsPM("hi", self.simon)
# THEN
self.assertEqual(1, self.count_chatlog_lines())
self.assert_log_line(self.get_all_chatlog_lines_from_logfile()[0], "@1 [Joe] to PM:\thi")
def test_unicode(self):
# WHEN
self.joe.name = u"★joe★"
self.simon.name = u"❮❮simon❯❯"
self.joe.sendsPM(u"hi ✪", self.simon)
# THEN
self.assertEqual(1, self.count_chatlog_lines())
self.assert_log_line(self.get_all_chatlog_lines_from_logfile()[0], u"@1 [★joe★] to PM:\thi ✪")