Example #1
0
def test_encode_json_small():
    feat = OwcResource(id="http://the.resource.com/id=1",
                            update_date=datetime.now(),
                            title="resource title",
                            temporal_extent=TimeIntervalFormat.from_string(
                                "2013-11-02T15:24:24.446+12:00"))
    assert feat.temporal_extent.to_dict() == TimeIntervalFormat.from_string(
        "2013-11-02T15:24:24.446+12:00").to_dict()

    t1 = feat.to_dict()
    t2 = skip_nulls(feat.to_dict())

    assert t1.get('temporal_extent') == t2.get('temporal_extent')

    owc1 = OwcContext(id="http://ows.com/id1",
                           update_date=datetime.now(),
                           title="my context collection 1",
                           time_interval_of_interest=TimeIntervalFormat.from_string(
                               "2013-11-02T15:24:24.446+12:00"),
                           resources=[])
    assert owc1.time_interval_of_interest.to_dict() == TimeIntervalFormat.from_string(
        "2013-11-02T15:24:24.446+12:00").to_dict()

    t3 = skip_nulls(owc1.to_dict())

    assert owc1.id == "http://ows.com/id1"
    assert owc1.language == "en"
    assert owc1.title == "my context collection 1"
    assert len(owc1.keywords) == 0

    jsdata = owc1.to_json()
    logger.debug(jsdata)
    assert len(jsdata) > 0
Example #2
0
def test_decode_full_json3():
    jsondata3 = open(resource_file(os.path.join('owc_geojson_examples', 'owc3.geojson')), 'rb').read().decode('utf-8')

    owc3 = OwcContext.from_json(jsondata3)
    assert owc3 is not None
    logger.debug(owc3.to_json())
    re_owc3 = OwcContext.from_json(owc3.to_json())
    assert owc3.to_dict() == re_owc3.to_dict()

    assert owc3.creator_display.pixel_width == 800
    assert owc3.authors[0].email == "*****@*****.**"

    assert len(owc3.keywords) == 5
    assert owc3.resources[0].keywords[0].label == "Informative Layers"

    links_via = [l for l in owc3.context_metadata if
                 l.href == "http://portal.smart-project.info/context/smart-sac.owc.json"]
    assert len(links_via) == 1

    assert owc3.resources[0].temporal_extent.to_dict() == TimeIntervalFormat.from_string(
        "2011-11-04T00:01:23Z/2017-12-05T17:28:56Z").to_dict()

    wms_offering = [of for of in owc3.resources[0].offerings if
                    of.offering_code == "http://www.opengis.net/spec/owc-geojson/1.0/req/wms"]
    assert len(wms_offering) > 0
    assert wms_offering[0].styles[
               0].legend_url == "http://docs.geoserver.org/latest/en/user/_images/line_simpleline1.png"
Example #3
0
def test_load_bulk():
    js1 = open(resource_file(os.path.join('owc_geojson_examples','from-meta-resource.json')), 'r').read()
    js2 = open(resource_file(os.path.join('owc_geojson_examples','ingest1.owc.geojson')), 'r').read()
    js3 = open(resource_file(os.path.join('owc_geojson_examples','newzealand-overview.json')), 'r').read()
    js4 = open(resource_file(os.path.join('owc_geojson_examples','owc1.geojson')), 'r').read()
    js5 = open(resource_file(os.path.join('owc_geojson_examples','owc2.geojson')), 'r').read()
    js6 = open(resource_file(os.path.join('owc_geojson_examples','owc3.geojson')), 'r').read()
    js7 = open(resource_file(os.path.join('owc_geojson_examples','sac-casestudies.json')), 'r').read()

    feeds = [js1, js2, js3,js4, js5, js6, js7 ]

    for f in feeds:
        logger.debug(f)
        dict_obj = decode_json(f)
        assert dict_obj is not None
        # logger.debug(dict_obj)
        owc = OwcContext.from_dict(dict_obj)
        assert owc is not None
        # logger.debug(OwcContext.from_dict(dict_obj).to_json())
        jsdata = owc.to_json()
        assert jsdata is not None
        assert len(jsdata) > 10
        re_owc = OwcContext.from_json(jsdata)
        assert re_owc is not None
        through = OwcContext.from_json(f)
        assert owc.to_dict() == through.to_dict()
def test_single_atomxml_coding():
    atom1 = open(resource_file(os.path.join('owc_atom_examples', 'wms_meris.xml')), 'rb').read()
    owc = OwcContext.from_atomxml(atom1)
    assert owc is not None
    # logger.debug("s owc title: " + owc.title)
    for res in owc.resources:
        # logger.debug("s res id: " + res.id)
        assert res.title is not None
        assert len(res.offerings) > 0
        for off in res.offerings:
            # logger.debug("s off code: " + off.offering_code)
            assert off.operations is not None
            assert len(off.operations) > 0
        # for lnk in res.preview:
        #     logger.debug(lnk.to_dict())

    jsdata = owc.to_json()
    assert jsdata is not None
    assert len(jsdata) > 10
    re_owc = OwcContext.from_json(jsdata)
    assert re_owc is not None
    for res in re_owc.resources:
        # logger.debug("s res id: " + res.id)
        assert res.title is not None
        assert len(res.offerings) > 0
        for off in res.offerings:
            # logger.debug("s off code: " + off.offering_code)
            assert off.operations is not None
            assert len(off.operations) > 0
        # for lnk in res.preview:
        #     logger.debug(lnk.to_dict())
    assert owc.to_dict() == re_owc.to_dict()
def test_single_atomxml_coding():
    atom1 = open(
        resource_file(os.path.join('owc_atom_examples', 'wms_meris.xml')),
        'rb').read()
    owc = OwcContext.from_atomxml(atom1)
    assert owc is not None
    # logger.debug("s owc title: " + owc.title)
    for res in owc.resources:
        # logger.debug("s res id: " + res.id)
        assert res.title is not None
        assert len(res.offerings) > 0
        for off in res.offerings:
            # logger.debug("s off code: " + off.offering_code)
            assert off.operations is not None
            assert len(off.operations) > 0
        # for lnk in res.preview:
        #     logger.debug(lnk.to_dict())

    jsdata = owc.to_json()
    assert jsdata is not None
    assert len(jsdata) > 10
    re_owc = OwcContext.from_json(jsdata)
    assert re_owc is not None
    for res in re_owc.resources:
        # logger.debug("s res id: " + res.id)
        assert res.title is not None
        assert len(res.offerings) > 0
        for off in res.offerings:
            # logger.debug("s off code: " + off.offering_code)
            assert off.operations is not None
            assert len(off.operations) > 0
        # for lnk in res.preview:
        #     logger.debug(lnk.to_dict())
    assert owc.to_dict() == re_owc.to_dict()
Example #6
0
def test_decode_full_json1():
    jsondata1 = open(resource_file(os.path.join('owc_geojson_examples', 'owc1.geojson')), 'r').read()
    owc1 = OwcContext.from_json(jsondata1)
    assert owc1 is not None
    assert owc1.resources[0].temporal_extent.to_dict() == TimeIntervalFormat.from_string(
        "2013-11-02T15:24:24.446+12:00").to_dict()
    # logger.debug(owc1.to_json())
    re_owc1 = OwcContext.from_json(owc1.to_json())
    assert owc1.to_dict() == re_owc1.to_dict()

    getcapa_ops = [op for op in owc1.resources[0].offerings[0].operations if op.operations_code == "GetCapabilities"]
    assert len(getcapa_ops) > 0
    assert getcapa_ops[0].mimetype == "application/xml"
Example #7
0
def test_decode_json_small():
    owc1 = OwcContext(id="http://ows.com/id1",
                           update_date=datetime.now(),
                           title="my context collection 1")
    jsdata = owc1.to_json()
    owc2 = OwcContext.from_json(jsdata)
    assert owc2 is not None
    assert isinstance(owc2, OwcContext)
    logger.debug(owc2.to_dict())
    assert owc2.id == "http://ows.com/id1"
    assert owc2.language == "en"
    assert owc2.title == "my context collection 1"
    assert len(owc1.keywords) == 0
Example #8
0
def test_decode_full_json2():
    jsondata2 = open(resource_file(os.path.join('owc_geojson_examples', 'owc2.geojson')), 'rb').read().decode('latin1')
    owc2 = OwcContext.from_json(jsondata2)
    assert owc2 is not None
    # logger.debug(owc2.to_json())
    re_owc2 = OwcContext.from_json(owc2.to_json())
    assert owc2.to_dict() == re_owc2.to_dict()

    assert owc2.creator_application.title == "Web Enterprise Suite"
    assert owc2.spec_reference[0].href == "http://www.opengis.net/spec/owc-geojson/1.0/req/core"
    assert isinstance(owc2.resources[0].geospatial_extent, dict)
    geo = owc2.resources[0].geospatial_extent
    assert geo.get('type') == "Polygon"
    assert isinstance(geo.get('coordinates'), list)
def test_load_feeds_bulk():
    atom1 = open(resource_file(os.path.join('owc_atom_examples', 'geotiff.xml')), 'rb').read()
    atom2 = open(resource_file(os.path.join('owc_atom_examples', 'csw_10entries.xml')), 'rb').read()
    atom3 = open(resource_file(os.path.join('owc_atom_examples', 'gml_road.xml')), 'rb').read()
    atom4 = open(resource_file(os.path.join('owc_atom_examples', 'gmlcov.xml')), 'rb').read()
    atom5 = open(resource_file(os.path.join('owc_atom_examples', 'meris.atom')), 'rb').read()
    atom6 = open(resource_file(os.path.join('owc_atom_examples', 'meris_borders_users.atom')), 'rb').read()
    atom7 = open(resource_file(os.path.join('owc_atom_examples', 'meris_noauthor.xml')), 'rb').read()
    atom8 = open(resource_file(os.path.join('owc_atom_examples', 'meris_noprofile.xml')), 'rb').read()
    atom9 = open(resource_file(os.path.join('owc_atom_examples', 'sea_ice_extent_01.atom')), 'rb').read()
    atom10 = open(resource_file(os.path.join('owc_atom_examples', 'wcs_kml.xml')), 'rb').read()
    atom11 = open(resource_file(os.path.join('owc_atom_examples', 'wfs_100entries.xml')), 'rb').read()
    atom12 = open(resource_file(os.path.join('owc_atom_examples', 'wms_gml_hurricane_tomas.xml')), 'rb').read()
    atom13 = open(resource_file(os.path.join('owc_atom_examples', 'wms_meris.xml')), 'rb').read()
    atom14 = open(resource_file(os.path.join('owc_atom_examples', 'wms_scale.xml')), 'rb').read()
    atom15 = open(resource_file(os.path.join('owc_atom_examples', 'wmstestdata.xml')), 'rb').read()
    atom16 = open(resource_file(os.path.join('owc_atom_examples', 'wmts.xml')), 'rb').read()
    atom17 = open(resource_file(os.path.join('owc_atom_examples', 'wps_52north.xml')), 'rb').read()

    feeds = [atom1, atom2, atom3, atom4, atom5, atom6, atom7, atom8, atom9, atom10,
             atom11, atom12, atom13, atom14, atom15, atom16, atom17]

    for f in feeds:
        # logger.debug(f)
        dict_obj = decode_atomxml(f)
        assert dict_obj is not None
        # logger.debug("dict title: " + dict_obj.get('properties').get('title'))
        owc = OwcContext.from_dict(dict_obj)
        assert owc is not None
        # logger.debug("owc title: " + owc.title)
        for res in owc.resources:
            # logger.debug(res.id)
            assert res.title is not None
            # logger.debug(OwcContext.from_dict(dict_obj).to_json())

        jsdata = owc.to_json()
        assert jsdata is not None
        assert len(jsdata) > 10
        re_owc = OwcContext.from_json(jsdata)
        assert re_owc is not None

        assert owc.to_dict() == re_owc.to_dict()

        # and other way round
        a_owc = OwcContext.from_atomxml(f)
        assert a_owc is not None
        assert len(a_owc.resources) > 0
        for a_res in a_owc.resources:
            assert len(a_res.offerings) > 0
            for a_off in a_res.offerings:
                ops = len(a_off.operations)
                con = len(a_off.contents)
                sty = len(a_off.styles)
                assert (ops + con + sty) > 0

        a_jsdata = a_owc.to_json()
        a_re_owc = OwcContext.from_json(a_jsdata)
        assert len(a_re_owc.resources) > 0
        for a_re_res in a_owc.resources:
            assert len(a_re_res.offerings) > 0
            for a_re_off in a_re_res.offerings:
                ops = len(a_re_off.operations)
                con = len(a_re_off.contents)
                sty = len(a_re_off.styles)
                assert (ops + con + sty) > 0
        assert a_owc.to_dict() == a_re_owc.to_dict()
def test_load_feeds_bulk():
    atom1 = open(
        resource_file(os.path.join('owc_atom_examples', 'geotiff.xml')),
        'rb').read()
    atom2 = open(
        resource_file(os.path.join('owc_atom_examples', 'csw_10entries.xml')),
        'rb').read()
    atom3 = open(
        resource_file(os.path.join('owc_atom_examples', 'gml_road.xml')),
        'rb').read()
    atom4 = open(
        resource_file(os.path.join('owc_atom_examples', 'gmlcov.xml')),
        'rb').read()
    atom5 = open(
        resource_file(os.path.join('owc_atom_examples', 'meris.atom')),
        'rb').read()
    atom6 = open(
        resource_file(
            os.path.join('owc_atom_examples', 'meris_borders_users.atom')),
        'rb').read()
    atom7 = open(
        resource_file(os.path.join('owc_atom_examples', 'meris_noauthor.xml')),
        'rb').read()
    atom8 = open(
        resource_file(os.path.join('owc_atom_examples',
                                   'meris_noprofile.xml')), 'rb').read()
    atom9 = open(
        resource_file(
            os.path.join('owc_atom_examples', 'sea_ice_extent_01.atom')),
        'rb').read()
    atom10 = open(
        resource_file(os.path.join('owc_atom_examples', 'wcs_kml.xml')),
        'rb').read()
    atom11 = open(
        resource_file(os.path.join('owc_atom_examples', 'wfs_100entries.xml')),
        'rb').read()
    atom12 = open(
        resource_file(
            os.path.join('owc_atom_examples', 'wms_gml_hurricane_tomas.xml')),
        'rb').read()
    atom13 = open(
        resource_file(os.path.join('owc_atom_examples', 'wms_meris.xml')),
        'rb').read()
    atom14 = open(
        resource_file(os.path.join('owc_atom_examples', 'wms_scale.xml')),
        'rb').read()
    atom15 = open(
        resource_file(os.path.join('owc_atom_examples', 'wmstestdata.xml')),
        'rb').read()
    atom16 = open(resource_file(os.path.join('owc_atom_examples', 'wmts.xml')),
                  'rb').read()
    atom17 = open(
        resource_file(os.path.join('owc_atom_examples', 'wps_52north.xml')),
        'rb').read()

    feeds = [
        atom1, atom2, atom3, atom4, atom5, atom6, atom7, atom8, atom9, atom10,
        atom11, atom12, atom13, atom14, atom15, atom16, atom17
    ]

    for f in feeds:
        # logger.debug(f)
        dict_obj = decode_atomxml(f)
        assert dict_obj is not None
        # logger.debug("dict title: " + dict_obj.get('properties').get('title'))
        owc = OwcContext.from_dict(dict_obj)
        assert owc is not None
        # logger.debug("owc title: " + owc.title)
        for res in owc.resources:
            # logger.debug(res.id)
            assert res.title is not None
            # logger.debug(OwcContext.from_dict(dict_obj).to_json())

        jsdata = owc.to_json()
        assert jsdata is not None
        assert len(jsdata) > 10
        re_owc = OwcContext.from_json(jsdata)
        assert re_owc is not None

        assert owc.to_dict() == re_owc.to_dict()

        # and other way round
        a_owc = OwcContext.from_atomxml(f)
        assert a_owc is not None
        assert len(a_owc.resources) > 0
        for a_res in a_owc.resources:
            assert len(a_res.offerings) > 0
            for a_off in a_res.offerings:
                ops = len(a_off.operations)
                con = len(a_off.contents)
                sty = len(a_off.styles)
                assert (ops + con + sty) > 0

        a_jsdata = a_owc.to_json()
        a_re_owc = OwcContext.from_json(a_jsdata)
        assert len(a_re_owc.resources) > 0
        for a_re_res in a_owc.resources:
            assert len(a_re_res.offerings) > 0
            for a_re_off in a_re_res.offerings:
                ops = len(a_re_off.operations)
                con = len(a_re_off.contents)
                sty = len(a_re_off.styles)
                assert (ops + con + sty) > 0
        assert a_owc.to_dict() == a_re_owc.to_dict()