Imports and initialize

    >>> from __future__ import (absolute_import, division, print_function)
    >>> from owslib.wfs import WebFeatureService
    >>> try:
    ...     from urlparse import urlparse
    ... except ImportError:
    ...     from urllib.parse import urlparse
    >>> from tests.utils import resource_file, sorted_url_query

    >>> getcapsin = open(resource_file("wfs_HSRS_GetCapabilities_1_1_0.xml"), "rb").read()
    >>> wfs = WebFeatureService('http://gis.bnhelp.cz/ows/crwfs', xml=getcapsin, version='1.1.0')

Test the capabilities info
    >>> wfs.identification.service
    'OGC WFS'
    >>> wfs.identification.version
    '1.1.0'
    >>> wfs.identification.title
    'Help Service Gazeteer'
    >>> wfs.identification.abstract
    'Vyhledavani sidel WFS'
    >>> wfs.identification.keywords
    ['Czech republic', 'gazeeteer']
    >>> wfs.identification.fees
    'none'
    >>> wfs.identification.accessconstraints
    'for non profit use'
    >>> wfs.provider.name
    'Help Service Remote Sensing, ltd.'
    >>> wfs.provider.url
    'http://www.hsrs.cz'
    >>> wfs.provider.contact.email
    >>> wfs.provider.contact.phone
    >>> wfs.provider.contact.name   #doctest: +SKIP
    u'Stanislav Hol\xfd'
    >>> wfs.provider.contact.organization
    >>> wfs.provider.contact.city
    >>> wfs.provider.contact.region
    >>> wfs.provider.contact.postcode
    >>> wfs.provider.contact.country

Test the getfeature method

    >>> sorted(wfs.contents.keys())
    ['kraje', 'nuts1', 'nuts2', 'nuts3', 'okresy', 'orp', 'sidla', 'states']

    >>> wfs.contents['okresy'].crsOptions[0].getcodeurn()
    'urn:ogc:def:crs:EPSG::4326'

    >>> sorted_url_query(wfs.getGETGetFeatureRequest(typename=['okresy'], maxfeatures=2))
    ['maxfeatures=2', 'request=GetFeature', 'service=WFS', 'typename=okresy', 'version=1.1.0']

    >>> sorted_url_query(wfs.getGETGetFeatureRequest(typename=['okresy'], maxfeatures=2, bbox=[15,49,16,51,'urn:ogc:def:crs:EPSG:4326']))
    ['bbox=49%2C15%2C51%2C16%2Curn%3Aogc%3Adef%3Acrs%3AEPSG%3A%3A4326', 'maxfeatures=2', 'request=GetFeature', 'service=WFS', 'typename=okresy', 'version=1.1.0']

    >>> sorted_url_query(wfs.getGETGetFeatureRequest(typename=['okresy'], maxfeatures=2, bbox=[-685336,-993518,-684996,-993285]))
    ['bbox=-993518%2C-685336%2C-993285%2C-684996%2Curn%3Aogc%3Adef%3Acrs%3AEPSG%3A%3A4326', 'maxfeatures=2', 'request=GetFeature', 'service=WFS', 'typename=okresy', 'version=1.1.0']


Test outputFormat

WFS 1.0.0
    >>> import json
    >>> wfs = WebFeatureService('https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288', version='1.0.0')
    >>> feature = wfs.getfeature(typename=['sb:Project_Area'], maxfeatures=1, propertyname=None, outputFormat='application/json')
    >>> json.dumps(json.loads(feature.read()))
    '{...}'

WFS 1.1.0
    >>> import json
    >>> wfs = WebFeatureService('https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288', version='1.1.0')
    >>> feature = wfs.getfeature(typename=['sb:Project_Area'], maxfeatures=1, propertyname=None, outputFormat='application/json')
    >>> json.dumps(json.loads(feature.read()))
    '{...}'

WFS 2.0.0
    >>> import json
    >>> wfs = WebFeatureService('https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288', version='2.0.0')
    >>> feature = wfs.getfeature(typename=['sb:Project_Area'], maxfeatures=1, propertyname=None, outputFormat='application/json')
    >>> json.dumps(json.loads(feature.read()))
    '{...}'


Test srsName

WFS 1.0.0
    >>> import json
    >>> wfs = WebFeatureService('https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288', version='1.0.0')
    >>> feature = wfs.getfeature(typename=['sb:Project_Area'], maxfeatures=1, propertyname=None, outputFormat='application/json', srsname="EPSG:99999999")  #doctest: +IGNORE_EXCEPTION_DETAIL
    ...
    Traceback (most recent call last):
    ...
    ServiceException: Unable to support srsName: EPSG:99999999
    ...

    >>> import json
    >>> wfs = WebFeatureService('https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288', version='1.0.0')
    >>> feature = wfs.getfeature(typename=['sb:Project_Area'], maxfeatures=1, propertyname=None, outputFormat='application/json', srsname="urn:x-ogc:def:crs:EPSG:4326")
    >>> json.dumps(json.loads(feature.read()))
    '{...}'

WFS 1.1.0
    >>> import json
    >>> wfs = WebFeatureService('https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288', version='1.1.0')
    >>> feature = wfs.getfeature(typename=['sb:Project_Area'], maxfeatures=1, propertyname=None, outputFormat='application/json', srsname="EPSG:99999999")  #doctest: +IGNORE_EXCEPTION_DETAIL
    ...
    Traceback (most recent call last):
    ...
    ServiceException: SRSNAME EPSG:99999999 not supported.  Options: urn:x-ogc:def:crs:EPSG:102715

    >>> import json
    >>> wfs = WebFeatureService('https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288', version='1.0.0')
    >>> feature = wfs.getfeature(typename=['sb:Project_Area'], maxfeatures=1, propertyname=None, outputFormat='application/json', srsname="urn:x-ogc:def:crs:EPSG:4326")
    >>> json.dumps(json.loads(feature.read()))
    '{...}'
