當前位置: 首頁>>代碼示例>>Python>>正文


Python Client.makeIpAlias方法代碼示例

本文整理匯總了Python中b3.clients.Client.makeIpAlias方法的典型用法代碼示例。如果您正苦於以下問題:Python Client.makeIpAlias方法的具體用法?Python Client.makeIpAlias怎麽用?Python Client.makeIpAlias使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在b3.clients.Client的用法示例。


在下文中一共展示了Client.makeIpAlias方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Test_Client

# 需要導入模塊: from b3.clients import Client [as 別名]
# 或者: from b3.clients.Client import makeIpAlias [as 別名]
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
#.........這裏部分代碼省略.........
開發者ID:ozon,項目名稱:big-brother-bot,代碼行數:103,代碼來源:test_Client.py


注:本文中的b3.clients.Client.makeIpAlias方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。