|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""QGIS Unit tests for QgsAttributeTableConfig. |
| 3 | +
|
| 4 | +.. note:: This program is free software; you can redistribute it and/or modify |
| 5 | +it under the terms of the GNU General Public License as published by |
| 6 | +the Free Software Foundation; either version 2 of the License, or |
| 7 | +(at your option) any later version. |
| 8 | +""" |
| 9 | +__author__ = 'Nyall Dawson' |
| 10 | +__date__ = '07/06/2016' |
| 11 | +__copyright__ = 'Copyright 2016, The QGIS Project' |
| 12 | +# This will get replaced with a git SHA1 when you do a git archive |
| 13 | +__revision__ = '$Format:%H$' |
| 14 | + |
| 15 | +import qgis # NOQA |
| 16 | + |
| 17 | +from qgis.core import (QgsAttributeTableConfig, |
| 18 | + QgsVectorLayer |
| 19 | + ) |
| 20 | +from qgis.testing import start_app, unittest |
| 21 | + |
| 22 | +start_app() |
| 23 | + |
| 24 | + |
| 25 | +class TestQgsAttributeTableConfig(unittest.TestCase): |
| 26 | + |
| 27 | + def testLayerConfig(self): |
| 28 | + """ test retrieving attribute table config from a layer """ |
| 29 | + |
| 30 | + # make a layer |
| 31 | + point_layer = QgsVectorLayer("Point?field=fldtxt:string&field=fldint:integer", |
| 32 | + "pointlayer", "memory") |
| 33 | + |
| 34 | + # make sure attribute table config is initially populated |
| 35 | + config = point_layer.attributeTableConfig() |
| 36 | + self.assertFalse(config.isEmpty()) |
| 37 | + self.assertEqual(config.columns()[0].name, 'fldtxt') |
| 38 | + self.assertEqual(config.columns()[1].name, 'fldint') |
| 39 | + |
| 40 | + # try replacing it |
| 41 | + config.setColumns([config.columns()[1], config.columns()[0]]) |
| 42 | + point_layer.setAttributeTableConfig(config) |
| 43 | + |
| 44 | + # and make sure changes were applied |
| 45 | + config = point_layer.attributeTableConfig() |
| 46 | + self.assertFalse(config.isEmpty()) |
| 47 | + self.assertEqual(config.columns()[0].name, 'fldint') |
| 48 | + self.assertEqual(config.columns()[1].name, 'fldtxt') |
| 49 | + |
| 50 | +if __name__ == '__main__': |
| 51 | + unittest.main() |
0 commit comments