Пример #1
0
        class NestedMap(MapObject):
            test_field_1 = Any(default='test_default_1')
            test_field_2 = Any(param='test_param_2')
            test_field_3 = Any(param='test_param_3', default='test_default_3')

            def resolve_test_field_3(self, value, parameters):
                return parameters.get('test_param_3') + '_the_resolver'
Пример #2
0
        class NestedMap(MapObject):
            test_field_1 = Any(default='test_default_1')
            test_field_2 = Any(param='test_param_2')
            test_field_3 = Any(param='test_param_3', default='test_default_3')

            def resolve_test_field_2(self, value, parameters):
                # resolvers should have access to other fields
                return self.test_field_1

            def resolve_test_field_3(self, value, parameters):
                return parameters.get('test_param_3') + '_the_resolver'
Пример #3
0
        class TestMap(MapObject):
            test_field_1 = Any()
            test_field_2 = Any()
            test_field_3 = Any()
            test_field_4 = Any()

            def resolve_test_field_2(self, value, parameters):
                mro.append(2)

            def resolve_test_field_3(self, value, parameters):
                mro.append(3)

            def resolve_test_field_4(self, value, parameters):
                mro.append(4)
Пример #4
0
        class NestedMap(MapObject):
            test_field_1 = Any(default='test_default_1')
            test_field_2 = Any(param='test_param_2', required=True)
            test_field_3 = Any(param='test_param_3', default='test_default_3')
            test_field_4 = List(Any)
            test_double_nested = Nested(DoubleNested)

            def resolve_test_field_2(self, value, parameters):
                # resolvers should have access to other fields
                return self.test_field_1

            def resolve_test_field_4(self, value, parameters):
                return [
                    'list_item_1',
                    'list_item_2',
                    'list_item_3',
                ]
Пример #5
0
 class DoubleNested(MapObject):
     test_field_1 = Any(default='test_default_1')
     test_field_2 = Any(param='test_param_2', default='test_default_2',
                        required=True)
     test_field_3 = Any(param='test_param_3', required=True)
     test_field_4 = Any(param='test_param_4', required=True)
     test_field_5 = Any(param='test_param_5', required=True)
     test_field_6 = Any(param='test_param_6')
Пример #6
0
    def test_define_common_field_outside_of_mapobject(self):
        common_field = Any(default='test')

        class TestMapOne(MapObject):
            common = common_field

        class TestMapTwo(MapObject):
            common = common_field

        test_one = TestMapOne()
        test_two = TestMapTwo()

        self.assertEqual(test_one.common, 'test')
        self.assertEqual(test_one.common, test_two.common)
Пример #7
0
        class NestedMap(MapObject):
            test_field_1 = Any(default='test_default_1')
            test_field_2 = Any(
                param='test_param_2',
                verbose_name='verbose_test_field_2_name'
            )
            test_field_3 = Any(param='test_param_3', default='test_default_3')
            test_field_4 = List(Any)
            test_double_nested = Nested(DoubleNested)

            def resolve_test_field_2(self, value, parameters):
                # resolvers should have access to other fields
                return self.test_field_1

            def resolve_test_field_3(self, value, parameters):
                return parameters.get('test_param_3') + '_the_resolver'

            def resolve_test_field_4(self, value, parameters):
                return [
                    'list_item_1',
                    'list_item_2',
                    'list_item_3',
                ]
Пример #8
0
        class TestMap(MapObject):
            test_nested = Nested(NestedMap)
            test_field_change_required_status = Any(
                param='test_param_not_required',
                required=True
            )

            def __init__(self, *args, **kwargs):
                super(TestMap, self).__init__(*args, **kwargs)
                key = 'test_field_change_required_status'
                # conditional requirement change
                self.base_fields[key].required = False

            def resolve_test_nested(self, value, parameters):
                return NestedMap(
                    parameters=parameters,
                    test_field_1='test_field_1_resolved'
                )
Пример #9
0
    def test_define_common_field_with_param_outside_of_mapobject(self):
        common_field = Any(param='TEST_PARAM')

        class TestMapOne(MapObject):
            common = common_field

        class TestMapTwo(MapObject):
            common = common_field

        parameters = {
            'TEST_PARAM': 'test',
        }

        test_one = TestMapOne(parameters=parameters)
        test_two = TestMapTwo(parameters=parameters)

        self.assertEqual(test_one.common, 'test')
        self.assertEqual(test_one.common, test_two.common)

        test_one = TestMapOne(parameters=parameters)
        test_two = TestMapTwo(parameters={})

        self.assertEqual(test_one.common, 'test')
        self.assertNotEqual(test_one.common, test_two.common)
Пример #10
0
        class TestMap(MapObject):
            test_field_1 = Any()
            test_field_2 = Any()

            def resolve_test_field_2(self, *args, **kwargs):
                return 'not_none'
Пример #11
0
 class DoubleNested(MapObject):
     test_field_1 = Any(default='test_default_1')
     test_field_2 = Any(param='test_param_2', default='test_default_2')
Пример #12
0
 class TestMap(MapObject):
     test_field_1 = Any()
Пример #13
0
 class NestedListItem(MapObject):
     test_field_1 = Any(param='test_param_1')
     test_field_2 = Any(param='test_param_2')
Пример #14
0
    def test_resolve_to_default(self):
        field = Any(default='test_default')

        self.assertEqual('5', field.resolve('5'))
        self.assertEqual('test_default', field.resolve(None))
Пример #15
0
    def test_resolve_identity(self):
        field = Any()

        self.assertEqual(5, field.resolve(5))
        self.assertEqual('test_value', field.resolve('test_value'))
Пример #16
0
    def test_create(self):
        field = Any(param='test_param', default='test_default')

        self.assertTrue('test_param', field.param)
        self.assertTrue('test_default', field.default)
Пример #17
0
    def test_attrs(self):
        field = Any()

        self.assertTrue(hasattr(field, 'param'))
        self.assertTrue(hasattr(field, 'default'))
Пример #18
0
 class NestedMap(MapObject):
     test_field_1 = Any(default='test_default_1')
     test_field_2 = Any(param='test_param_2')
     test_field_3 = Any(param='test_param_3', default='test_default_3')
Пример #19
0
 class TestMapObject(MapObject):
     test_field_1 = Any()
     test_field_2 = Any(param='test_param_2')