def test_single_nested(): # Geo # - Place # - Coord geo_spec = builder.spec_builder() \ .add_field("place_id:uuid", {}) \ .add_field("coordinates", builder.geo_pair(as_list=True)) spec = builder.spec_builder() \ .add_field("id:uuid", {}) \ .add_field("geo", builder.nested(fields=geo_spec.build())) \ .build() supplier = Loader(spec).get('geo') first = supplier.next(0) assert isinstance(first, dict) assert list(first.keys()) == ['place_id', 'coordinates']
def test_multi_nested(): # User # - Geo # - - Place # - - Coord geo_spec = builder.spec_builder() \ .add_field("place_id:uuid", {}) \ .add_field("coordinates", builder.geo_pair(as_list=True)) user_spec = builder.spec_builder() \ .add_field("user_id:uuid", {}) \ .add_field("geo", builder.nested(fields=geo_spec.build())) spec = builder.spec_builder() \ .add_field("id:uuid", {}) \ .add_field("user", builder.nested(fields=user_spec.build())) \ .build() supplier = Loader(spec).get('user') first = supplier.next(0) assert isinstance(first, dict) assert list(first.keys()) == ['user_id', 'geo'] second = first['geo'] assert isinstance(second, dict) assert list(second.keys()) == ['place_id', 'coordinates']
}, "data": [["3040", "309f"]] }), (builder.geo_lat(start_lat=75.5), { "type": "geo.lat", "config": { "start_lat": 75.5 } }), (builder.geo_long(bbox=[31.3, 22.0, 34.1, 25.0]), { "type": "geo.long", "config": { "bbox": [31.3, 22.0, 34.1, 25.0] } }), (builder.geo_pair(join_with=":", as_list="yes"), { "type": "geo.pair", "config": { "join_with": ":", "as_list": "yes" } }), (builder.ip(base="192.168"), { "type": "ip", "config": { "base": "192.168" } }), (builder.ipv4(cidr="2.22.222.0/16"), { "type": "ipv4", "config": {
def _geo_pair_spec(**config): return builder.spec_builder() \ .add_field('pair', builder.geo_pair(**config)) \ .build()