3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-02-25 01:40:38 +01:00

Fixes to clientbot._get_UID() behaviour

This commit is contained in:
James Lu 2019-08-26 12:17:07 -07:00
parent 27eed3334b
commit 304631ebd0
3 changed files with 23 additions and 3 deletions

View File

@ -929,7 +929,7 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
log.debug('Mode %s: This mode is a prefix mode.', mode)
arg = args.pop(0)
# Convert nicks to UIDs implicitly
arg = self._get_UID(arg) or arg
arg = self._get_UID(arg)
if arg not in self.users: # Target doesn't exist, skip it.
log.debug('(%s) Skipping setting mode "%s %s"; the '
'target doesn\'t seem to exist!', self.name,

View File

@ -44,7 +44,7 @@ class ClientbotBaseProtocol(PyLinkNetworkCoreWithUtils):
# If this sender doesn't already exist, spawn a new client.
idsource = self.spawn_client(nick, ident or 'unknown', host or 'unknown',
server=self.uplink, realname=FALLBACK_REALNAME).uid
return idsource
return idsource or nick # Return input if missing per upstream spec
def away(self, source, text):
"""STUB: sets away messages for internal clients."""

View File

@ -1,17 +1,37 @@
import unittest
import unittest.mock
from pylinkirc.protocols import clientbot
from pylinkirc.classes import User
import protocol_test_fixture as ptf
class UnrealProtocolTest(ptf.BaseProtocolTest):
class ClientbotProtocolTest(ptf.BaseProtocolTest):
proto_class = clientbot.ClientbotWrapperProtocol
def setUp(self):
super().setUp()
self.p.pseudoclient = self._make_user('PyLink', uid='ClientbotInternal@0')
def test_get_UID(self):
u_internal = self._make_user('you', uid='100')
check = lambda inp, expected: self.assertEqual(self.p._get_UID(inp), expected)
# External clients are returned by the matcher
with unittest.mock.patch.object(self.proto_class, 'is_internal_client', return_value=False) as m:
check('you', '100') # nick to UID
check('YOu', '100')
check('100', '100') # already a UID
check('Test', 'Test') # non-existent
# Internal clients are ignored
with unittest.mock.patch.object(self.proto_class, 'is_internal_client', return_value=True) as m:
check('you', 'you')
check('YOu', 'YOu')
check('100', '100') # already a UID
check('Test', 'Test') # non-existent
# In the future we will have protocol specific test cases here
if __name__ == '__main__':