Пример #1
0
def test_url_background_color():
    conf, services = _wms_services('mapfile_background-color.xml')

    reqparams = {
        'srs': 'EPSG:4326',
        'bbox': '-180.0000,-90.0000,180.0000,90.0000',
        'width': 800,
        'height': 600,
        'layers': '__all__',
        'styles': '',
        'format': 'image/png',
        'bgcolor': '0x00FF00',
    }

    from ogcserver.WMS import ServiceHandlerFactory
    mapfactory = BaseWMSFactory() 
    servicehandler = ServiceHandlerFactory(conf, mapfactory, '', '1.1.1')
    ogcparams = servicehandler.processParameters('GetMap', reqparams)
    ogcparams['crs'] = ogcparams['srs']
    ogcparams['HTTP_USER_AGENT'] = 'unit_tests'

    m = services['1.1.1']._buildMap(ogcparams)
    print 'wms 1.1.1 backgound color: %s' % m.background
    assert m.background == ColorFactory('rgb(0,255,0)')

    m = services['1.3.0']._buildMap(ogcparams)
    print 'wms 1.3.0 backgound color: %s' % m.background
    assert m.background == ColorFactory('rgb(0,255,0)')
Пример #2
0
def test_map():
    from ogcserver.WMS import ServiceHandlerFactory

    reqparams = {
        'srs': 'EPSG:4326',
        'bbox': '-180.0000,-90.0000,180.0000,90.0000',
        'width': 800,
        'height': 600,
        'layers': '__all__',
        'styles': '',
        'format': 'image/png',
    }

    def check_map_styles(version, no, layer, style_param, styles=None):

        print 'GetMap %s: layer #%d \'%s\': STYLES=%s' % (version, no, layer,
                                                          style_param)

        ogcparams['layers'] = layer.split(',')
        ogcparams['styles'] = style_param.split(',')

        # Parameter 'styles' contains the list of expected styles. If styles
        # evaluates to False (e.g. None, Null), an invalid STYLE was provided
        # and so, an OGCException 'StyleNotDefined' is expected.
        try:
            m = services[version]._buildMap(ogcparams)
        except OGCException:
            if not styles:
                print '              style #0 \'invalid style\': OK (caught OGCException)'
                print
                return
            raise Exception(
                'GetMap %s: Expected OGCExecption for invalid style \'%s\' for layer #%d \'%s\' was not thrown.'
                % (version, style_param, no, layer))

        _check_style_lists('GetMap', version, no, layer, m.layers[0].styles,
                           styles)
        print

    conf, services = _wms_services('mapfile_styles.xml')

    mapfactory = BaseWMSFactory()
    servicehandler = ServiceHandlerFactory(conf, mapfactory, '', '1.1.1')
    ogcparams = servicehandler.processParameters('GetMap', reqparams)
    ogcparams['crs'] = ogcparams['srs']
    ogcparams['HTTP_USER_AGENT'] = 'unit_tests'

    for version in ['1.1.1', '1.3.0']:
        check_map_styles(version, 1, 'single-style-layer', '',
                         ['simple-style'])
        check_map_styles(version, 1, 'single-style-layer', 'simple-style',
                         ['simple-style'])
        check_map_styles(version, 1, 'single-style-layer', 'default')
        check_map_styles(version, 1, 'single-style-layer', 'invalid-style')

        check_map_styles(version, 2, 'multi-style-layer', '',
                         ['simple-style', 'another-style'])
        check_map_styles(version, 2, 'multi-style-layer', 'default',
                         ['simple-style', 'another-style'])
        check_map_styles(version, 2, 'multi-style-layer', 'simple-style',
                         ['simple-style'])
        check_map_styles(version, 2, 'multi-style-layer', 'another-style',
                         ['another-style'])
        check_map_styles(version, 2, 'multi-style-layer', 'invalid-style')

        check_map_styles(version, 3, 'awkward-layer', '',
                         ['default', 'another-style'])
        check_map_styles(version, 3, 'awkward-layer', 'default',
                         ['default', 'another-style'])
        check_map_styles(version, 3, 'awkward-layer', 'another-style',
                         ['another-style'])
        check_map_styles(version, 3, 'awkward-layer', 'invalid-style')

        check_map_styles(version, 4, 'single-default-layer', '', ['default'])
        check_map_styles(version, 4, 'single-default-layer', 'default',
                         ['default'])
        check_map_styles(version, 4, 'single-default-layer', 'invalid-style')

        # Some 'manually' created error cases for testing error reporting
        #check_map_styles(version, 2, 'multi-style-layer', 'default', ['simple-style', 'another-style', 'foo', 'bar'])
        #check_map_styles(version, 2, 'multi-style-layer', 'default', ['simple-style'])

    return True