本文整理汇总了Python中b3.clients.Client类的典型用法代码示例。如果您正苦于以下问题:Python Client类的具体用法?Python Client怎么用?Python Client使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_auth_client_without_guid_but_with_known_pbid
def test_auth_client_without_guid_but_with_known_pbid(self):
# GIVEN
# known superadmin named Snoopy
superadmin = Client(console=self.parser, name='Snoopy', guid='EA_AAAAAAAABBBBBBBBBBBBBB00000000000012222', pbid='300000aaaaaabbbbbbccccc111223300', group_bits=128, connections=21)
superadmin.save()
# bf3 server failing to provide guid
def write(data):
if data == ('admin.listPlayers', 'player', 'Snoopy'):
return ['7', 'name', 'guid', 'teamId', 'squadId', 'kills', 'deaths', 'score', '1', 'Snoopy', '', '2', '8', '0', '0', '0']
else:
return DEFAULT
self.write_mock.side_effect = write
# WHEN
self.assertFalse('Snoopy' in self.parser.clients)
self.parser.OnPBPlayerGuid(match=re.match(self.regex_for_OnPBPlistItem, self.event_raw_data), data=self.event_raw_data)
# THEN
# B3 should have authed Snoopy
self.assertTrue('Snoopy' in self.parser.clients)
snoopy = self.parser.clients['Snoopy']
self.assertTrue(snoopy.authed)
for attb in ('name', 'pbid', 'guid', 'groupBits'):
self.assertEqual(getattr(superadmin, attb), getattr(snoopy, attb))
示例2: test_name_change
def test_name_change(self):
c = Client(console=b3.console, authed=True)
c.name = "cucurb"
self.assertEqual(c.name, "cucurb")
b3.console.queueEvent.assert_called()
args = b3.console.queueEvent.call_args
eventraised = args[0][0]
self.assertEquals(eventraised.type, b3.events.EVT_CLIENT_NAME_CHANGE)
self.assertEquals(eventraised.data, 'cucurb')
示例3: test_team_change
def test_team_change(self):
b3.console = Mock()
c = Client(console=b3.console)
c.team = 24
self.assertEqual(c.team, 24)
b3.console.queueEvent.assert_called()
args = b3.console.queueEvent.call_args
eventraised = args[0][0]
self.assertEquals(eventraised.type, b3.events.EVT_CLIENT_TEAM_CHANGE)
self.assertEquals(eventraised.data, 24)
示例4: test_one_ban_with_reason
def test_one_ban_with_reason(self):
# GIVEN
player1 = Client(console=self.console, guid='BillGUID', name="Bill")
player1.save()
penalty1 = ClientBan(clientId=player1.id, timeExpire=-1, adminId=0, reason="test reason")
when(self.console.storage).getLastPenalties(types=whatever(), num=whatever()).thenReturn([penalty1])
# WHEN
self.lastbans()
# THEN
self.mock_command.sayLoudOrPM.assert_called_once_with(self.player, u'^[email protected]^7 Bill^7^7 (Perm) test reason')
示例5: test_makeAlias_new
def test_makeAlias_new(self):
c = Client(console=b3.console)
c.id = 123
c.name = "foo"
b3.console.storage.getClientAlias.side_effect = KeyError()
c.makeAlias("bar")
self.assertEquals(b3.console.storage.getClientAlias.call_count, 1)
alias = b3.console.storage.getClientAlias.call_args[0][0]
self.assertIsInstance(alias, b3.clients.Alias)
self.assertEqual(alias.alias, "bar")
self.assertEqual(alias.numUsed, 1)
示例6: test_makeAlias_existing
def test_makeAlias_existing(self):
c = Client(console=b3.console)
c.id = 123
c.name = "foo"
aliasFoo = b3.clients.Alias()
aliasFoo.alias = "foo"
aliasFoo.clientId = c.id
aliasFoo.numUsed = 48
b3.console.storage.getClientAlias.side_effect = lambda x: aliasFoo
c.makeAlias("whatever")
self.assertEquals(b3.console.storage.getClientAlias.call_count, 1)
self.assertIsInstance(aliasFoo, b3.clients.Alias)
self.assertEqual(aliasFoo.alias, "foo")
self.assertEqual(aliasFoo.numUsed, 49)
示例7: setUp
def setUp(self):
B3TestCase.setUp(self)
self.queueEvent_patcher = patch.object(self.console, 'queueEvent')
self.queueEvent_mock = self.queueEvent_patcher.start()
self.admin = Client(console=self.console)
self.client = Client(console=self.console)
self.client.save()
示例8: test_known_client_by_cid
def test_known_client_by_cid(self):
# GIVEN
known_client = Client(console=self.parser, guid="AAAAAAAAAAAA000000000000000", name="theName")
known_client.save()
self.assertEqual(1, len(self.parser.clients))
self.assertDictContainsSubset({'clients': 2}, self.parser.storage.getCounts())
# WHEN
client = self.parser.getClientOrCreate(cid="2", guid="AAAAAAAAAAAA000000000000000", name="newName", team="CT")
# THEN
self.assertIsInstance(client, Client)
self.assertEqual(known_client.id, client.id)
self.assertEqual("2", client.cid)
self.assertEqual("AAAAAAAAAAAA000000000000000", client.guid)
self.assertEqual("newName", client.name)
self.assertEqual(TEAM_RED, client.team)
self.assertTrue(client.authed)
self.assertEqual(2, len(self.parser.clients))
self.assertDictContainsSubset({'clients': 2}, self.parser.storage.getCounts())
示例9: test_known_client__guid
def test_known_client__guid(self):
# GIVEN
known_client = Client(console=self.parser, guid="12312312312312312", name="courgette", connections=15)
known_client.save()
self.assertEqual(1, len(self.parser.clients))
self.assertDictContainsSubset({'clients': 2}, self.parser.storage.getCounts())
# WHEN
client = self.parser.getClientOrCreate(guid="12312312312312312", name="newName", team="0")
# THEN
self.assertIsInstance(client, Client)
self.assertEqual(known_client.id, client.id)
self.assertEqual("12312312312312312", client.cid)
self.assertEqual("12312312312312312", client.guid)
self.assertEqual("newName", client.name)
self.assertEqual(TEAM_SCAVENGERS, client.team)
self.assertEqual(16, client.connections)
self.assertTrue(client.authed)
self.assertEqual(2, len(self.parser.clients))
self.assertDictContainsSubset({'clients': 2}, self.parser.storage.getCounts())
示例10: Test_Client_events
class Test_Client_events(B3TestCase):
def setUp(self):
B3TestCase.setUp(self)
self.queueEvent_patcher = patch.object(self.console, 'queueEvent')
self.queueEvent_mock = self.queueEvent_patcher.start()
self.admin = Client(console=self.console)
self.client = Client(console=self.console)
self.client.save()
def tearDown(self):
B3TestCase.tearDown(self)
self.queueEvent_patcher.stop()
def test_warn(self):
with self.assertRaiseEvent(event_type="EVT_CLIENT_WARN", event_client=self.client, event_data={
'reason': 'insulting admin',
'duration': 5*60,
'data': 'foobar',
'admin': self.admin,
'timeExpire': ANY
}, event_target=None):
self.client.warn(duration='5h', warning='insulting admin', keyword=None, admin=self.admin, data='foobar')
def test_notice(self):
with self.assertRaiseEvent(event_type="EVT_CLIENT_NOTICE", event_client=self.client, event_data={
'notice': "keep a eye on this guy",
'admin': self.admin,
'timeAdd': ANY
}):
self.client.notice(notice="keep a eye on this guy", spare=None, admin=self.admin)
示例11: test_guid_readonly
def test_guid_readonly(self):
c = Client(console=b3.console)
self.assertFalse(c.authed)
c.guid = "foo"
self.assertEqual(c.guid, "foo")
c.auth()
self.assertTrue(c.authed)
# upon guid change, prevent change and consider client not
# authed anymore
c.guid = "bar"
self.assertFalse(c.authed)
c.guid = "foo"
示例12: test_two_bans_with_reason
def test_two_bans_with_reason(self):
# GIVEN
when(self.console).time().thenReturn(0)
player1 = Client(console=self.console, guid='player1GUID', name="P1")
player1.save()
penalty1 = ClientBan(clientId=player1.id, timeExpire=-1, adminId=0, reason="test reason")
player2 = Client(console=self.console, guid='player2GUID', name="P2")
player2.save()
penalty2 = ClientTempBan(clientId=player2.id, timeExpire=self.console.time() + 60*2, adminId=0, reason="test reason f00")
when(self.console.storage).getLastPenalties(types=whatever(), num=whatever()).thenReturn([penalty1, penalty2])
# WHEN
self.lastbans()
# THEN
self.mock_command.sayLoudOrPM.assert_has_calls([
call(self.player, u'^[email protected]^7 P1^7^7 (Perm) test reason'),
call(self.player, u'^[email protected]^7 P2^7^7 (2 minutes remaining) test reason f00'),
])
示例13: test_message
def test_message(self):
self.parser.msgPrefix = "[Pre]"
player = Client(console=self.parser, guid="theGuid")
with patch.object(self.parser.output, 'write') as write_mock:
player.message("f00")
write_mock.assert_has_calls([call('sm_psay #theGuid "[Pre] f00"')])
示例14: Test_Client
class Test_Client(B3TestCase):
def setUp(self):
B3TestCase.setUp(self)
self.client = Client(console=self.console)
def test_construct(self):
c = Client(name="Courgette", guid="1234567890")
self.assertEqual(c.name, "Courgette")
self.assertEqual(c.exactName, "Courgette^7")
self.assertEqual(c.guid, "1234567890")
self.assertEqual(c.team, TEAM_UNKNOWN)
self.assertTrue(c.connected)
self.assertFalse(c.hide)
self.assertEqual(c.ip, '')
self.assertEqual(c.greeting, '')
self.assertEqual(c.pbid, '')
def test_team(self):
m = Mock()
self.client.team = m
self.assertEqual(self.client.team, m)
def test_team_change(self):
self.console.queueEvent = Mock()
self.client.team = 24
self.assertEqual(self.client.team, 24)
self.console.queueEvent.assert_called()
args = self.console.queueEvent.call_args
eventraised = args[0][0]
self.assertEquals(eventraised.type, EVT_CLIENT_TEAM_CHANGE)
self.assertEquals(eventraised.data, 24)
def test_name_change(self):
self.console.queueEvent = Mock()
self.client.authed = True
self.client.name = "cucurb"
self.assertEqual(self.client.name, "cucurb")
self.console.queueEvent.assert_called()
args = self.console.queueEvent.call_args
eventraised = args[0][0]
self.assertEquals(eventraised.type, EVT_CLIENT_NAME_CHANGE)
self.assertEquals(eventraised.data, 'cucurb')
def test_makeAlias_new(self):
self.client.id = 123
self.console.storage.getClientAlias = Mock(side_effect = KeyError())
self.client.makeAlias("bar")
self.assertEquals(self.console.storage.getClientAlias.call_count, 1)
alias = self.console.storage.getClientAlias.call_args[0][0]
self.assertIsInstance(alias, Alias)
self.assertEqual(alias.alias, "bar")
self.assertEqual(alias.numUsed, 1)
def test_makeAlias_existing(self):
self.client.id = 123
aliasFoo = Alias()
aliasFoo.alias = "foo"
aliasFoo.clientId = self.client.id
aliasFoo.numUsed = 48
self.console.storage.getClientAlias = Mock(side_effect = lambda x: aliasFoo)
self.client.makeAlias("whatever")
self.assertEquals(self.console.storage.getClientAlias.call_count, 1)
self.assertIsInstance(aliasFoo, Alias)
self.assertEqual(aliasFoo.alias, "foo")
self.assertEqual(aliasFoo.numUsed, 49)
def test_guid_readonly(self):
self.assertFalse(self.client.authed)
self.client.guid = "foo"
self.assertEqual(self.client.guid, "foo")
self.client.auth()
self.assertTrue(self.client.authed)
# upon guid change, prevent change and consider client not
# authed anymore
self.client.guid = "bar"
self.assertFalse(self.client.authed)
self.client.guid = "foo"
def test_set_ip(self):
self.client.ip = "1.2.3.4"
self.assertEqual(self.client._ip, "1.2.3.4")
self.client.ip = "5.6.7.8:27960"
self.assertEqual(self.client._ip, "5.6.7.8")
def test_makeIpAlias_new(self):
self.client.id = 123
self.console.storage.getClientIpAddress = Mock(side_effect = KeyError())
self.client.makeIpAlias("1.4.7.8")
self.assertEquals(self.console.storage.getClientIpAddress.call_count, 1)
alias = self.console.storage.getClientIpAddress.call_args[0][0]
self.assertIsInstance(alias, IpAlias)
self.assertEqual(alias.ip, "1.4.7.8")
self.assertEqual(alias.numUsed, 1)
def test_makeIpAlias_existing(self):
self.client.id = 123
aliasFoo = IpAlias()
aliasFoo.ip = "9.5.4.4"
aliasFoo.clientId = self.client.id
#.........这里部分代码省略.........
示例15: setUp
def setUp(self):
B3TestCase.setUp(self)
self.client = Client(console=self.console)