Navigation Menu

Skip to content

Commit

Permalink
Add test case for backgroundColor serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Feb 25, 2019
1 parent e63b2ef commit 94b5fed
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions tests/src/python/test_qgseditformconfig.py
Expand Up @@ -20,11 +20,14 @@
QgsVectorLayer,
QgsReadWriteContext,
QgsEditFormConfig,
QgsFetchedContent)
QgsFetchedContent,
QgsAttributeEditorContainer,
)
from qgis.gui import QgsGui

from qgis.testing import start_app, unittest
from qgis.PyQt.QtXml import QDomDocument, QDomElement
from qgis.PyQt.QtGui import QColor
from utilities import unitTestDataPath
import socketserver
import threading
Expand Down Expand Up @@ -84,14 +87,16 @@ def testFormUi(self):
config.setLayout(QgsEditFormConfig.GeneratedLayout)
self.assertEqual(config.layout(), QgsEditFormConfig.GeneratedLayout)

uiLocal = os.path.join(unitTestDataPath(), '/qgis_local_server/layer_attribute_form.ui')
uiLocal = os.path.join(
unitTestDataPath(), '/qgis_local_server/layer_attribute_form.ui')
config.setUiForm(uiLocal)
self.assertEqual(config.layout(), QgsEditFormConfig.UiFileLayout)

config.setLayout(QgsEditFormConfig.GeneratedLayout)
self.assertEqual(config.layout(), QgsEditFormConfig.GeneratedLayout)

uiUrl = 'http://localhost:' + str(self.port) + '/qgis_local_server/layer_attribute_form.ui'
uiUrl = 'http://localhost:' + \
str(self.port) + '/qgis_local_server/layer_attribute_form.ui'
config.setUiForm(uiUrl)
self.assertEqual(config.layout(), QgsEditFormConfig.UiFileLayout)
content = QgsApplication.networkContentFetcherRegistry().fetch(uiUrl)
Expand Down Expand Up @@ -140,6 +145,19 @@ def testLabelOnTop(self):
self.assertFalse(config.labelOnTop(0))
self.assertFalse(config.labelOnTop(1))

def test_backgroundColorSerialize(self):
"""Test backgroundColor serialization"""

layer = self.createLayer()
config = layer.editFormConfig()
color_name = '#ff00ff'
container = QgsAttributeEditorContainer('container name', None, QColor('#ff00ff'))
doc = QDomDocument()
element = container.toDomElement(doc)
config = QgsEditFormConfig()
container2 = config.attributeEditorElementFromDomElement(element, None, self.layer.id())
self.assertEqual(container2.backgroundColor().name(), color_name)


if __name__ == '__main__':
unittest.main()

0 comments on commit 94b5fed

Please sign in to comment.