From 4ab9dc7718f5b36491ec5d383460e788c2e85e3a Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Thu, 18 Sep 2003 07:52:34 +0000 Subject: [PATCH] Added changeusername command and fixed the framework so tests could run. --- src/UserCommands.py | 28 ++++++++++++++++++++++++++-- test/test.py | 17 +++++++++++++++-- test/test_UserCommands.py | 18 +++++++++++++++--- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/UserCommands.py b/src/UserCommands.py index 72ca4d22b..7a789d6ca 100755 --- a/src/UserCommands.py +++ b/src/UserCommands.py @@ -61,7 +61,7 @@ class UserCommands(callbacks.Privmsg): return try: ircdb.users.getUserId(name) - irc.error(msg, 'That name is alrady assigned to someone.') + irc.error(msg, 'That name is already assigned to someone.') return except KeyError: pass @@ -95,11 +95,35 @@ class UserCommands(callbacks.Privmsg): else: irc.error(msg, conf.replyIncorrectAuth) + def changeusername(self, irc, msg, args): + """ [] + + Changes your current user database name to the new name given. + is only necessary if the user isn't recognized by hostmask. + """ + (name, newname, password) = privmsgs.getArgs(args, needed=2,optional=1) + try: + id = ircdb.users.getUserId(name) + user = ircdb.users.getUser(id) + except KeyError: + irc.error(msg, 'That username isn\'t registered.') + return + try: + id = ircdb.users.getUserId(newname) + irc.error(msg, '%r is already registered.' % newname) + return + except KeyError: + pass + if user.checkHostmask(msg.prefix) or user.checkPassword(password): + user.name = newname + ircdb.users.setUser(id, user) + irc.reply(msg, conf.replySuccess) + def addhostmask(self, irc, msg, args): """ [] Adds the hostmask to the user specified by . The - may only be required if the user is not recognized by his + may only be required if the user is not recognized by hostmask. """ (name, hostmask, password) = privmsgs.getArgs(args, 2, 1) diff --git a/test/test.py b/test/test.py index 32c5869b7..2d7e42a61 100755 --- a/test/test.py +++ b/test/test.py @@ -37,6 +37,8 @@ if 'test' not in sys.path: import conf conf.dataDir = 'test-data' +conf.confDir = 'test-conf' +conf.logDir = 'test-log' conf.replyWhenNotCommand = False from fix import * @@ -52,14 +54,21 @@ import unittest if not os.path.exists(conf.dataDir): os.mkdir(conf.dataDir) -for filename in os.listdir(conf.dataDir): - os.remove(os.path.join(conf.dataDir, filename)) +if not os.path.exists(conf.confDir): + os.mkdir(conf.confDir) + +if not os.path.exists(conf.logDir): + os.mkdir(conf.logDir) + +for filename in os.listdir(conf.logDir): + os.remove(os.path.join(conf.logDir, filename)) import debug debug.minimumDebugPriority = 'high' import world +import ircdb import irclib import drivers import ircmsgs @@ -106,8 +115,12 @@ class PluginTestCase(unittest.TestCase): timeout = 10 plugins = () def setUp(self, nick='test'): + for filename in os.listdir(conf.confDir): + os.remove(os.path.join(conf.confDir, filename)) for filename in os.listdir(conf.dataDir): os.remove(os.path.join(conf.dataDir, filename)) + ircdb.users.reload() + ircdb.channels.reload() if not self.plugins: raise ValueError, 'PluginTestCase must have a "plugins" attribute.' self.nick = nick diff --git a/test/test_UserCommands.py b/test/test_UserCommands.py index c0cddd276..7e3804164 100644 --- a/test/test_UserCommands.py +++ b/test/test_UserCommands.py @@ -33,9 +33,21 @@ from test import * class UserCommandsTestCase(PluginTestCase, PluginDocumentation): plugins = ('UserCommands',) -## def testRegister(self): -## self.assertNotError('register foo bar') -## self.assertError('register foo baz') + prefix1 = 'somethingElse!user@host.tld' + prefix2 = 'EvensomethingElse!user@host.tld' + def testRegister(self): + self.prefix = self.prefix1 + self.assertNotError('register foo bar') + self.assertError('register foo baz') + + def testChangeUsername(self): + self.prefix = self.prefix1 + self.assertNotError('register foo bar') + self.prefix = self.prefix2 + self.assertNotError('register bar baz') + self.prefix = self.prefix1 + self.assertError('changeusername foo bar') + self.assertNotError('changeusername foo baz') # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: