Пример #1
0
    def test_to_dict_dict_factory(self):
        def upcasedict(tuples):
            return dict((x.upper(), y) for x, y in tuples)

        param_spec = ParamSpec.List(id_name='l',
                                    visible_if=dict(id_name='othermenu',
                                                    value='showlist'),
                                    child_parameters=[
                                        ParamSpec.String(id_name='s',
                                                         default='foo'),
                                        ParamSpec.Column(id_name='c',
                                                         visible_if=dict(
                                                             id_name='s',
                                                             value='iddqd')),
                                    ])
        param_dict = param_spec.to_dict(dict_factory=upcasedict)
        self.assertEqual(
            param_dict, {
                'TYPE':
                'list',
                'ID_NAME':
                'l',
                'NAME':
                '',
                'VISIBLE_IF': {
                    'ID_NAME': 'othermenu',
                    'VALUE': 'showlist'
                },
                'CHILD_PARAMETERS': [
                    {
                        'TYPE': 'string',
                        'ID_NAME': 's',
                        'NAME': '',
                        'DEFAULT': 'foo',
                        'MULTILINE': False,
                        'PLACEHOLDER': '',
                        'VISIBLE_IF': None,
                    },
                    {
                        'TYPE': 'column',
                        'ID_NAME': 'c',
                        'PLACEHOLDER': '',
                        'NAME': '',
                        'TAB_PARAMETER': None,
                        'COLUMN_TYPES': None,
                        'VISIBLE_IF': {
                            'ID_NAME': 's',
                            'VALUE': 'iddqd',
                        },
                    },
                ]
            })
Пример #2
0
 def test_to_dict(self):
     param_spec = ParamSpec.List(id_name='l',
                                 child_parameters=[
                                     ParamSpec.String(id_name='s',
                                                      default='foo'),
                                     ParamSpec.Column(id_name='c',
                                                      visible_if=dict(
                                                          id_name='s',
                                                          value='iddqd')),
                                 ])
     param_dict = param_spec.to_dict()
     self.assertEqual(
         param_dict, {
             'type':
             'list',
             'id_name':
             'l',
             'name':
             '',
             'visible_if':
             None,
             'child_parameters': [
                 {
                     'type': 'string',
                     'id_name': 's',
                     'name': '',
                     'default': 'foo',
                     'multiline': False,
                     'placeholder': '',
                     'visible_if': None,
                 },
                 {
                     'type': 'column',
                     'id_name': 'c',
                     'placeholder': '',
                     'name': '',
                     'tab_parameter': None,
                     'column_types': None,
                     'visible_if': {
                         'id_name': 's',
                         'value': 'iddqd',
                     },
                 },
             ]
         })
     # Just to make sure our unit-test is sane: verify from_dict(to_json)
     # returns the original.
     self.assertEqual(ParamSpec.from_dict(param_dict), param_spec)