Kaydet (Commit) c969b17a authored tarafından Akshesh's avatar Akshesh Kaydeden (comit) Tim Graham

Refs #26709 -- Added type check for models.Index fields argument.

üst a71724cd
......@@ -14,6 +14,8 @@ class Index(object):
suffix = 'idx'
def __init__(self, fields=[], name=None):
if not isinstance(fields, list):
raise ValueError('Index.fields must be a list.')
if not fields:
raise ValueError('At least one field is required to define an index.')
self.fields = fields
......
......@@ -22,6 +22,10 @@ class IndexesTests(TestCase):
self.assertEqual(index, same_index)
self.assertNotEqual(index, another_index)
def test_index_fields_type(self):
with self.assertRaisesMessage(ValueError, 'Index.fields must be a list.'):
models.Index(fields='title')
def test_raises_error_without_field(self):
msg = 'At least one field is required to define an index.'
with self.assertRaisesMessage(ValueError, msg):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment