mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Added changeusername command and fixed the framework so tests could run.
This commit is contained in:
parent
476ef32f47
commit
4ab9dc7718
@ -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):
|
||||
"""<name> <new name> [<password>]
|
||||
|
||||
Changes your current user database name to the new name given.
|
||||
<password> 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):
|
||||
"""<name> <hostmask> [<password>]
|
||||
|
||||
Adds the hostmask <hostmask> to the user specified by <name>. The
|
||||
<password> may only be required if the user is not recognized by his
|
||||
<password> may only be required if the user is not recognized by
|
||||
hostmask.
|
||||
"""
|
||||
(name, hostmask, password) = privmsgs.getArgs(args, 2, 1)
|
||||
|
17
test/test.py
17
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
|
||||
|
@ -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:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user