Services: Reset configured passwords in tests

I didn't observe any error with the current set of tests but adding
another one that used "services password" caused oen of these tests
to fail.  Given that tests shouldn't leave traces in global state,
let's reset the configured passwords in finally blocks.
This commit is contained in:
David Macek 2021-04-24 20:33:40 +02:00 committed by Valentin Lorentz
parent 151fcf8caf
commit 8a4e8c2a37

View File

@ -39,43 +39,53 @@ class ServicesTestCase(PluginTestCase):
} }
def testPasswordAndIdentify(self): def testPasswordAndIdentify(self):
self.assertNotError('services password foo bar') try:
self.assertError('services identify') # Don't have a password. self.assertNotError('services password foo bar')
self.assertNotError('services password %s baz' % self.nick) self.assertError('services identify') # Don't have a password.
m = self.assertNotError('services identify') finally:
self.assertTrue(m.args[0] == 'NickServ') self.assertNotError('services password foo ""')
self.assertTrue(m.args[1].lower() == 'identify baz')
self.assertNotError('services password %s biff' % self.nick) try:
m = self.assertNotError('services identify') self.assertNotError('services password %s baz' % self.nick)
self.assertTrue(m.args[0] == 'NickServ') m = self.assertNotError('services identify')
self.assertTrue(m.args[1].lower() == 'identify biff') self.assertTrue(m.args[0] == 'NickServ')
self.assertTrue(m.args[1].lower() == 'identify baz')
self.assertNotError('services password %s biff' % self.nick)
m = self.assertNotError('services identify')
self.assertTrue(m.args[0] == 'NickServ')
self.assertTrue(m.args[1].lower() == 'identify biff')
finally:
self.assertNotError('services password %s ""' % self.nick)
def testPasswordConfig(self): def testPasswordConfig(self):
self.assertNotError('config plugins.Services.nicks ""') self.assertNotError('config plugins.Services.nicks ""')
self.assertNotError('config network plugins.Services.nicks ""') self.assertNotError('config network plugins.Services.nicks ""')
self.assertNotError('services password %s bar' % self.nick) try:
self.assertNotError('services password %s bar' % self.nick)
self.assertResponse( self.assertResponse(
'config plugins.Services.nicks', 'config plugins.Services.nicks',
'Global: ; test: %s' % self.nick) 'Global: ; test: %s' % self.nick)
self.assertResponse( self.assertResponse(
'config plugins.Services.nickserv.password.%s' % self.nick, 'config plugins.Services.nickserv.password.%s' % self.nick,
'Global: bar; test: bar') 'Global: bar; test: bar')
self.assertNotError( self.assertNotError(
'config network plugins.Services.nickserv.password.%s bar2' 'config network plugins.Services.nickserv.password.%s bar2'
% self.nick) % self.nick)
self.assertResponse( self.assertResponse(
'config plugins.Services.nickserv.password.%s' % self.nick, 'config plugins.Services.nickserv.password.%s' % self.nick,
'Global: bar; test: bar2') 'Global: bar; test: bar2')
self.assertResponse( self.assertResponse(
'config plugins.Services.nickserv.password.%s' % self.nick, 'config plugins.Services.nickserv.password.%s' % self.nick,
'Global: bar; test: bar2') 'Global: bar; test: bar2')
m = self.assertNotError('services identify') m = self.assertNotError('services identify')
self.assertTrue(m.args[0] == 'NickServ') self.assertTrue(m.args[0] == 'NickServ')
self.assertTrue(m.args[1].lower() == 'identify bar2') self.assertTrue(m.args[1].lower() == 'identify bar2')
finally:
self.assertNotError('services password %s ""' % self.nick)
def testRegisterNoExperimentalExtensions(self): def testRegisterNoExperimentalExtensions(self):
self.assertRegexp( self.assertRegexp(