Skip to content

Commit b3d9214

Browse files
authored
Add None guard when checking for XML list elements with test (#1000)
1 parent 9dddeef commit b3d9214

File tree

3 files changed

+145
-2
lines changed

3 files changed

+145
-2
lines changed

owslib/util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,12 @@ def extract_time(element):
692692

693693
def extract_xml_list(elements):
694694
"""
695-
Some people don't have seperate tags for their keywords and seperate them with
695+
Some people don't have separate tags for their keywords and separate them with
696696
a newline. This will extract out all of the keywords correctly.
697697
"""
698+
if elements is None:
699+
return []
700+
698701
keywords = (re.split(r'[\n\r]+', f.text) for f in elements if f.text)
699702
flattened = (item.strip() for sublist in keywords for item in sublist)
700703
remove_blank = [_f for _f in flattened if _f]
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<WFS_Capabilities version="1.0.0" updateSequence="0" xmlns="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-capabilities.xsd">
3+
<Service>
4+
<Name>MapServer WFS</Name>
5+
<Title>WFS Demo Server for MapServer</Title>
6+
<Abstract>This demonstration server showcases MapServer (www.mapserver.org) and its OGC support</Abstract>
7+
<OnlineResource>https://demo.mapserver.org/cgi-bin/wfs?</OnlineResource>
8+
</Service>
9+
10+
<Capability>
11+
<Request>
12+
<GetCapabilities>
13+
<DCPType>
14+
<HTTP>
15+
<Get onlineResource="https://demo.mapserver.org/cgi-bin/wfs?"/>
16+
</HTTP>
17+
</DCPType>
18+
<DCPType>
19+
<HTTP>
20+
<Post onlineResource="https://demo.mapserver.org/cgi-bin/wfs?"/>
21+
</HTTP>
22+
</DCPType>
23+
</GetCapabilities>
24+
<DescribeFeatureType>
25+
<SchemaDescriptionLanguage>
26+
<XMLSCHEMA/>
27+
</SchemaDescriptionLanguage>
28+
<DCPType>
29+
<HTTP>
30+
<Get onlineResource="https://demo.mapserver.org/cgi-bin/wfs?"/>
31+
</HTTP>
32+
</DCPType>
33+
<DCPType>
34+
<HTTP>
35+
<Post onlineResource="https://demo.mapserver.org/cgi-bin/wfs?"/>
36+
</HTTP>
37+
</DCPType>
38+
</DescribeFeatureType>
39+
<GetFeature>
40+
<ResultFormat>
41+
<GML2/>
42+
<geojson/>
43+
</ResultFormat>
44+
<DCPType>
45+
<HTTP>
46+
<Get onlineResource="https://demo.mapserver.org/cgi-bin/wfs?"/>
47+
</HTTP>
48+
</DCPType>
49+
<DCPType>
50+
<HTTP>
51+
<Post onlineResource="https://demo.mapserver.org/cgi-bin/wfs?"/>
52+
</HTTP>
53+
</DCPType>
54+
</GetFeature>
55+
</Request>
56+
</Capability>
57+
58+
<FeatureTypeList>
59+
<Operations>
60+
<Query/>
61+
</Operations>
62+
<FeatureType>
63+
<Name>continents</Name>
64+
<Title>World continents</Title>
65+
<SRS>EPSG:4326</SRS>
66+
<LatLongBoundingBox minx="-180.000000" miny="-90.000000" maxx="180.000000" maxy="83.627419"/>
67+
<MetadataURL type="TC211" format="text/xml">https://demo.mapserver.org/cgi-bin/wfs?request=GetMetadata&amp;layer=continents</MetadataURL>
68+
</FeatureType>
69+
<FeatureType>
70+
<Name>cities</Name>
71+
<Title>World cities</Title>
72+
<SRS>EPSG:4326</SRS>
73+
<LatLongBoundingBox minx="-178.166667" miny="-54.800000" maxx="179.383333" maxy="78.933333"/>
74+
<MetadataURL type="TC211" format="text/xml">https://demo.mapserver.org/cgi-bin/wfs?request=GetMetadata&amp;layer=cities</MetadataURL>
75+
</FeatureType>
76+
</FeatureTypeList>
77+
78+
<ogc:Filter_Capabilities>
79+
<ogc:Spatial_Capabilities>
80+
<ogc:Spatial_Operators>
81+
<ogc:Equals/>
82+
<ogc:Disjoint/>
83+
<ogc:Touches/>
84+
<ogc:Within/>
85+
<ogc:Overlaps/>
86+
<ogc:Crosses/>
87+
<ogc:Intersect/>
88+
<ogc:Contains/>
89+
<ogc:DWithin/>
90+
<ogc:BBOX/>
91+
</ogc:Spatial_Operators>
92+
</ogc:Spatial_Capabilities>
93+
<ogc:Scalar_Capabilities>
94+
<ogc:Logical_Operators/>
95+
<ogc:Comparison_Operators>
96+
<ogc:Simple_Comparisons/>
97+
<ogc:Like/>
98+
<ogc:Between/>
99+
</ogc:Comparison_Operators>
100+
</ogc:Scalar_Capabilities>
101+
</ogc:Filter_Capabilities>
102+
103+
</WFS_Capabilities>

tests/test_wfs_schema.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@
88
WFS_SERVICE_URL = 'https://www.dov.vlaanderen.be/geoserver/wfs?request=GetCapabilities'
99

1010

11+
@pytest.fixture
12+
def mp_wfs_100(monkeypatch):
13+
"""Monkeypatch the call to the remote GetCapabilities request of WFS
14+
version 1.0.0.
15+
16+
Parameters
17+
----------
18+
monkeypatch : pytest.fixture
19+
PyTest monkeypatch fixture.
20+
21+
"""
22+
def read(*args, **kwargs):
23+
with open('tests/resources/wfs_mapserver_demo_getcapabilities_100.xml', 'r') as f:
24+
data = f.read()
25+
if type(data) is not bytes:
26+
data = data.encode('utf-8')
27+
data = etree.fromstring(data)
28+
return data
29+
30+
monkeypatch.setattr(
31+
owslib.feature.common.WFSCapabilitiesReader, 'read', read)
32+
33+
1134
@pytest.fixture
1235
def mp_wfs_110(monkeypatch):
1336
"""Monkeypatch the call to the remote GetCapabilities request of WFS
@@ -122,7 +145,21 @@ def test_schema_result(self, wfs_version):
122145

123146
class TestOffline(object):
124147
"""Class grouping offline tests for the WFS get_schema method."""
125-
def test_get_schema(self, mp_wfs_110, mp_remote_describefeaturetype):
148+
def test_get_schema_100(self, mp_wfs_100):
149+
"""Test the get_schema method for a standard schema.
150+
151+
Parameters
152+
----------
153+
mp_wfs_100 : pytest.fixture
154+
Monkeypatch the call to the remote GetCapabilities request.
155+
"""
156+
wfs100 = WebFeatureService(WFS_SERVICE_URL, version='1.0.0')
157+
assert wfs100.identification.title == 'WFS Demo Server for MapServer'
158+
assert wfs100.identification.keywords == []
159+
assert list(wfs100.contents) == ['continents', 'cities']
160+
161+
162+
def test_get_schema(self, mp_wfs_100, mp_remote_describefeaturetype):
126163
"""Test the get_schema method for a standard schema.
127164
128165
Parameters

0 commit comments

Comments
 (0)