Esempio n. 1
0
    def _get_children(self, theme, layers, wms, wms_layers, version, catalogue, min_levels):
        children = []
        errors = set()
        for item in theme.children:
            if type(item) == LayerGroup:
                time = TimeInformation()
                gp, gp_errors = self._group(
                    "%s/%s" % (theme.name, item.name),
                    item, layers, time=time, wms=wms, wms_layers=wms_layers,
                    version=version, catalogue=catalogue, min_levels=min_levels
                )
                errors |= gp_errors

                if gp is not None:
                    if time.has_time() and time.layer is None:
                        gp["time"] = time.to_dict()
                    children.append(gp)
            elif self._layer_included(item, version):
                if min_levels > 0:
                    errors.add("The Layer '%s' cannot be directly in the theme '%s' (0/%i)." % (
                        item.name, theme.name, min_levels
                    ))
                elif item.name in layers:
                    time = TimeInformation()
                    l, l_errors = self._layer(
                        item, time=time, wms=wms, wms_layers=wms_layers
                    )
                    errors |= l_errors
                    children.append(l)
        return children, errors
Esempio n. 2
0
    def _getChildren(self, theme, layers, wms_layers, wms):
        children = []
        errors = []
        for item in sorted(theme.children, key=lambda item: item.order):
            if type(item) == LayerGroup:
                time = TimeInformation()
                gp, gp_errors, stop = self._group(item, layers, wms_layers,
                                                  wms, time)
                errors += gp_errors
                if stop:
                    errors.append(
                        "Themes listing interrupted because of an error"
                        " with theme \"%s\"" % theme.name)
                    return children, errors, True

                if gp is not None:
                    if time.has_time():
                        gp.update({"time": time.to_dict()})  # pragma nocover
                    children.append(gp)
            elif type(item) == Layer:
                if item in layers:
                    time = TimeInformation()
                    l, l_errors = self._layer(item, wms_layers, wms, time)
                    if time.has_time():
                        l.update({"time": time.to_dict()})  # pragma nocover
                    errors += l_errors
                    children.append(l)
        return children, errors, False
Esempio n. 3
0
 def test_merge_modes(self):
     from c2cgeoportal.lib.wmstparsing import TimeInformation
     ti = TimeInformation()
     self.assertFalse(ti.has_time())
     self.assertTrue(ti.to_dict() is None)
     ti.merge_mode("single")
     self.assertEqual(ti.mode, "single")
     ti.merge_mode("single")
     self.assertEqual(ti.mode, "single")
Esempio n. 4
0
 def test_merge_modes(self):
     from c2cgeoportal.lib.wmstparsing import TimeInformation
     ti = TimeInformation()
     self.assertFalse(ti.has_time())
     self.assertTrue(ti.to_dict() is None)
     ti.merge_mode('single')
     self.assertEqual(ti.mode, 'single')
     ti.merge_mode('single')
     self.assertEqual(ti.mode, 'single')
Esempio n. 5
0
    def _getChildren(self, theme, layers, wms_layers, wms):
        children = []
        errors = []
        for item in sorted(theme.children, key=lambda item: item.order):
            if type(item) == LayerGroup:
                time = TimeInformation()
                gp, gp_errors, stop = self._group(item, layers, wms_layers, wms, time)
                errors += gp_errors
                if stop:
                    errors.append("Themes listing interrupted because of an error"
                                  " with theme \"%s\"" % theme.name)
                    return children, errors, True

                if gp is not None:
                    if time.has_time():
                        gp.update({"time": time.to_dict()})  # pragma nocover
                    children.append(gp)
            elif type(item) == Layer:
                if item in layers:
                    time = TimeInformation()
                    l, l_errors = self._layer(item, wms_layers, wms, time)
                    if time.has_time():
                        l.update({"time": time.to_dict()})  # pragma nocover
                    errors += l_errors
                    children.append(l)
        return children, errors, False
Esempio n. 6
0
 def test_merge_different_modes(self):
     from c2cgeoportal.lib.wmstparsing import TimeInformation
     ti = TimeInformation()
     ti.merge_mode('single')
     self.assertRaises(ValueError, ti.merge_mode, 'range')
Esempio n. 7
0
 def test_merge_different_widgets(self):
     from c2cgeoportal.lib.wmstparsing import TimeInformation
     ti = TimeInformation()
     ti.merge_widget("single")
     self.assertRaises(ValueError, ti.merge_widget, "datepicker")
Esempio n. 8
0
 def test_merge_different_modes(self):
     from c2cgeoportal.lib.wmstparsing import TimeInformation
     ti = TimeInformation()
     ti.merge_mode("single")
     self.assertRaises(ValueError, ti.merge_mode, "range")
 def test_merge_different_widgets(self):
     from c2cgeoportal.lib.wmstparsing import TimeInformation
     ti = TimeInformation()
     ti.merge_widget("single")
     self.assertRaises(ValueError, ti.merge_widget, "datepicker")
Esempio n. 10
0
    def test_layer(self):
        import httplib2
        from c2cgeoportal.views.entry import Entry
        from c2cgeoportal.models import Layer, LayerGroup
        from c2cgeoportal.lib.wmstparsing import TimeInformation

        request = self._create_request_obj()
        request.static_url = lambda name: '/dummy/static/' + name
        request.route_url = lambda name: '/dummy/route/' + name
        request.registry.settings['project'] = 'test_layer'
        entry = Entry(request)

        self.assertEqual(
            entry._group(LayerGroup(), [], [], None, TimeInformation()),
            (None, [], False))

        layer = Layer()
        layer.id = 20
        layer.name = 'test internal WMS'
        layer.metadataURL = "http://example.com/tiwms"
        layer.isChecked = True
        layer.layerType = "internal WMS"
        layer.imageType = "image/png"
        layer.style = "my-style"
        layer.kml = "tiwms.kml"
        layer.legend = True
        layer.legendRule = "rule"
        layer.legendImage = "legend:static/tiwms-legend.png"
        layer.isLegendExpanded = False
        layer.minResolution = 10
        layer.maxResolution = 1000
        layer.disclaimer = "Camptocamp"
        layer.identifierAttributeField = "name"
        layer.geoTable = "tiwms"
        layer.public = True
        self.assertEqual(entry._layer(layer, [], None, TimeInformation(
        )), ({
            'id': 20,
            'name': 'test internal WMS',
            'metadataURL': 'http://example.com/tiwms',
            'isChecked': True,
            'icon': '/dummy/route/mapserverproxy?SERVICE=WMS&VERSION=1.1.1&'
            'REQUEST=GetLegendGraphic&LAYER=test internal WMS&FORMAT=image/png&TRANSPARENT=TRUE&RULE=rule',
            'type': u'internal WMS',
            'imageType': 'image/png',
            'style': 'my-style',
            'kml': '/dummy/static/test_layer:static/tiwms.kml',
            'legend': True,
            'legendImage': '/dummy/static/legend:static/tiwms-legend.png',
            'isLegendExpanded': False,
            'minResolutionHint': 10,
            'maxResolutionHint': 1000,
            'disclaimer': 'Camptocamp',
            'identifierAttribute': 'name',
            'editable': True,
            'public': True,
        }, ['The layer test internal WMS is not defined in WMS capabilities']))

        layer = Layer()
        layer.id = 20
        layer.name = 'test external WMS'
        layer.isChecked = False
        layer.icon = "tewms.png"
        layer.layerType = "external WMS"
        layer.url = "http://example.com"
        layer.imageType = "image/jpeg"
        layer.isSingleTile = True
        layer.legend = False
        layer.isLegendExpanded = False
        layer.minResolution = 10
        layer.maxResolution = 1000
        layer.public = True
        self.assertEqual(entry._layer(
            layer, [], None, TimeInformation), ({
                'id': 20,
                'name': 'test external WMS',
                'icon': '/dummy/static/test_layer:static/tewms.png',
                'isChecked': False,
                'type': u'external WMS',
                'url': 'http://example.com',
                'imageType': 'image/jpeg',
                'isSingleTile': True,
                'legend': False,
                'isLegendExpanded': False,
                'minResolutionHint': 10,
                'maxResolutionHint': 1000,
                'public': True,
            }, []))

        layer = Layer()
        layer.id = 20
        layer.name = 'test WMTS'
        layer.isChecked = False
        layer.layerType = "WMTS"
        layer.url = "http://example.com/WMTS-Capabilities.xml"
        layer.style = 'wmts-style'
        layer.dimensions = '{"DATE": "1012"}'
        layer.matrixSet = "swissgrid"
        layer.wmsUrl = 'http://example.com/'
        layer.wmsLayers = 'test'
        layer.legend = False
        layer.isLegendExpanded = False
        layer.minResolution = 10
        layer.maxResolution = 1000
        layer.public = True
        self.assertEqual(entry._layer(layer, [], None, TimeInformation()),
                         ({
                             'id': 20,
                             'name': 'test WMTS',
                             'isChecked': False,
                             'type': 'WMTS',
                             'url': 'http://example.com/WMTS-Capabilities.xml',
                             'style': 'wmts-style',
                             'dimensions': {
                                 u'DATE': u'1012'
                             },
                             'matrixSet': 'swissgrid',
                             'wmsUrl': 'http://example.com/',
                             'wmsLayers': 'test',
                             'legend': False,
                             'isLegendExpanded': False,
                             'minResolutionHint': 10,
                             'maxResolutionHint': 1000,
                             'public': True,
                         }, []))

        layer = Layer()
        layer.id = 20
        layer.name = 'test WMTS'
        layer.isChecked = False
        layer.layerType = "WMTS"
        layer.url = "http://example.com/WMTS-Capabilities.xml"
        layer.wmsUrl = 'http://example.com/'
        layer.legend = False
        layer.isLegendExpanded = False
        layer.minResolution = 10
        layer.maxResolution = 1000
        layer.public = True
        self.assertEqual(entry._layer(layer, [], None, TimeInformation()),
                         ({
                             'id': 20,
                             'name': 'test WMTS',
                             'isChecked': False,
                             'type': 'WMTS',
                             'url': 'http://example.com/WMTS-Capabilities.xml',
                             'wmsUrl': 'http://example.com/',
                             'wmsLayers': 'test WMTS',
                             'legend': False,
                             'isLegendExpanded': False,
                             'minResolutionHint': 10,
                             'maxResolutionHint': 1000,
                             'public': True,
                         }, []))

        layer = Layer()
        layer.id = 20
        layer.name = 'test WMTS'
        layer.isChecked = False
        layer.layerType = "WMTS"
        layer.url = "http://example.com/WMTS-Capabilities.xml"
        layer.wmsLayers = 'test'
        layer.legend = False
        layer.isLegendExpanded = False
        layer.minResolution = 10
        layer.maxResolution = 1000
        layer.public = True
        self.assertEqual(entry._layer(layer, [], None, TimeInformation()),
                         ({
                             'id': 20,
                             'name': 'test WMTS',
                             'isChecked': False,
                             'type': 'WMTS',
                             'url': 'http://example.com/WMTS-Capabilities.xml',
                             'wmsUrl': '/dummy/route/mapserverproxy',
                             'wmsLayers': 'test',
                             'queryLayers': [],
                             'legend': False,
                             'isLegendExpanded': False,
                             'minResolutionHint': 10,
                             'maxResolutionHint': 1000,
                             'public': True,
                         }, []))

        layer = Layer()
        layer.id = 20
        layer.name = 'test no 2D'
        layer.isChecked = False
        layer.layerType = "no 2D"
        layer.legend = False
        layer.isLegendExpanded = False
        layer.metadataURL = 'http://example.com/wmsfeatures.metadata'
        layer.public = True
        self.assertEqual(entry._layer(
            layer, [], None, TimeInformation()), ({
                'id': 20,
                'name': u'test no 2D',
                'isChecked': False,
                'type': u'no 2D',
                'legend': False,
                'isLegendExpanded': False,
                'metadataURL': u'http://example.com/wmsfeatures.metadata',
                'public': True,
            }, []))

        curdir = os.path.dirname(os.path.abspath(__file__))
        mapfile = os.path.join(curdir, 'c2cgeoportal_test.map')

        mapfile = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               'c2cgeoportal_test.map')
        params = (
            ('map', mapfile),
            ('SERVICE', 'WMS'),
            ('VERSION', '1.1.1'),
            ('REQUEST', 'GetCapabilities'),
        )
        mapserv = "%s?map=%s&" % (mapserv_url, mapfile)
        url = mapserv + '&'.join(['='.join(p) for p in params])
        http = httplib2.Http()
        h = {'Host': host}
        resp, xml = http.request(url, method='GET', headers=h)

        wms = WebMapService(None, xml=xml)
        wms_layers = list(wms.contents)

        layer = Layer()
        layer.id = 20
        layer.name = 'test_wmsfeaturesgroup'
        layer.layerType = "internal WMS"
        layer.imageType = "image/png"
        layer.isChecked = False
        layer.legend = False
        layer.isLegendExpanded = False
        layer.public = True
        self.assertEqual(
            entry._layer(layer, wms_layers, wms, TimeInformation()), ({
                'id':
                20,
                'name':
                u'test_wmsfeaturesgroup',
                'type':
                u'internal WMS',
                'isChecked':
                False,
                'legend':
                False,
                'isLegendExpanded':
                False,
                'imageType':
                u'image/png',
                'minResolutionHint':
                1.76,
                'maxResolutionHint':
                8.8200000000000003,
                'public':
                True,
                'queryable':
                0,
                'metadataUrls': [{
                    'url': 'http://example.com/wmsfeatures.metadata',
                    'type': 'TC211',
                    'format': 'text/plain',
                }],
                'childLayers': [{
                    'name': u'test_wmsfeatures',
                    'minResolutionHint': 1.76,
                    'maxResolutionHint': 8.8200000000000003,
                    'queryable': 1,
                }],
            }, []))

        layer_t1 = Layer()
        layer_t1.id = 20
        layer_t1.name = 'test_wmstime'
        layer_t1.layerType = "internal WMS"
        layer_t1.imageType = "image/png"
        layer_t1.isChecked = False
        layer_t1.legend = False
        layer_t1.isLegendExpanded = False
        layer_t1.public = True
        layer_t1.timeMode = 'single'
        time = TimeInformation()
        entry._layer(layer_t1, wms_layers, wms, time)
        self.assertEqual(
            time.to_dict(), {
                'resolution': 'year',
                'interval': (1, 0, 0, 0),
                'maxValue': '2010-01-01T00:00:00Z',
                'minValue': '2000-01-01T00:00:00Z',
                'mode': 'single',
            })

        layer_t2 = Layer()
        layer_t2.id = 30
        layer_t2.name = 'test_wmstime2'
        layer_t2.layerType = "internal WMS"
        layer_t2.imageType = "image/png"
        layer_t2.isChecked = False
        layer_t2.legend = False
        layer_t2.isLegendExpanded = False
        layer_t2.public = True
        layer_t2.timeMode = 'single'
        time = TimeInformation()
        entry._layer(layer_t2, wms_layers, wms, time)
        self.assertEqual(
            time.to_dict(), {
                'resolution': 'year',
                'interval': (1, 0, 0, 0),
                'maxValue': '2020-01-01T00:00:00Z',
                'minValue': '2015-01-01T00:00:00Z',
                'mode': 'single',
            })

        group = LayerGroup()
        group.name = 'time'
        group.children = [layer_t1, layer_t2]
        time = TimeInformation()
        entry._group(group, [layer_t1, layer_t2], wms_layers, wms, time)
        self.assertEqual(
            time.to_dict(), {
                'resolution': 'year',
                'interval': (1, 0, 0, 0),
                'maxValue': '2020-01-01T00:00:00Z',
                'minValue': '2000-01-01T00:00:00Z',
                'mode': 'single',
            })

        layer = Layer()
        layer.id = 20
        layer.name = 'test_wmstimegroup'
        layer.layerType = "internal WMS"
        layer.imageType = "image/png"
        layer.isChecked = False
        layer.legend = False
        layer.isLegendExpanded = False
        layer.public = True
        layer.timeMode = 'single'
        time = TimeInformation()
        entry._layer(layer, wms_layers, wms, time)
        self.assertEqual(
            time.to_dict(), {
                'resolution': 'year',
                'interval': (1, 0, 0, 0),
                'maxValue': '2020-01-01T00:00:00Z',
                'minValue': '2000-01-01T00:00:00Z',
                'mode': 'single',
            })

        layer = Layer()
        layer.id = 20
        layer.name = 'test WMTS'
        layer.isChecked = False
        layer.layerType = "WMTS"
        layer.url = "http://example.com/WMTS-Capabilities.xml"
        layer.wmsLayers = 'test_wmsfeatures'
        layer.legend = False
        layer.isLegendExpanded = False
        layer.public = True
        self.assertEqual(
            entry._layer(layer, wms_layers, wms, TimeInformation()), ({
                'id':
                20,
                'name':
                'test WMTS',
                'isChecked':
                False,
                'type':
                'WMTS',
                'url':
                'http://example.com/WMTS-Capabilities.xml',
                'wmsUrl':
                '/dummy/route/mapserverproxy',
                'wmsLayers':
                'test_wmsfeatures',
                'queryLayers': [{
                    'name': 'test_wmsfeatures',
                    'minResolutionHint': 1.76,
                    'maxResolutionHint': 8.8200000000000003
                }],
                'legend':
                False,
                'isLegendExpanded':
                False,
                'public':
                True,
            }, []))

        layer = Layer()
        layer.id = 20
        layer.name = 'test WMTS'
        layer.isChecked = False
        layer.layerType = "WMTS"
        layer.url = "http://example.com/WMTS-Capabilities.xml"
        layer.wmsLayers = 'foo'
        layer.queryLayers = 'test_wmsfeatures'
        layer.legend = False
        layer.isLegendExpanded = False
        layer.public = True
        self.assertEqual(
            entry._layer(layer, wms_layers, wms, TimeInformation()), ({
                'id':
                20,
                'name':
                'test WMTS',
                'isChecked':
                False,
                'type':
                'WMTS',
                'url':
                'http://example.com/WMTS-Capabilities.xml',
                'wmsUrl':
                '/dummy/route/mapserverproxy',
                'wmsLayers':
                'foo',
                'queryLayers': [{
                    'name': 'test_wmsfeatures',
                    'minResolutionHint': 1.76,
                    'maxResolutionHint': 8.8200000000000003
                }],
                'legend':
                False,
                'isLegendExpanded':
                False,
                'public':
                True,
            }, []))

        group1 = LayerGroup()
        group1.name = 'block'
        group2 = LayerGroup()
        group2.name = 'node'
        group2.metadataURL = 'http://example.com/group.metadata'
        layer = Layer()
        layer.id = 20
        layer.name = 'test layer in group'
        layer.isChecked = False
        layer.layerType = "internal WMS"
        layer.imageType = "image/png"
        layer.legend = False
        layer.isLegendExpanded = False
        layer.public = True
        group1.children = [group2]
        group2.children = [layer]
        self.assertEqual(
            entry._group(group1, [layer], [], None, TimeInformation()), ({
                'isExpanded':
                False,
                'isInternalWMS':
                True,
                'name':
                u'block',
                'isBaseLayer':
                False,
                'children': [{
                    'isExpanded':
                    False,
                    'isInternalWMS':
                    True,
                    'name':
                    u'node',
                    'isBaseLayer':
                    False,
                    'metadataURL':
                    'http://example.com/group.metadata',
                    'children': [{
                        'name': u'test layer in group',
                        'id': 20,
                        'isChecked': False,
                        'type': u'internal WMS',
                        'legend': False,
                        'isLegendExpanded': False,
                        'imageType': u'image/png',
                        'public': True,
                    }]
                }]
            }, [
                'The layer test layer in group is not defined in WMS capabilities'
            ], False))

        group1 = LayerGroup()
        group1.isInternalWMS = True
        group2 = LayerGroup()
        group2.isInternalWMS = False
        group1.children = [group2]
        _, errors, stop = entry._group(group1, [], [], None, TimeInformation())
        self.assertTrue(len(errors) > 0)
        self.assertFalse(stop)

        group1 = LayerGroup()
        group1.isInternalWMS = False
        group2 = LayerGroup()
        group2.isInternalWMS = True
        group1.children = [group2]
        _, errors, stop = entry._group(group1, [], [], None, TimeInformation())
        self.assertTrue(len(errors) > 0)
        self.assertFalse(stop)

        group = LayerGroup()
        group.isInternalWMS = True
        layer = Layer()
        layer.layerType = 'internal WMS'
        group.children = [layer]
        _, errors, stop = entry._group(group, [layer], [], None,
                                       TimeInformation())
        self.assertEqual(len(errors), 1)
        self.assertEqual(errors[0],
                         "The layer  is not defined in WMS capabilities")
        self.assertFalse(stop)

        group = LayerGroup()
        group.isInternalWMS = True
        layer = Layer()
        layer.layerType = 'external WMS'
        group.children = [layer]
        _, errors, stop = entry._group(group, [layer], [], None,
                                       TimeInformation())
        self.assertTrue(len(errors) > 0)
        self.assertFalse(stop)

        group = LayerGroup()
        group.isInternalWMS = True
        layer = Layer()
        layer.layerType = 'WMTS'
        group.children = [layer]
        _, errors, stop = entry._group(group, [layer], [], None,
                                       TimeInformation())
        self.assertTrue(len(errors) > 0)
        self.assertFalse(stop)

        group = LayerGroup()
        group.isInternalWMS = True
        layer = Layer()
        layer.layerType = 'no 2D'
        group.children = [layer]
        _, errors, stop = entry._group(group, [layer], [], None,
                                       TimeInformation())
        self.assertTrue(len(errors) > 0)
        self.assertFalse(stop)

        group = LayerGroup()
        group.isInternalWMS = False
        layer = Layer()
        layer.layerType = 'internal WMS'
        group.children = [layer]
        _, errors, stop = entry._group(group, [layer], [], None,
                                       TimeInformation())
        self.assertTrue(len(errors) > 0)
        self.assertFalse(stop)

        group = LayerGroup()
        group.isInternalWMS = False
        layer = Layer()
        layer.layerType = 'external WMS'
        group.children = [layer]
        _, errors, stop = entry._group(group, [layer], [], None,
                                       TimeInformation())
        self.assertEqual(len(errors), 0)
        self.assertFalse(stop)

        group = LayerGroup()
        group.isInternalWMS = False
        layer = Layer()
        layer.layerType = 'WMTS'
        group.children = [layer]
        _, errors, stop = entry._group(group, [layer], [], None,
                                       TimeInformation())
        self.assertEqual(len(errors), 0)
        self.assertFalse(stop)

        group = LayerGroup()
        group.isInternalWMS = False
        layer = Layer()
        layer.layerType = 'no 2D'
        group.children = [layer]
        _, errors, stop = entry._group(group, [layer], [], None,
                                       TimeInformation())
        self.assertEqual(len(errors), 0)
        self.assertFalse(stop)
Esempio n. 11
0
    def test_layer(self):
        import httplib2
        from c2cgeoportal.views.entry import Entry
        from c2cgeoportal.models import Layer, LayerGroup
        from c2cgeoportal.lib.wmstparsing import TimeInformation

        request = self._create_request_obj()
        request.static_url = lambda name: '/dummy/static/' + name
        request.route_url = lambda name: '/dummy/route/' + name
        request.registry.settings['project'] = 'test_layer'
        entry = Entry(request)

        self.assertEqual(entry._group(LayerGroup(), [], [], None, TimeInformation()), (None, [], False))

        layer = Layer()
        layer.id = 20
        layer.name = 'test internal WMS'
        layer.metadataURL = "http://example.com/tiwms"
        layer.isChecked = True
        layer.layerType = "internal WMS"
        layer.imageType = "image/png"
        layer.style = "my-style"
        layer.kml = "tiwms.kml"
        layer.legend = True
        layer.legendRule = "rule"
        layer.legendImage = "legend:static/tiwms-legend.png"
        layer.isLegendExpanded = False
        layer.minResolution = 10
        layer.maxResolution = 1000
        layer.disclaimer = "Camptocamp"
        layer.identifierAttributeField = "name"
        layer.geoTable = "tiwms"
        layer.public = True
        self.assertEqual(entry._layer(layer, [], None, TimeInformation()), ({
            'id': 20,
            'name': 'test internal WMS',
            'metadataURL': 'http://example.com/tiwms',
            'isChecked': True,
            'icon': '/dummy/route/mapserverproxy?SERVICE=WMS&VERSION=1.1.1&'
            'REQUEST=GetLegendGraphic&LAYER=test internal WMS&FORMAT=image/png&TRANSPARENT=TRUE&RULE=rule',
            'type': u'internal WMS',
            'imageType': 'image/png',
            'style': 'my-style',
            'kml': '/dummy/static/test_layer:static/tiwms.kml',
            'legend': True,
            'legendImage': '/dummy/static/legend:static/tiwms-legend.png',
            'isLegendExpanded': False,
            'minResolutionHint': 10,
            'maxResolutionHint': 1000,
            'disclaimer': 'Camptocamp',
            'identifierAttribute': 'name',
            'editable': True,
            'public': True,
        }, ['The layer test internal WMS is not defined in WMS capabilities']))

        layer = Layer()
        layer.id = 20
        layer.name = 'test external WMS'
        layer.isChecked = False
        layer.icon = "tewms.png"
        layer.layerType = "external WMS"
        layer.url = "http://example.com"
        layer.imageType = "image/jpeg"
        layer.isSingleTile = True
        layer.legend = False
        layer.isLegendExpanded = False
        layer.minResolution = 10
        layer.maxResolution = 1000
        layer.public = True
        self.assertEqual(entry._layer(layer, [], None, TimeInformation), ({
            'id': 20,
            'name': 'test external WMS',
            'icon': '/dummy/static/test_layer:static/tewms.png',
            'isChecked': False,
            'type': u'external WMS',
            'url': 'http://example.com',
            'imageType': 'image/jpeg',
            'isSingleTile': True,
            'legend': False,
            'isLegendExpanded': False,
            'minResolutionHint': 10,
            'maxResolutionHint': 1000,
            'public': True,
        }, []))

        layer = Layer()
        layer.id = 20
        layer.name = 'test WMTS'
        layer.isChecked = False
        layer.layerType = "WMTS"
        layer.url = "http://example.com/WMTS-Capabilities.xml"
        layer.style = 'wmts-style'
        layer.dimensions = '{"DATE": "1012"}'
        layer.matrixSet = "swissgrid"
        layer.wmsUrl = 'http://example.com/'
        layer.wmsLayers = 'test'
        layer.legend = False
        layer.isLegendExpanded = False
        layer.minResolution = 10
        layer.maxResolution = 1000
        layer.public = True
        self.assertEqual(entry._layer(layer, [], None, TimeInformation()), ({
            'id': 20,
            'name': 'test WMTS',
            'isChecked': False,
            'type': 'WMTS',
            'url': 'http://example.com/WMTS-Capabilities.xml',
            'style': 'wmts-style',
            'dimensions': {u'DATE': u'1012'},
            'matrixSet': 'swissgrid',
            'wmsUrl': 'http://example.com/',
            'wmsLayers': 'test',
            'legend': False,
            'isLegendExpanded': False,
            'minResolutionHint': 10,
            'maxResolutionHint': 1000,
            'public': True,
        }, []))

        layer = Layer()
        layer.id = 20
        layer.name = 'test WMTS'
        layer.isChecked = False
        layer.layerType = "WMTS"
        layer.url = "http://example.com/WMTS-Capabilities.xml"
        layer.wmsUrl = 'http://example.com/'
        layer.legend = False
        layer.isLegendExpanded = False
        layer.minResolution = 10
        layer.maxResolution = 1000
        layer.public = True
        self.assertEqual(entry._layer(layer, [], None, TimeInformation()), ({
            'id': 20,
            'name': 'test WMTS',
            'isChecked': False,
            'type': 'WMTS',
            'url': 'http://example.com/WMTS-Capabilities.xml',
            'wmsUrl': 'http://example.com/',
            'wmsLayers': 'test WMTS',
            'legend': False,
            'isLegendExpanded': False,
            'minResolutionHint': 10,
            'maxResolutionHint': 1000,
            'public': True,
        }, []))

        layer = Layer()
        layer.id = 20
        layer.name = 'test WMTS'
        layer.isChecked = False
        layer.layerType = "WMTS"
        layer.url = "http://example.com/WMTS-Capabilities.xml"
        layer.wmsLayers = 'test'
        layer.legend = False
        layer.isLegendExpanded = False
        layer.minResolution = 10
        layer.maxResolution = 1000
        layer.public = True
        self.assertEqual(entry._layer(layer, [], None, TimeInformation()), ({
            'id': 20,
            'name': 'test WMTS',
            'isChecked': False,
            'type': 'WMTS',
            'url': 'http://example.com/WMTS-Capabilities.xml',
            'wmsUrl': '/dummy/route/mapserverproxy',
            'wmsLayers': 'test',
            'queryLayers': [],
            'legend': False,
            'isLegendExpanded': False,
            'minResolutionHint': 10,
            'maxResolutionHint': 1000,
            'public': True,
        }, []))

        layer = Layer()
        layer.id = 20
        layer.name = 'test no 2D'
        layer.isChecked = False
        layer.layerType = "no 2D"
        layer.legend = False
        layer.isLegendExpanded = False
        layer.metadataURL = 'http://example.com/wmsfeatures.metadata'
        layer.public = True
        self.assertEqual(entry._layer(layer, [], None, TimeInformation()), ({
            'id': 20,
            'name': u'test no 2D',
            'isChecked': False,
            'type': u'no 2D',
            'legend': False,
            'isLegendExpanded': False,
            'metadataURL': u'http://example.com/wmsfeatures.metadata',
            'public': True,
        }, []))

        curdir = os.path.dirname(os.path.abspath(__file__))
        mapfile = os.path.join(curdir, 'c2cgeoportal_test.map')

        mapfile = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            'c2cgeoportal_test.map'
        )
        params = (
            ('map', mapfile),
            ('SERVICE', 'WMS'),
            ('VERSION', '1.1.1'),
            ('REQUEST', 'GetCapabilities'),
        )
        mapserv = "%s?map=%s&" % (mapserv_url, mapfile)
        url = mapserv + '&'.join(['='.join(p) for p in params])
        http = httplib2.Http()
        h = {'Host': host}
        resp, xml = http.request(url, method='GET', headers=h)

        wms = WebMapService(None, xml=xml)
        wms_layers = list(wms.contents)

        layer = Layer()
        layer.id = 20
        layer.name = 'test_wmsfeaturesgroup'
        layer.layerType = "internal WMS"
        layer.imageType = "image/png"
        layer.isChecked = False
        layer.legend = False
        layer.isLegendExpanded = False
        layer.public = True
        self.assertEqual(entry._layer(layer, wms_layers, wms, TimeInformation()), ({
            'id': 20,
            'name': u'test_wmsfeaturesgroup',
            'type': u'internal WMS',
            'isChecked': False,
            'legend': False,
            'isLegendExpanded': False,
            'imageType': u'image/png',
            'minResolutionHint': 1.76,
            'maxResolutionHint': 8.8200000000000003,
            'public': True,
            'queryable': 0,
            'metadataUrls': [{
                'url': 'http://example.com/wmsfeatures.metadata',
                'type': 'TC211',
                'format': 'text/plain',
            }],
            'childLayers': [{
                'name': u'test_wmsfeatures',
                'minResolutionHint': 1.76,
                'maxResolutionHint': 8.8200000000000003,
                'queryable': 1,
            }],
        }, []))

        layer_t1 = Layer()
        layer_t1.id = 20
        layer_t1.name = 'test_wmstime'
        layer_t1.layerType = "internal WMS"
        layer_t1.imageType = "image/png"
        layer_t1.isChecked = False
        layer_t1.legend = False
        layer_t1.isLegendExpanded = False
        layer_t1.public = True
        layer_t1.timeMode = 'single'
        time = TimeInformation()
        entry._layer(layer_t1, wms_layers, wms, time)
        self.assertEqual(time.to_dict(), {
            'resolution': 'year',
            'interval': (1, 0, 0, 0),
            'maxValue': '2010-01-01T00:00:00Z',
            'minValue': '2000-01-01T00:00:00Z',
            'mode': 'single',
        })

        layer_t2 = Layer()
        layer_t2.id = 30
        layer_t2.name = 'test_wmstime2'
        layer_t2.layerType = "internal WMS"
        layer_t2.imageType = "image/png"
        layer_t2.isChecked = False
        layer_t2.legend = False
        layer_t2.isLegendExpanded = False
        layer_t2.public = True
        layer_t2.timeMode = 'single'
        time = TimeInformation()
        entry._layer(layer_t2, wms_layers, wms, time)
        self.assertEqual(time.to_dict(), {
            'resolution': 'year',
            'interval': (1, 0, 0, 0),
            'maxValue': '2020-01-01T00:00:00Z',
            'minValue': '2015-01-01T00:00:00Z',
            'mode': 'single',
        })

        group = LayerGroup()
        group.name = 'time'
        group.children = [layer_t1, layer_t2]
        time = TimeInformation()
        entry._group(group, [layer_t1, layer_t2], wms_layers, wms, time)
        self.assertEqual(time.to_dict(), {
            'resolution': 'year',
            'interval': (1, 0, 0, 0),
            'maxValue': '2020-01-01T00:00:00Z',
            'minValue': '2000-01-01T00:00:00Z',
            'mode': 'single',
        })

        layer = Layer()
        layer.id = 20
        layer.name = 'test_wmstimegroup'
        layer.layerType = "internal WMS"
        layer.imageType = "image/png"
        layer.isChecked = False
        layer.legend = False
        layer.isLegendExpanded = False
        layer.public = True
        layer.timeMode = 'single'
        time = TimeInformation()
        entry._layer(layer, wms_layers, wms, time)
        self.assertEqual(time.to_dict(), {
            'resolution': 'year',
            'interval': (1, 0, 0, 0),
            'maxValue': '2020-01-01T00:00:00Z',
            'minValue': '2000-01-01T00:00:00Z',
            'mode': 'single',
        })

        layer = Layer()
        layer.id = 20
        layer.name = 'test WMTS'
        layer.isChecked = False
        layer.layerType = "WMTS"
        layer.url = "http://example.com/WMTS-Capabilities.xml"
        layer.wmsLayers = 'test_wmsfeatures'
        layer.legend = False
        layer.isLegendExpanded = False
        layer.public = True
        self.assertEqual(entry._layer(layer, wms_layers, wms, TimeInformation()), ({
            'id': 20,
            'name': 'test WMTS',
            'isChecked': False,
            'type': 'WMTS',
            'url': 'http://example.com/WMTS-Capabilities.xml',
            'wmsUrl': '/dummy/route/mapserverproxy',
            'wmsLayers': 'test_wmsfeatures',
            'queryLayers': [{
                'name': 'test_wmsfeatures',
                'minResolutionHint': 1.76,
                'maxResolutionHint': 8.8200000000000003
            }],
            'legend': False,
            'isLegendExpanded': False,
            'public': True,
        }, []))

        layer = Layer()
        layer.id = 20
        layer.name = 'test WMTS'
        layer.isChecked = False
        layer.layerType = "WMTS"
        layer.url = "http://example.com/WMTS-Capabilities.xml"
        layer.wmsLayers = 'foo'
        layer.queryLayers = 'test_wmsfeatures'
        layer.legend = False
        layer.isLegendExpanded = False
        layer.public = True
        self.assertEqual(entry._layer(layer, wms_layers, wms, TimeInformation()), ({
            'id': 20,
            'name': 'test WMTS',
            'isChecked': False,
            'type': 'WMTS',
            'url': 'http://example.com/WMTS-Capabilities.xml',
            'wmsUrl': '/dummy/route/mapserverproxy',
            'wmsLayers': 'foo',
            'queryLayers': [{
                'name': 'test_wmsfeatures',
                'minResolutionHint': 1.76,
                'maxResolutionHint': 8.8200000000000003
            }],
            'legend': False,
            'isLegendExpanded': False,
            'public': True,
        }, []))

        group1 = LayerGroup()
        group1.name = 'block'
        group2 = LayerGroup()
        group2.name = 'node'
        group2.metadataURL = 'http://example.com/group.metadata'
        layer = Layer()
        layer.id = 20
        layer.name = 'test layer in group'
        layer.isChecked = False
        layer.layerType = "internal WMS"
        layer.imageType = "image/png"
        layer.legend = False
        layer.isLegendExpanded = False
        layer.public = True
        group1.children = [group2]
        group2.children = [layer]
        self.assertEqual(entry._group(group1, [layer], [], None, TimeInformation()), ({
            'isExpanded': False,
            'isInternalWMS': True,
            'name': u'block',
            'isBaseLayer': False,
            'children': [{
                'isExpanded': False,
                'isInternalWMS': True,
                'name': u'node',
                'isBaseLayer': False,
                'metadataURL': 'http://example.com/group.metadata',
                'children': [{
                    'name': u'test layer in group',
                    'id': 20,
                    'isChecked': False,
                    'type': u'internal WMS',
                    'legend': False,
                    'isLegendExpanded': False,
                    'imageType': u'image/png',
                    'public': True,
                }]
            }]
        }, ['The layer test layer in group is not defined in WMS capabilities'], False))

        group1 = LayerGroup()
        group1.isInternalWMS = True
        group2 = LayerGroup()
        group2.isInternalWMS = False
        group1.children = [group2]
        _, errors, stop = entry._group(group1, [], [], None, TimeInformation())
        self.assertTrue(len(errors) > 0)
        self.assertFalse(stop)

        group1 = LayerGroup()
        group1.isInternalWMS = False
        group2 = LayerGroup()
        group2.isInternalWMS = True
        group1.children = [group2]
        _, errors, stop = entry._group(group1, [], [], None, TimeInformation())
        self.assertTrue(len(errors) > 0)
        self.assertFalse(stop)

        group = LayerGroup()
        group.isInternalWMS = True
        layer = Layer()
        layer.layerType = 'internal WMS'
        group.children = [layer]
        _, errors, stop = entry._group(group, [layer], [], None, TimeInformation())
        self.assertEqual(len(errors), 1)
        self.assertEqual(errors[0], "The layer  is not defined in WMS capabilities")
        self.assertFalse(stop)

        group = LayerGroup()
        group.isInternalWMS = True
        layer = Layer()
        layer.layerType = 'external WMS'
        group.children = [layer]
        _, errors, stop = entry._group(group, [layer], [], None, TimeInformation())
        self.assertTrue(len(errors) > 0)
        self.assertFalse(stop)

        group = LayerGroup()
        group.isInternalWMS = True
        layer = Layer()
        layer.layerType = 'WMTS'
        group.children = [layer]
        _, errors, stop = entry._group(group, [layer], [], None, TimeInformation())
        self.assertTrue(len(errors) > 0)
        self.assertFalse(stop)

        group = LayerGroup()
        group.isInternalWMS = True
        layer = Layer()
        layer.layerType = 'no 2D'
        group.children = [layer]
        _, errors, stop = entry._group(group, [layer], [], None, TimeInformation())
        self.assertTrue(len(errors) > 0)
        self.assertFalse(stop)

        group = LayerGroup()
        group.isInternalWMS = False
        layer = Layer()
        layer.layerType = 'internal WMS'
        group.children = [layer]
        _, errors, stop = entry._group(group, [layer], [], None, TimeInformation())
        self.assertTrue(len(errors) > 0)
        self.assertFalse(stop)

        group = LayerGroup()
        group.isInternalWMS = False
        layer = Layer()
        layer.layerType = 'external WMS'
        group.children = [layer]
        _, errors, stop = entry._group(group, [layer], [], None, TimeInformation())
        self.assertEqual(len(errors), 0)
        self.assertFalse(stop)

        group = LayerGroup()
        group.isInternalWMS = False
        layer = Layer()
        layer.layerType = 'WMTS'
        group.children = [layer]
        _, errors, stop = entry._group(group, [layer], [], None, TimeInformation())
        self.assertEqual(len(errors), 0)
        self.assertFalse(stop)

        group = LayerGroup()
        group.isInternalWMS = False
        layer = Layer()
        layer.layerType = 'no 2D'
        group.children = [layer]
        _, errors, stop = entry._group(group, [layer], [], None, TimeInformation())
        self.assertEqual(len(errors), 0)
        self.assertFalse(stop)