本文整理汇总了Python中b3.fake.FakeClient.isvar方法的典型用法代码示例。如果您正苦于以下问题:Python FakeClient.isvar方法的具体用法?Python FakeClient.isvar怎么用?Python FakeClient.isvar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类b3.fake.FakeClient
的用法示例。
在下文中一共展示了FakeClient.isvar方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Test_events
# 需要导入模块: from b3.fake import FakeClient [as 别名]
# 或者: from b3.fake.FakeClient import isvar [as 别名]
class Test_events(JumperTestCase):
def setUp(self):
JumperTestCase.setUp(self)
with logging_disabled():
from b3.fake import FakeClient
# create some clients
self.mike = FakeClient(console=self.console, name="Mike", guid="mikeguid", team=TEAM_FREE, groupBits=1)
self.bill = FakeClient(console=self.console, name="Bill", guid="billguid", team=TEAM_FREE, groupBits=1)
self.mike.connects("1")
self.bill.connects("2")
# force fake mapname
self.console.game.mapName = 'ut42_bstjumps_u2'
def tearDown(self):
self.mike.disconnects()
self.bill.disconnects()
JumperTestCase.tearDown(self)
####################################################################################################################
# #
# JUMPRUN EVENTS #
# #
####################################################################################################################
def test_event_client_jumprun_started(self):
# WHEN
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_START', client=self.mike, data={'way_id' : '1'}))
# THEN
self.assertEqual(True, self.mike.isvar(self.p, 'jumprun'))
self.assertIsNone(self.mike.var(self.p, 'jumprun').value.demo)
self.assertIsInstance(self.mike.var(self.p, 'jumprun').value, JumpRun)
def test_event_client_jumprun_stopped(self):
# WHEN
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_STOP', client=self.mike, data={'way_id' : '1', 'way_time' : '12345'}))
# THEN
self.assertEqual(False, self.mike.isvar(self.p, 'jumprun'))
self.assertListEqual([], self.p.getClientRecords(self.mike, self.console.game.mapName))
def test_event_client_jumprun_canceled(self):
# WHEN
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_CANCEL', client=self.mike, data={'way_id' : '1'}))
# THEN
self.assertEqual(False, self.mike.isvar(self.p, 'jumprun'))
self.assertListEqual([], self.p.getClientRecords(self.mike, self.console.game.mapName))
def test_event_client_jumprun_started_stopped(self):
# WHEN
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_START', client=self.mike, data={'way_id' : '1'}))
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_STOP', client=self.mike, data={'way_id' : '1', 'way_time' : '12345'}))
# THEN
self.assertEqual(False, self.mike.isvar(self.p, 'jumprun'))
self.assertEqual(1, len(self.p.getClientRecords(self.mike, self.console.game.mapName)))
def test_event_client_jumprun_started_canceled(self):
# WHEN
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_START', client=self.mike, data={'way_id' : '1'}))
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_CANCEL', client=self.mike, data={'way_id' : '1'}))
# THEN
self.assertEqual(False, self.mike.isvar(self.p, 'jumprun'))
self.assertEqual(0, len(self.p.getClientRecords(self.mike, self.console.game.mapName)))
def test_event_client_jumprun_started_stopped_multiple_clients(self):
# WHEN
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_START', client=self.mike, data={'way_id' : '1'}))
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_STOP', client=self.mike, data={'way_id' : '1', 'way_time' : '12345'}))
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_START', client=self.bill, data={'way_id' : '1'}))
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_STOP', client=self.bill, data={'way_id' : '1', 'way_time' : '12345'}))
# THEN
self.assertEqual(False, self.mike.isvar(self.p, 'jumprun'))
self.assertEqual(False, self.bill.isvar(self.p, 'jumprun'))
self.assertEqual(1, len(self.p.getClientRecords(self.mike, self.console.game.mapName)))
self.assertEqual(1, len(self.p.getClientRecords(self.bill, self.console.game.mapName)))
def test_event_client_jumprun_started_stopped_multiple_ways(self):
# WHEN
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_START', client=self.mike, data={'way_id' : '1'}))
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_STOP', client=self.mike, data={'way_id' : '1', 'way_time' : '12345'}))
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_START', client=self.mike, data={'way_id' : '2'}))
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_STOP', client=self.mike, data={'way_id' : '2', 'way_time' : '12345'}))
# THEN
self.assertEqual(False, self.mike.isvar(self.p, 'jumprun'))
self.assertEqual(2, len(self.p.getClientRecords(self.mike, self.console.game.mapName)))
def test_event_client_jumprun_started_stopped_multiple_clients_multiple_ways(self):
# WHEN
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_START', client=self.mike, data={'way_id' : '1'}))
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_STOP', client=self.mike, data={'way_id' : '1', 'way_time' : '12345'}))
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_START', client=self.mike, data={'way_id' : '2'}))
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_STOP', client=self.mike, data={'way_id' : '2', 'way_time' : '12345'}))
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_START', client=self.bill, data={'way_id' : '1'}))
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_STOP', client=self.bill, data={'way_id' : '1', 'way_time' : '12345'}))
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_START', client=self.bill, data={'way_id' : '2'}))
self.console.queueEvent(self.console.getEvent('EVT_CLIENT_JUMP_RUN_STOP', client=self.bill, data={'way_id' : '2', 'way_time' : '12345'}))
# THEN
self.assertEqual(False, self.mike.isvar(self.p, 'jumprun'))
self.assertEqual(False, self.bill.isvar(self.p, 'jumprun'))
#.........这里部分代码省略.........
示例2: Test_cmd_login
# 需要导入模块: from b3.fake import FakeClient [as 别名]
# 或者: from b3.fake.FakeClient import isvar [as 别名]
class Test_cmd_login(LoginTestCase):
def setUp(self):
LoginTestCase.setUp(self)
self.init_plugin()
# create a client which needs to log in and has a password saved in database
self.jack = FakeClient(self.console, name="Jack", guid="jackguid", groupBits=128, password=F00_MD5)
self.jack.save()
def test_already_logged_in(self):
# GIVEN
joe = FakeClient(self.console, name="Joe", guid="joeguid", groupBits=128)
joe.setvar(self.p, 'loggedin', 1)
joe.connects("0")
# WHEN
joe.clearMessageHistory()
joe.says("!login")
# THEN
self.assertEqual(['You are already logged in'], joe.message_history)
def test_low_level(self):
# GIVEN
joe = FakeClient(self.console, name="Joe", guid="joeguid", groupBits=8)
joe.connects("0")
# WHEN
joe.clearMessageHistory()
joe.says("!login")
# THEN
self.assertEqual(['You do not need to log in'], joe.message_history)
self.assertFalse(self.jack.isvar(self.p, 'loggedin'))
def test_high_level_no_parameter(self):
# GIVEN
self.jack.connects("0")
self.assertEqual(2, self.jack.groupBits) # the login plugin set his level down to 2 while waiting for the password
# WHEN
self.jack.clearMessageHistory()
self.jack.says("!login")
# THEN
self.assertEqual(['Usage (via console): /tell 0 !login yourpassword'], self.jack.message_history)
self.assertEqual(2, self.jack.groupBits)
self.assertFalse(self.jack.isvar(self.p, 'loggedin'))
def test_high_level_wrong_password(self):
# GIVEN
self.jack.connects("0")
self.assertEqual(2, self.jack.groupBits) # the login plugin set his level down to 2 while waiting for the password
# WHEN
self.jack.clearMessageHistory()
self.jack.says("!login qsfddqsf")
# THEN
self.assertEqual(['***Access denied***'], self.jack.message_history)
self.assertEqual(2, self.jack.groupBits)
self.assertFalse(self.jack.isvar(self.p, 'loggedin'))
def test_high_level_correct_password(self):
# GIVEN
self.jack.connects("0")
self.assertEqual(2, self.jack.groupBits) # the login plugin set his level down to 2 while waiting for the password
# WHEN
self.jack.clearMessageHistory()
self.jack.says("!login f00")
# THEN
self.assertEqual(['You are successfully logged in'], self.jack.message_history)
self.assertEqual(128, self.jack.groupBits)
self.assertTrue(self.jack.isvar(self.p, 'loggedin'))
def test_high_level_spoofed_password_with_compromised_client_object(self):
"""
in some B3 game parser implementation there is an issue which could let the 'password' property of client
objects be compromised.
"""
# GIVEN
batman_md5 = 'ec0e2603172c73a8b644bb9456c1ff6e'
self.jack.connects("0")
self.assertEqual(2, self.jack.groupBits) # the login plugin set his level down to 2 while waiting for the password
self.jack.password = batman_md5
# WHEN
self.jack.clearMessageHistory()
self.jack.says("!login batman")
# THEN
self.assertEqual(['***Access denied***'], self.jack.message_history)
self.assertEqual(2, self.jack.groupBits)
self.assertFalse(self.jack.isvar(self.p, 'loggedin'))
def test_high_level_correct_password_with_compromised_client_object(self):
"""
in some B3 game parser implementation there is an issue which could let the 'password' property of client
objects be compromised.
"""
# GIVEN
batman_md5 = 'ec0e2603172c73a8b644bb9456c1ff6e'
self.jack.connects("0")
self.assertEqual(2, self.jack.groupBits) # the login plugin set his level down to 2 while waiting for the password
self.jack.password = batman_md5
# WHEN
self.jack.clearMessageHistory()
self.jack.says("!login f00")
# THEN
self.assertEqual(['You are successfully logged in'], self.jack.message_history)
#.........这里部分代码省略.........
示例3: Test_events
# 需要导入模块: from b3.fake import FakeClient [as 别名]
# 或者: from b3.fake.FakeClient import isvar [as 别名]
class Test_events(JumperTestCase):
def setUp(self):
JumperTestCase.setUp(self)
with logging_disabled():
from b3.fake import FakeClient
# prevent the test to query the api: we handle this somewhere else
when(self.p).getMapsData().thenReturn(dict())
# create some clients
self.mike = FakeClient(console=self.console, name="Mike", guid="mikeguid", team=TEAM_FREE, groupBits=1)
self.bill = FakeClient(console=self.console, name="Bill", guid="billguid", team=TEAM_FREE, groupBits=1)
self.mike.connects("1")
self.bill.connects("2")
# force fake mapname
self.console.game.mapName = 'ut42_bstjumps_u2'
def tearDown(self):
self.mike.disconnects()
self.bill.disconnects()
JumperTestCase.tearDown(self)
####################################################################################################################
## ##
## JUMPRUN EVENTS ##
## ##
####################################################################################################################
def test_event_client_jumprun_started(self):
# WHEN
event = self.console.getEventID('EVT_CLIENT_JUMP_RUN_START')
self.console.queueEvent(Event(event, client=self.mike, data={'way_id' : '1'}))
# THEN
self.assertEqual(True, self.mike.isvar(self.p, 'jumprun'))
self.assertIsNone(self.mike.var(self.p, 'jumprun').value.demo)
self.assertIsInstance(self.mike.var(self.p, 'jumprun').value, JumpRun)
def test_event_client_jumprun_stopped(self):
# WHEN
event = self.console.getEventID('EVT_CLIENT_JUMP_RUN_STOP')
self.console.queueEvent(Event(event, client=self.mike, data={'way_id' : '1', 'way_time' : '12345'}))
# THEN
self.assertEqual(False, self.mike.isvar(self.p, 'jumprun'))
self.assertListEqual([], self.p.getClientRecords(self.mike, self.console.game.mapName))
def test_event_client_jumprun_canceled(self):
# WHEN
event = self.console.getEventID('EVT_CLIENT_JUMP_RUN_CANCEL')
self.console.queueEvent(Event(event, client=self.mike, data={'way_id' : '1'}))
# THEN
self.assertEqual(False, self.mike.isvar(self.p, 'jumprun'))
self.assertListEqual([], self.p.getClientRecords(self.mike, self.console.game.mapName))
def test_event_client_jumprun_started_stopped(self):
# WHEN
event1 = self.console.getEventID('EVT_CLIENT_JUMP_RUN_START')
event2 = self.console.getEventID('EVT_CLIENT_JUMP_RUN_STOP')
self.console.queueEvent(Event(event1, client=self.mike, data={'way_id' : '1'}))
self.console.queueEvent(Event(event2, client=self.mike, data={'way_id' : '1', 'way_time' : '12345'}))
# THEN
self.assertEqual(False, self.mike.isvar(self.p, 'jumprun'))
self.assertEqual(1, len(self.p.getClientRecords(self.mike, self.console.game.mapName)))
def test_event_client_jumprun_started_canceled(self):
# WHEN
event1 = self.console.getEventID('EVT_CLIENT_JUMP_RUN_START')
event2 = self.console.getEventID('EVT_CLIENT_JUMP_RUN_CANCEL')
self.console.queueEvent(Event(event1, client=self.mike, data={'way_id' : '1'}))
self.console.queueEvent(Event(event2, client=self.mike, data={'way_id' : '1'}))
# THEN
self.assertEqual(False, self.mike.isvar(self.p, 'jumprun'))
self.assertEqual(0, len(self.p.getClientRecords(self.mike, self.console.game.mapName)))
def test_event_client_jumprun_started_stopped_multiple_clients(self):
# WHEN
event1 = self.console.getEventID('EVT_CLIENT_JUMP_RUN_START')
event2 = self.console.getEventID('EVT_CLIENT_JUMP_RUN_STOP')
self.console.queueEvent(Event(event1, client=self.mike, data={'way_id' : '1'}))
self.console.queueEvent(Event(event2, client=self.mike, data={'way_id' : '1', 'way_time' : '12345'}))
self.console.queueEvent(Event(event1, client=self.bill, data={'way_id' : '1'}))
self.console.queueEvent(Event(event2, client=self.bill, data={'way_id' : '1', 'way_time' : '12345'}))
# THEN
self.assertEqual(False, self.mike.isvar(self.p, 'jumprun'))
self.assertEqual(False, self.bill.isvar(self.p, 'jumprun'))
self.assertEqual(1, len(self.p.getClientRecords(self.mike, self.console.game.mapName)))
self.assertEqual(1, len(self.p.getClientRecords(self.bill, self.console.game.mapName)))
def test_event_client_jumprun_started_stopped_multiple_ways(self):
# WHEN
event1 = self.console.getEventID('EVT_CLIENT_JUMP_RUN_START')
event2 = self.console.getEventID('EVT_CLIENT_JUMP_RUN_STOP')
self.console.queueEvent(Event(event1, client=self.mike, data={'way_id' : '1'}))
self.console.queueEvent(Event(event2, client=self.mike, data={'way_id' : '1', 'way_time' : '12345'}))
self.console.queueEvent(Event(event1, client=self.mike, data={'way_id' : '2'}))
self.console.queueEvent(Event(event2, client=self.mike, data={'way_id' : '2', 'way_time' : '12345'}))
# THEN
#.........这里部分代码省略.........