コード例 #1
0
    def test_complete_selection(self):
        "Test complete selection"
        field = {
            'type': 'selection',
            'selection': [
                ('male', 'Male'),
                ('female', 'Female'),
                ],
            }
        for value, result in (
                ('m', ['male']),
                ('test', []),
                ('', ['male', 'female']),
                (None, ['male', 'female']),
                (['male', 'f'], [['male', 'female']]),
                (['male', None], [['male', 'male'], ['male', 'female']]),
                ):
            self.assertEqual(
                list(complete_value(field, value)), result,
                msg="complete_value(%r, %r)" % (field, value))

        field_with_empty = field.copy()
        field_with_empty['selection'] = (field_with_empty['selection']
            + [('', '')])
        for value, result in (
                ('m', ['male']),
                ('test', []),
                ('', ['male', 'female', '']),
                (None, ['male', 'female', '']),
                (['male', 'f'], [['male', 'female']]),
                ):
            self.assertEqual(
                list(complete_value(field_with_empty, value)), result,
                msg="complete_value(%r, %r)" % (field_with_empty, value))
コード例 #2
0
 def test_complete_boolean(self):
     "Test complete boolean"
     field = {
         'type': 'boolean',
         }
     for value, result in [
             (None, [True, False]),
             (True, [False]),
             (False, [True]),
             ]:
         self.assertEqual(
             list(complete_value(field, value)), result,
             msg="complete_value(%r, %r)" % (field, value))
コード例 #3
0
 def test_complete_reference(self):
     "Test complete reference"
     field = {
         'type': 'reference',
         'selection': [
             ('spam', 'Spam'),
             ('ham', 'Ham'),
             ('', ''),
             ],
         }
     for value, result in (
             ('s', ['%spam%']),
             ('test', []),
             ('', ['%spam%', '%ham%', '%']),
             (None, ['%spam%', '%ham%', '%']),
             (['spam', 'h'], [['spam', 'ham']]),
             ):
         self.assertEqual(
             list(complete_value(field, value)), result,
             msg="complete_value(%r, %r)" % (field, value))