mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 20:59:27 +01:00
registry: Normalize values before checking they are valid
Otherwise, normalization is useless, and gives a surprising error message, such as: ``` <user> config plugins.rss.sortfeeditems oldestfirst <bot> Error: Valid values include 'asInFeed', 'oldestFirst', 'newestFirst', 'outdatedFirst', and 'updatedFirst', not 'oldestFirst'. ```
This commit is contained in:
parent
86b389618f
commit
200acdfa93
@ -1,7 +1,7 @@
|
||||
###
|
||||
# Copyright (c) 2002-2005, Jeremiah Fincher
|
||||
# Copyright (c) 2009, James McCoy
|
||||
# Copyright (c) 2010-2021, Valentin Lorentz
|
||||
# Copyright (c) 2010-2022, Valentin Lorentz
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@ -33,11 +33,20 @@ import random
|
||||
|
||||
from supybot.test import *
|
||||
import supybot.conf as conf
|
||||
import supybot.registry as registry
|
||||
|
||||
_letters = 'abcdefghijklmnopqrstuvwxyz'
|
||||
def random_string():
|
||||
return ''.join(random.choice(_letters) for _ in range(16))
|
||||
|
||||
class Fruit(registry.OnlySomeStrings):
|
||||
validStrings = ('Apple', 'Orange')
|
||||
|
||||
group = conf.registerGroup(conf.supybot.plugins.Config, 'test')
|
||||
conf.registerGlobalValue(group, 'fruit',
|
||||
Fruit('Orange', '''Must be a fruit'''))
|
||||
|
||||
|
||||
class ConfigTestCase(ChannelPluginTestCase):
|
||||
# We add utilities so there's something in supybot.plugins.
|
||||
plugins = ('Config', 'User', 'Utilities', 'Web')
|
||||
@ -50,6 +59,16 @@ class ConfigTestCase(ChannelPluginTestCase):
|
||||
self.assertNotRegexp('config get supybot.reply', r'registry\.Group')
|
||||
self.assertResponse('config supybot.protocols.irc.throttleTime', '0.0')
|
||||
|
||||
def testSetOnlysomestrings(self):
|
||||
self.assertResponse('config supybot.plugins.Config.test.fruit Apple',
|
||||
'The operation succeeded.')
|
||||
self.assertResponse('config supybot.plugins.Config.test.fruit orange',
|
||||
'The operation succeeded.')
|
||||
self.assertResponse('config supybot.plugins.Config.test.fruit Tomatoe',
|
||||
"Error: Valid values include 'Apple' and "
|
||||
"'Orange', not 'Tomatoe'.")
|
||||
|
||||
|
||||
def testList(self):
|
||||
self.assertError('config list asldfkj')
|
||||
self.assertError('config list supybot.asdfkjsldf')
|
||||
|
@ -710,7 +710,7 @@ class OnlySomeStrings(String):
|
||||
|
||||
def setValue(self, s):
|
||||
v = self.normalize(s)
|
||||
if s in self.validStrings:
|
||||
if v in self.validStrings:
|
||||
self.__parent.setValue(v)
|
||||
else:
|
||||
self.error(v)
|
||||
|
Loading…
Reference in New Issue
Block a user