Skip to content

Commit

Permalink
Fix up metadata URL tests
Browse files Browse the repository at this point in the history
- Some 'Offline' tests were still calling on external services, monkeypatch of 'OpenURL' not working
- Fixed up monkeypatch of 'OpenURL' calls
- Added function to detect outer tag for iso_3.py
- Added code to utilise iso_3 in WFS/WMS GetCapabilities responses
- Added ISO 19115 Part 3 XML tests using pytest parameters
  • Loading branch information
vjf committed Jan 7, 2024
1 parent 32daa95 commit 3b58df6
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 51 deletions.
4 changes: 1 addition & 3 deletions owslib/feature/wfs100.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,7 @@ def parse_remote_metadata(self, timeout=30):
if mdelem is not None:
metadataUrl["metadata"] = MD_Metadata(mdelem)
else:
mdelem = doc.find(
".//" + util.nspath_eval("mdb:MD_Metadata", n.get_namespaces(["mdb"]))
)
mdelem = MD_Metadata_3.find_start(doc)
if mdelem is not None:
metadataUrl["metadata"] = MD_Metadata_3(mdelem)
else:
Expand Down
10 changes: 7 additions & 3 deletions owslib/feature/wfs110.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
testXMLValue,
nspath_eval,
ServiceException,
Authentication,
# openURL,
Authentication
)
from owslib.etree import etree
from owslib.fgdc import Metadata
from owslib.iso import MD_Metadata
from owslib.iso_3 import MD_Metadata as MD_Metadata_3 # ISO 19115 Part 3 XML
from owslib.ows import (
OwsCommon,
ServiceIdentification,
Expand Down Expand Up @@ -488,6 +488,10 @@ def parse_remote_metadata(self, timeout=30):
if mdelem is not None:
metadataUrl["metadata"] = MD_Metadata(mdelem)
else:
metadataUrl["metadata"] = None
mdelem = MD_Metadata_3.find_start(doc)
if mdelem is not None:
metadataUrl["metadata"] = MD_Metadata_3(mdelem)
else:
metadataUrl["metadata"] = None
except Exception:
metadataUrl["metadata"] = None
8 changes: 4 additions & 4 deletions owslib/feature/wfs200.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from owslib import util
from owslib.fgdc import Metadata
from owslib.iso import MD_Metadata
from owslib.iso_3 import MD_Metadata as MD_Metadata_3
from owslib.iso_3 import MD_Metadata as MD_Metadata_3 # ISO 19115 Part 3 XML
from owslib.ows import Constraint, ServiceIdentification, ServiceProvider, OperationsMetadata
from owslib.etree import etree
from owslib.util import nspath, testXMLValue, openURL, Authentication
Expand Down Expand Up @@ -613,11 +613,11 @@ def parse_remote_metadata(self, timeout=30):
metadataUrl["metadata"] = MD_Metadata(mdelem)
continue
else: # ISO 19115 Part 3 XML
mdelem = doc.find(
".//" + util.nspath_eval("mdb:MD_Metadata", n.get_namespaces(["mdb"]))
)
mdelem = MD_Metadata_3.find_start(doc)
if mdelem is not None:
metadataUrl["metadata"] = MD_Metadata_3(mdelem)
else:
metadataUrl["metadata"] = None
continue
except Exception:
metadataUrl["metadata"] = None
14 changes: 14 additions & 0 deletions owslib/iso_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,20 @@ def __init__(self, md=None):
else:
self.dataquality = None

@staticmethod
def find_start(doc):
""" Tests for valid ISO 19115 Part 3 XML and returns the starting tag
:param doc: lxml Element object
:returns: 'mdb:MD_Metadata' lxml Element object
"""
mtags = doc.xpath("//mdb:MD_Metadata", namespaces=NAMESPACES_V2)
if len(mtags) > 0:
return mtags[0]
mtags = doc.xpath("//mdb:MD_Metadata", namespaces=NAMESPACES_V1)
if len(mtags) > 0:
return mtags[0]
return None

def get_all_contacts(self):
""" Get all contacts in identification part of document
Expand Down
8 changes: 4 additions & 4 deletions owslib/map/wms111.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
bind_url, nspath_eval, Authentication)
from owslib.fgdc import Metadata
from owslib.iso import MD_Metadata
from owslib.iso_3 import MD_Metadata_3
from owslib.iso_3 import MD_Metadata as MD_Metadata_3 # ISO 19115 Part 3 XML
from owslib.map.common import WMSCapabilitiesReader, AbstractContentMetadata
from owslib.namespaces import Namespaces

Expand Down Expand Up @@ -619,11 +619,11 @@ def parse_remote_metadata(self, timeout=30):
metadataUrl['metadata'] = MD_Metadata(mdelem)
continue
else: # ISO 19115 Part 3 XML
mdelem = doc.find(
".//" + nspath_eval("mdb:MD_Metadata", n.get_namespaces(["mdb"]))
)
mdelem = MD_Metadata_3.find_start(doc)
if mdelem is not None:
metadataUrl["metadata"] = MD_Metadata_3(mdelem)
else:
metadataUrl["metadata"] = None
continue
except Exception:
metadataUrl['metadata'] = None
Expand Down
6 changes: 2 additions & 4 deletions owslib/map/wms130.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
nspath_eval, bind_url, Authentication)
from owslib.fgdc import Metadata
from owslib.iso import MD_Metadata
from owslib.iso_3 import MD_Metadata_3
from owslib.iso_3 import MD_Metadata as MD_Metadata_3 # ISO 19115 Part 3 XML
from owslib.crs import Crs
from owslib.namespaces import Namespaces
from owslib.map.common import WMSCapabilitiesReader, AbstractContentMetadata
Expand Down Expand Up @@ -711,9 +711,7 @@ def parse_remote_metadata(self, timeout=30):
metadataUrl['metadata'] = MD_Metadata(mdelem)
continue
else:
mdelem = doc.find(
".//" + nspath_eval("mdb:MD_Metadata", n.get_namespaces(["mdb"]))
)
mdelem = MD_Metadata_3.find_start(doc)
if mdelem is not None:
metadataUrl["metadata"] = MD_Metadata_3(mdelem)
else:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_iso3_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,8 @@ def test_service2(emd):
assert(srv_ident.fees == "Resource > Service Details > Access Properties > Fees")

def test_md_distribution(emd):
""" Test MD_Distribution
"""
contact = emd.distribution.distributor[0].contact
assert contact.address =='Resource > Distribution > Distributor > Contact Information > Address'
assert contact.city =='Resource > Distribution > Distributor > Contact Information > City'
Expand Down
Loading

0 comments on commit 3b58df6

Please sign in to comment.