예제 #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
예제 #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"
예제 #3
0
 def from_dict(cls, d):
     return OwcResource(
         id=d['id'],
         geospatial_extent=extract_p('geometry', d, None),
         title=d['properties']['title'],
         subtitle=extract_p('properties.abstract', d, None),
         update_date=extract_p('properties.updated', d, None),
         authors=[OwcAuthor.from_dict(do) for do in
                  extract_p('properties.authors', d, [])],
         publisher=extract_p('properties.publisher', d, None),
         rights=extract_p('properties.rights', d, None),
         temporal_extent=TimeIntervalFormat.from_string(
             extract_p('properties.date', d, None)),
         keywords=[OwcCategory.from_dict(do) for do in
                   extract_p('properties.categories', d, [])],
         resource_metadata=[OwcLink.from_dict(do) for do in
                            extract_p('properties.links.via', d, [])],
         content_description=[OwcLink.from_dict(do)
                              for do in extract_p('properties.links.alternates', d, [])],
         preview=[OwcLink.from_dict(do) for do in
                  extract_p('properties.links.previews', d, [])],
         content_by_ref=[OwcLink.from_dict(do) for do in
                         extract_p('properties.links.data', d, [])],
         offerings=[OwcOffering.from_dict(do) for do in
                    extract_p('properties.offerings', d, [])],
         active=extract_p('properties.active', d, None),
         min_scale_denominator=try_float(extract_p(
             'properties.minscaledenominator', d, None)),
         max_scale_denominator=try_float(extract_p(
             'properties.maxscaledenominator', d, None)),
         folder=extract_p('properties.folder', d, None),
     )
예제 #4
0
 def from_dict(cls, d):
     # TODO parse bbox??
     return OwcContext(
         id=d['id'],
         spec_reference=[OwcLink.from_dict(do) for do in
                         extract_p('properties.links.profiles', d, [])],
         area_of_interest=extract_p('bbox', d, None),
         context_metadata=[OwcLink.from_dict(do) for do in
                           extract_p('properties.links.via', d, [])],
         language=extract_p('properties.lang', d, None),
         title=extract_p('properties.title', d, None),
         subtitle=extract_p('properties.abstract', d, None),
         update_date=extract_p('properties.updated', d, None),
         authors=[OwcAuthor.from_dict(do) for do in
                  extract_p('properties.authors', d, [])],
         publisher=extract_p('properties.publisher', d, None),
         creator_application=build_from_xp(
             'properties.generator', d, OwcCreatorApplication, None),
         creator_display=build_from_xp(
             'properties.display', d, OwcCreatorDisplay, None),
         rights=extract_p('properties.rights', d, None),
         time_interval_of_interest=TimeIntervalFormat.from_string(
             extract_p('properties.date', d, None)),
         keywords=[OwcCategory.from_dict(do) for do in
                   extract_p('properties.categories', d, [])],
         resources=[OwcResource.from_dict(do) for do in
                    extract_p('features', d, [])]
     )
예제 #5
0
def test_time_interval_format():
    single_date_str = "2013-11-02T15:24:24.446+12:00"
    interval_date_str = "2011-11-04T00:01:23Z/2017-12-05T17:28:56Z"
    bogus = "2011-11-04"

    ti1 = TimeIntervalFormat.from_string(single_date_str)
    assert isinstance(ti1.start, datetime)
    logger.debug(ti1.__str__())
    logger.debug(ti1.start.isoformat())

    ti2 = TimeIntervalFormat.from_string(interval_date_str)
    assert isinstance(ti2.start, datetime)
    assert isinstance(ti2.end, datetime)
    logger.debug(ti2.__str__())
    logger.debug(ti2.end.isoformat())

    ti3 = TimeIntervalFormat.from_string(bogus)
    assert isinstance(ti3.start, datetime)
    logger.debug(ti3.__str__())
예제 #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"