From 304631ebd0e6a126c98bd386741618f0904e7689 Mon Sep 17 00:00:00 2001 From: James Lu Date: Mon, 26 Aug 2019 12:17:07 -0700 Subject: [PATCH] Fixes to clientbot._get_UID() behaviour --- classes.py | 2 +- protocols/clientbot.py | 2 +- test/test_protocol_clientbot.py | 22 +++++++++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/classes.py b/classes.py index a0705fb..7dea015 100644 --- a/classes.py +++ b/classes.py @@ -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, diff --git a/protocols/clientbot.py b/protocols/clientbot.py index cd57948..8566d9f 100644 --- a/protocols/clientbot.py +++ b/protocols/clientbot.py @@ -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.""" diff --git a/test/test_protocol_clientbot.py b/test/test_protocol_clientbot.py index 370e3a7..0ee29eb 100644 --- a/test/test_protocol_clientbot.py +++ b/test/test_protocol_clientbot.py @@ -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__':