Skip to content

Commit a2c64fd

Browse files
committed
Validate indexer values
Make sure that indexer values are one of the supported indexers. Invalid values would have raised an invalid indexer exception on access.
1 parent 7813515 commit a2c64fd

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

roundup/configuration.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,18 @@ def str2value(self, value):
408408
return _val
409409
raise OptionValueError(self, value, self.class_description)
410410

411+
class IndexerOption(Option):
412+
"""Valid options for indexer"""
413+
414+
allowed = ['', 'xapian', 'whoosh', 'native']
415+
class_description = "Allowed values: %s" % ', '.join("'%s'" % a
416+
for a in allowed)
417+
418+
def str2value(self, value):
419+
_val = value.lower()
420+
if _val in self.allowed:
421+
return _val
422+
raise OptionValueError(self, value, self.class_description)
411423

412424
class MailAddressOption(Option):
413425

@@ -742,7 +754,7 @@ def str2value(self, value):
742754
"email?"),
743755
(BooleanOption, "email_registration_confirmation", "yes",
744756
"Offer registration confirmation by email or only through the web?"),
745-
(Option, "indexer", "",
757+
(IndexerOption, "indexer", "",
746758
"Force Roundup to use a particular text indexer.\n"
747759
"If no indexer is supplied, the first available indexer\n"
748760
"will be used in the following order:\n"

test/test_config.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def testInvalidIndexerLanguage_w_native(self):
381381
self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG')
382382

383383
def testInvalidIndexerLanguage_w_xapian(self):
384-
""" Use explicit xapian indexer. VAerify exception is
384+
""" Use explicit xapian indexer. Verify exception is
385385
generated.
386386
"""
387387

@@ -418,3 +418,23 @@ def testLoadConfig(self):
418418
# uppercase name passes as does tuple index for setting in web
419419
self.assertEqual(config['WEB_COOKIE_TAKES_PRECEDENCE'], 0)
420420
self.assertEqual(config[('web','cookie_takes_precedence')], 0)
421+
422+
423+
def testInvalidIndexerValue(self):
424+
""" Mistype native indexer. Verify exception is
425+
generated.
426+
"""
427+
428+
print("Testing indexer nati")
429+
430+
self.munge_configini(mods=[ ("indexer = ", "nati") ])
431+
432+
with self.assertRaises(configuration.OptionValueError) as cm:
433+
config.load(self.dirname)
434+
435+
self.assertIn("OptionValueError", repr(cm.exception))
436+
# look for failing value
437+
self.assertEqual("nati", cm.exception.args[1])
438+
# look for supported values
439+
self.assertIn("whoosh", cm.exception.args[2])
440+

0 commit comments

Comments
 (0)