Exemplo n.º 1
0
def test_encoding():
    import os
    from ogcserver.configparser import SafeConfigParser
    from ogcserver.WMS import BaseWMSFactory
    from ogcserver.wms111 import ServiceHandler as ServiceHandler111
    from ogcserver.wms130 import ServiceHandler as ServiceHandler130

    base_path, tail = os.path.split(__file__)
    file_path = os.path.join(base_path, 'mapfile_encoding.xml')
    wms = BaseWMSFactory()
    wms.loadXML(file_path)
    wms.finalize()

    conf = SafeConfigParser()
    conf.readfp(open(os.path.join(base_path, 'ogcserver.conf')))

    wms111 = ServiceHandler111(conf, wms, "localhost")
    response = wms111.GetCapabilities({})
    # Check the response is encoded in UTF-8
    # Search for the title in the response
    if conf.get('service', 'title') not in response.content:
        raise Exception('GetCapabilities is not correctly encoded')

    wms130 = ServiceHandler130(conf, wms, "localhost")
    wms130.GetCapabilities({})

    return True
Exemplo n.º 2
0
def ServiceHandlerFactory(conf, mapfactory, onlineresource, version):

    if not version:
        version = common.Version()
    else:
        version = common.Version(version)
    if version >= '1.3.0':
        return ServiceHandler130(conf, mapfactory, onlineresource)
    else:
        return ServiceHandler111(conf, mapfactory, onlineresource)
Exemplo n.º 3
0
def _wms_services(mapfile):
    base_path, tail = os.path.split(__file__)
    file_path = os.path.join(base_path, mapfile)
    wms = BaseWMSFactory()

    # Layer 'awkward-layer' contains a regular style named 'default', which will
    # be hidden by OGCServer's auto-generated 'default' style. A warning message
    # is written to sys.stderr in loadXML.
    # Since we don't want to see this several times while unit testing (nose only
    # redirects sys.stdout), we redirect sys.stderr here into a StringIO buffer
    # temporarily.
    # As a side effect, we can as well search for the warning message and fail the
    # test, if it occurs zero or more than one times per loadXML invocation. However,
    # this test highly depends on the warning message text.
    stderr = sys.stderr
    errbuf = StringIO.StringIO()
    sys.stderr = errbuf

    wms.loadXML(file_path)

    sys.stderr = stderr
    errbuf.seek(0)
    warnings = 0
    for line in errbuf:
        if line.strip('\r\n') == multi_style_err_text:
            warnings += 1
        else:
            sys.stderr.write(line)
    errbuf.close()

    if warnings == 0:
        raise Exception(
            'Expected warning message for layer \'awkward-layer\' not found in stderr stream.'
        )
    elif warnings > 1:
        raise Exception(
            'Expected warning message for layer \'awkward-layer\' occurred several times (%d) in stderr stream.'
            % warnings)

    wms.finalize()

    conf = SafeConfigParser()
    conf.readfp(open(os.path.join(base_path, 'ogcserver.conf')))

    wms111 = ServiceHandler111(conf, wms, "localhost")
    wms130 = ServiceHandler130(conf, wms, "localhost")

    return (conf, {'1.1.1': wms111, '1.3.0': wms130})
Exemplo n.º 4
0
def _wms_services(mapfile):
    base_path, tail = os.path.split(__file__)
    file_path = os.path.join(base_path, mapfile)
    wms = BaseWMSFactory() 
    wms.loadXML(file_path)
    wms.finalize()

    conf = SafeConfigParser()
    conf.readfp(open(os.path.join(base_path, 'ogcserver.conf')))

    wms111 = ServiceHandler111(conf, wms, "localhost")
    wms130 = ServiceHandler130(conf, wms, "localhost")

    return (conf, {
        '1.1.1': wms111,
        '1.3.0': wms130
    })
Exemplo n.º 5
0
def _wms_capabilities():
    base_path, tail = os.path.split(__file__)
    file_path = os.path.join(base_path, 'mapfile_encoding.xml')
    wms = BaseWMSFactory()
    wms.loadXML(file_path)
    wms.finalize()

    conf = SafeConfigParser()
    conf.readfp(open(os.path.join(base_path, 'ogcserver.conf')))

    wms111 = ServiceHandler111(conf, wms, "localhost")
    wms130 = ServiceHandler130(conf, wms, "localhost")

    return (conf, {
        '1.1.1': wms111.GetCapabilities({}),
        '1.3.0': wms130.GetCapabilities({})
    })
Exemplo n.º 6
0
def test_encoding():
    import os
    from ogcserver.configparser import SafeConfigParser
    from ogcserver.WMS import BaseWMSFactory
    from ogcserver.wms111 import ServiceHandler as ServiceHandler111
    from ogcserver.wms130 import ServiceHandler as ServiceHandler130

    base_path, tail = os.path.split(__file__)
    file_path = os.path.join(base_path, 'shape_encoding.xml')
    wms = BaseWMSFactory()
    wms.loadXML(file_path)
    wms.finalize()

    conf = SafeConfigParser()
    conf.readfp(open(os.path.join(base_path, 'ogcserver.conf')))

    # srs = EPSG:4326
    # 3.00 , 42,35 - 3.15 , 42.51
    # x = 5 , y = 6
    params = {}
    params['srs'] = 'epsg:4326'
    params['x'] = 5
    params['y'] = 5
    params['bbox'] = [3.00, 42.35, 3.15, 42.51]
    params['height'] = 10
    params['width'] = 10
    params['layers'] = ['row']
    params['styles'] = ''
    params['query_layers'] = ['row']

    for format in ['text/plain', 'text/xml']:
        params['info_format'] = format
        wms111 = ServiceHandler111(conf, wms, "localhost")
        result = wms111.GetFeatureInfo(params)

        wms130 = ServiceHandler130(conf, wms, "localhost")
        wms130.GetCapabilities({})

    return True