Ejemplo n.º 1
0
class Supported(pyschema.Record):
    """We have doc"""
    _namespace = "com.spotify.pyschema.test"
    int_field = pyschema.Integer(nullable=False, size=4)
    float1 = pyschema.Float(nullable=False)
    required_string_field = pyschema.Text(nullable=False)
    long_field = pyschema.Integer(description="some number")
    optional_string_field = pyschema.Text(description="")
    undocumented_string_field = pyschema.Text()
    string_list = pyschema.List(pyschema.Text(nullable=False),
                                nullable=True,
                                default=None)
    string_map = pyschema.Map(pyschema.Text(nullable=False),
                              description="map of foo",
                              nullable=True,
                              default=None)
    bytes1 = pyschema.Bytes(description="bytes field 1")
    boolean1 = pyschema.Boolean(description="boolean field 1")
    another_string_field = pyschema.Text(description="What")
    boolean2 = pyschema.Boolean(description="boolean field 2")
    bytes2 = pyschema.Bytes(description="bytes field 2")
    weird_characters = pyschema.Integer(
        description=u"\';drop table schemas;--\u0100\u0101\x00\x00\n"
        u"http://uncyclopedia.wikia.com/wiki/AAAAAAAAA! "
        u"\\ \u043c\u043d\u043e\u0433\u0430\u0431\u0443"
        u"\u043a\u0430\u0444 <script>alert(\"eh\")</script>(:,%)\'")
    float2 = pyschema.Float(description="float field 2")
Ejemplo n.º 2
0
class ParseMaps(ParseThreeIncludingNullable):
    maxDiff = 2000
    schema_name = "MySchema"
    avsc = """
{
    "name": "MySchema",
    "type": "record",
    "fields": [{
        "default": {},
        "type": {
            "values": ["null", "long"],
            "type": "map"
        },
        "name": "m"
    }, {
        "default": {},
        "type": [{
            "values": ["null", "long"],
            "type": "map"
        }, "null"],
        "name": "n"
    }, {
        "default": null,
        "type": ["null",
        {
            "values": ["null", "long"],
            "type": "map"
        }],
        "name": "o"
    }]
}"""
    references = [("m", pyschema.Map(pyschema.Integer())),
                  ("n", pyschema.Map(pyschema.Integer(), nullable=True)),
                  ("o",
                   pyschema.Map(pyschema.Integer(),
                                nullable=True,
                                default=None))]
Ejemplo n.º 3
0
class ParseThreeIncludingNullable(NoAutoRegister):
    schema_name = "FooRecord"
    avsc = """
{
  "type" : "record",
  "name" : "FooRecord",
  "fields" : [ {
    "name" : "field_a",
    "type" : [ "null", "string" ],
    "default" : null
  }, {
    "name" : "long_b",
    "type" : [ "null", "long" ],
    "default" : null
  }, {
    "name" : "required_c",
    "type" : "string"
  } ]
}"""

    references = [("field_a", pyschema.Text()), ("long_b", pyschema.Integer()),
                  ("required_c", pyschema.Text(nullable=False))]

    def test_can_parse(self):
        schema_class = avro_schema_parser.parse_schema_string(self.avsc)
        self.assertTrue(pyschema.ispyschema(schema_class))
        self.assertEqual(schema_class._schema_name, self.schema_name)

        for (gen_name, gen_type), (ref_name, ref_type) in zip(
                schema_class._fields.items(), self.references):
            self.assertEqual(gen_name, ref_name)
            self.assertTrue(
                gen_type.is_similar_to(ref_type),
                "Types for field {0!r} don't match".format(ref_name))

    def test_roundtrip(self):
        schema_class = avro_schema_parser.parse_schema_string(self.avsc)
        schema_struct = json.loads(self.avsc)
        regenerated_struct = avro.get_schema_dict(schema_class)
        self.assertEqual(schema_struct, regenerated_struct)
Ejemplo n.º 4
0
 class Target(pyschema.Record):
     impressions = pyschema.Integer()
     clicks = pyschema.Integer()