コード例 #1
0
    def test_error_strict(self):
        fields = {
            FieldName("version", alias="@version"):
            StringField(),
            FieldName("servers", alias="server"): [{
                FieldName("type", alias="@type"):
                StringField(),
                "host":
                StringField(),
                "port":
                IntegerField()
            }]
        }
        serializer = SerializerFactory.create(None, fields, error_strict=False)

        raw_data = {
            "@version": "3.0",
            "server": {
                "id": "main",
                "@type": "main",
                "host": "127.0.0.1",
                "port": '80'
            }
        }
        load_data = serializer.load(raw_data)
        self.assertEqual(len(serializer.errors), 0)
        self.assertEqual(
            load_data, {
                "version": "3.0",
                "servers": [{
                    "type": "main",
                    "host": "127.0.0.1",
                    "port": 80
                }]
            })
コード例 #2
0
ファイル: test_generic.py プロジェクト: brain-zhang/learn123
class SimpleTestConfig(BaseConfig):
    fields = {
        FieldName("version", alias="@version"):
        StringField(),
        FieldName("servers", alias="server"): [{
            FieldName("type", alias="@type"):
            StringField(),
            "host":
            StringField(),
            "port":
            IntegerField()
        }]
    }
    loader_class = Mock()
コード例 #3
0
ファイル: test_generic.py プロジェクト: brain-zhang/learn123
class Config1(ReadWriteConfig):

    config_file = "a"
    loader_class = MemFileLoader.build(mem=mem)
    fields = {
        FieldName("version", alias="@version"): StringField(),
    }
コード例 #4
0
ファイル: test_fields.py プロジェクト: memoryboxes/learn123
    def test_string(self):
        field = StringField()
        self.assertEqual(field.load('abc'), u'abc')
        with self.assertRaises(ValidationError):
            field.load('')

        field = StringField(min_length=4)
        with self.assertRaises(ValidationError):
            field.load('abc')

        field = StringField(allow_blank=True, min_length=4)
        self.assertEqual(field.load(None), u'')
        self.assertEqual(field.load('abcd'), 'abcd')
        with self.assertRaises(ValidationError):
            field.load('abc')

        field = StringField(allow_blank=True)
        self.assertEqual(field.load(None), u'')
        self.assertEqual(field.load('abcd'), u'abcd')
        self.assertEqual(field.load('abc'), u'abc')
コード例 #5
0
ファイル: test_fields.py プロジェクト: brain-zhang/learn123
    def test_string(self):
        field = StringField()
        self.assertEqual(field.load('abc'), u'abc')
        with self.assertRaises(ValidationError):
            field.load('')

        field = StringField(min_length=4)
        with self.assertRaises(ValidationError):
            field.load('abc')

        field = StringField(allow_blank=True, min_length=4)
        self.assertEqual(field.load(None), u'')
        self.assertEqual(field.load('abcd'), 'abcd')
        with self.assertRaises(ValidationError):
            field.load('abc')

        field = StringField(allow_blank=True)
        self.assertEqual(field.load(None), u'')
        self.assertEqual(field.load('abcd'), u'abcd')
        self.assertEqual(field.load('abc'), u'abc')