DDL update: saving layer styles on databases

Fix #11421
This commit is contained in:
Jorge Gustavo Rocha 2017-01-18 20:02:48 +00:00
parent 5c2fec325a
commit 65c01775f6
5 changed files with 36 additions and 23 deletions

View File

@ -28,12 +28,9 @@ import qgis # NOQA
import os
from qgis.testing import start_app, unittest
from qgis.core import (QgsVectorLayer,
QgsProject,
QgsRectangle,
QgsMultiRenderChecker,
QgsSingleSymbolRenderer,
QgsFillSymbol,
QgsFeatureRequest
QgsFeature,
QgsGeometry,
QgsPoint
)
from qgis.testing import unittest
from qgis.testing.mocked import get_iface
@ -43,33 +40,50 @@ start_app()
TEST_DATA_DIR = unitTestDataPath()
def createLayerWithOneLine():
# create a temporary layer
# linelayer = iface.addVectorLayer("LineString?crs=epsg:4326&field=gid:int&field=name:string", "simple_line", "memory")
linelayer = QgsVectorLayer("LineString?crs=epsg:4326&field=gid:int&field=name:string", "simple_line", "memory")
one = QgsFeature(linelayer.dataProvider().fields(), 0)
one.setAttributes([1, 'one'])
one.setGeometry(QgsGeometry.fromPolyline([QgsPoint(-7, 38), QgsPoint(-8, 42)]))
linelayer.dataProvider().addFeatures([one])
return linelayer
class TestQgsSymbolLayerReadSld(unittest.TestCase):
"""
This class loads an SLD style and checks if the styling was properly applied
This class checks if SLD styles are properly applied
"""
def setUp(self):
self.iface = get_iface()
myShpFile = os.path.join(TEST_DATA_DIR, 'streams.shp')
self.layer = QgsVectorLayer(myShpFile, 'streams', 'ogr')
# test <CSSParameter>VALUE<CSSParameter/>
# test <CSSParameter><ogc:Literal>VALUE<ogc:Literal/><CSSParameter/>
def test_Literal_within_CSSParameter(self):
layer = createLayerWithOneLine()
mFilePath = os.path.join(TEST_DATA_DIR, 'symbol_layer/external_sld/simple_streams.sld')
self.layer.loadSldStyle(mFilePath)
self.props = self.layer.renderer().symbol().symbolLayers()[0].properties()
layer.loadSldStyle(mFilePath)
props = layer.renderer().symbol().symbolLayers()[0].properties()
def testLineColor(self):
# stroke CSSParameter within ogc:Literal
# expected color is #003EBA, RGB 0,62,186
self.assertEqual(self.layer.renderer().symbol().symbolLayers()[0].color().name(), '#003eba')
def testLineColor():
# stroke CSSParameter within ogc:Literal
# expected color is #003EBA, RGB 0,62,186
self.assertEqual(layer.renderer().symbol().symbolLayers()[0].color().name(), '#003eba')
def testLineWidth(self):
# stroke-width CSSParameter within ogc:Literal
self.assertEqual(self.props['line_width'], '2')
def testLineWidth():
# stroke-width CSSParameter within ogc:Literal
self.assertEqual(props['line_width'], '2')
def testLineOpacity(self):
# stroke-opacity CSSParameter NOT within ogc:Literal
# stroke-opacity=0.1
self.assertEqual(self.props['line_color'], '0,62,186,25')
def testLineOpacity():
# stroke-opacity CSSParameter NOT within ogc:Literal
# stroke-opacity=0.1
self.assertEqual(props['line_color'], '0,62,186,25')
testLineColor()
testLineWidth()
testLineOpacity()
if __name__ == '__main__':
unittest.main()

Binary file not shown.

View File

@ -1 +0,0 @@
PROJCS["NAD27 / UTM zone 13N", GEOGCS["NAD27", DATUM["North American Datum 1927", SPHEROID["Clarke 1866", 6378206.4, 294.9786982138982, AUTHORITY["EPSG","7008"]], TOWGS84[-4.2, 135.4, 181.9, 0.0, 0.0, 0.0, 0.0], AUTHORITY["EPSG","6267"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH], AUTHORITY["EPSG","4267"]], PROJECTION["Transverse Mercator", AUTHORITY["EPSG","9807"]], PARAMETER["central_meridian", -105.0], PARAMETER["latitude_of_origin", 0.0], PARAMETER["scale_factor", 0.9996], PARAMETER["false_easting", 500000.0], PARAMETER["false_northing", 0.0], UNIT["m", 1.0], AXIS["Easting", EAST], AXIS["Northing", NORTH], AUTHORITY["EPSG","26713"]]

Binary file not shown.

Binary file not shown.