Skip to content

Commit

Permalink
Add CSW geonetwork tests for iso_3.py
Browse files Browse the repository at this point in the history
  • Loading branch information
vjf committed Jan 8, 2024
1 parent 0b1a676 commit a4067e9
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 12 deletions.
8 changes: 3 additions & 5 deletions owslib/catalogue/csw2.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,9 @@ def _parserecords(self, outputschema, esn):
val = i.find(util.nspath_eval('gm03:fileIdentifier', namespaces))
identifier = self._setidentifierkey(util.testXMLValue(val))
self.records[identifier] = GM03(i)
elif outputschema == namespaces['mdb']: # ISO 19115 Part 3 XML
for i in self._exml.findall('.//' + util.nspath_eval('mdb:MD_Metadata', namespaces)):
val = i.find(util.nspath_eval('mdb:metadataIdentifier/mcc:MD_Identifier/mcc:code/gco:CharacterString', namespaces))
identifier = self._setidentifierkey(util.testXMLValue(val))
self.records[identifier] = MD_Metadata_3(i)
elif MD_Metadata_3.handles(outputschema): # ISO 19115 Part 3 XML
for elem, id in MD_Metadata_3.find_ids(self._exml):
self.records[self._setidentifierkey(id)] = MD_Metadata_3(elem)
for i in self._exml.findall('.//' + util.nspath_eval('gfc:FC_FeatureCatalogue', namespaces)):
identifier = self._setidentifierkey(util.testXMLValue(i.attrib['uuid'], attrib=True))
self.records[identifier] = FC_FeatureCatalogue_3(i)
Expand Down
8 changes: 3 additions & 5 deletions owslib/catalogue/csw3.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,9 @@ def _parserecords(self, outputschema, esn):
val = i.find(util.nspath_eval('gm03:fileIdentifier', namespaces))
identifier = self._setidentifierkey(util.testXMLValue(val))
self.records[identifier] = GM03(i)
elif outputschema == namespaces['mdb']: # ISO 19115 Part 3 XML
for i in self._exml.findall('.//' + util.nspath_eval('mdb:MD_Metadata', namespaces)):
val = i.find(util.nspath_eval('mdb:metadataIdentifier/mcc:MD_Identifier/mcc:code/gco:CharacterString', namespaces))
identifier = self._setidentifierkey(util.testXMLValue(val))
self.records[identifier] = MD_Metadata_3(i)
elif MD_Metadata_3.handles(outputschema): # ISO 19115 Part 3 XML
for elem, id in MD_Metadata_3.find_ids(self._exml):
self.records[self._setidentifierkey(id)] = MD_Metadata_3(elem)
for i in self._exml.findall('.//' + util.nspath_eval('gfc:FC_FeatureCatalogue', namespaces)):
identifier = self._setidentifierkey(util.testXMLValue(i.attrib['uuid'], attrib=True))
self.records[identifier] = FC_FeatureCatalogue_3(i)
Expand Down
27 changes: 27 additions & 0 deletions owslib/iso_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,33 @@ def find_start(doc):
return mtags[0]
return None

@staticmethod
def handles(outputschema):
""" Returns True iff the outputschema is handled by this class
:param outputschema: outputschema parameter string
:returns: True iff the outputschema is handled by this class
"""
return outputschema == NAMESPACES_V1['mdb'] or \
outputschema == NAMESPACES_V2['mdb']

@staticmethod
def find_ids(elemtree):
""" Finds identifer strings and outer 'mdb:MD_Metadata' Elements
:param elemtree: lxml.ElementTree to search in
:returns: a list of tuples (id string, 'mdb:MD_Metadata' lxml.Element)
"""
for ns in [NAMESPACES_V2, NAMESPACES_V1]:
elems = elemtree.findall('.//' + util.nspath_eval('mdb:MD_Metadata', ns))
if len(elems) > 0:
ret_list = []
for i in elems:
val = i.find(util.nspath_eval('mdb:metadataIdentifier/mcc:MD_Identifier/mcc:code/gco:CharacterString', NAMESPACES_V2))
ret_list.append((i, util.testXMLValue(val)))
return ret_list
return []

def get_all_contacts(self):
""" Get all contacts in identification part of document
Expand Down
21 changes: 21 additions & 0 deletions tests/test_csw_geonetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,24 @@ def test_csw_geonetwork():
assert c.results.get('returned') > 0
assert c.results.get('nextrecord') > 0
assert c.results.get('matches') > 0

SERVICE_URL3 = 'https://metawal.wallonie.be/geonetwork/srv/eng/csw'

@pytest.mark.skipif(not service_ok(SERVICE_URL3),
reason='service is unreachable')
@pytest.mark.parametrize("esn_in", ['full', 'summary'])
def test_csw_geonetwork_iso_3(esn_in):
""" Test retrieving records from Belgian geonetwork,
specifically requesting ISO 19115 Part 3 XML records.
"""
c = CatalogueServiceWeb(SERVICE_URL3)
c.getrecords2(outputschema='http://standards.iso.org/iso/19115/-3/mdb/2.0',
typenames='mdb:MD_Metadata',
esn=esn_in)

# Valid results were returned
assert c.results.get('returned') > 0
assert c.results.get('nextrecord') > 0
assert c.results.get('matches') > 0
for id in c.records.keys():
assert c.records[id].identifier == id
2 changes: 0 additions & 2 deletions tests/test_remote_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,12 @@ def read(*args, **kwargs):
def openURL(*args, **kwargs):
""" Used to patch the 'openURL' call, returning ISO 19139 XML
"""
print("@patch openURL")
return open('tests/resources/csw_dov_getrecordbyid.xml', 'rb')


def openURL_3(*args, **kwargs):
""" Used to patch the 'openURL' call, returning ISO 19115 Part 3 XML
"""
print("@patch openURL_3")
return open('tests/resources/iso3_examples/auscope-3d-model.xml', 'rb')


Expand Down

0 comments on commit a4067e9

Please sign in to comment.