|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""QGIS Unit tests for QgsOwsConnection |
| 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__ = '12.09.2017' |
| 11 | +__copyright__ = 'Copyright 2017, 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.testing import unittest, start_app |
| 18 | +from qgis.core import (QgsOwsConnection, |
| 19 | + QgsDataSourceUri, |
| 20 | + QgsSettings) |
| 21 | +from qgis.PyQt.QtCore import QCoreApplication |
| 22 | + |
| 23 | + |
| 24 | +class TestQgsOwsConnection(unittest.TestCase): |
| 25 | + |
| 26 | + @classmethod |
| 27 | + def setUpClass(cls): |
| 28 | + """Run before all tests""" |
| 29 | + QCoreApplication.setOrganizationName("QGIS_Test") |
| 30 | + QCoreApplication.setOrganizationDomain("QGIS_TestPyQgsColorScheme.com") |
| 31 | + QCoreApplication.setApplicationName("QGIS_TestPyQgsColorScheme") |
| 32 | + QgsSettings().clear() |
| 33 | + start_app() |
| 34 | + |
| 35 | + # setup some fake connections |
| 36 | + settings = QgsSettings() |
| 37 | + key = 'qgis/connections-wms/test/' |
| 38 | + settings.setValue(key + 'url', 'aaa.bbb.com') |
| 39 | + settings.setValue(key + 'referer', 'my_ref') |
| 40 | + settings.setValue(key + 'ignoreGetMapURI', True) |
| 41 | + settings.setValue(key + 'ignoreGetFeatureInfoURI', True) |
| 42 | + settings.setValue(key + 'smoothPixmapTransform', True) |
| 43 | + settings.setValue(key + 'dpiMode', 4) |
| 44 | + settings.setValue(key + 'ignoreAxisOrientation', True) |
| 45 | + settings.setValue(key + 'invertAxisOrientation', True) |
| 46 | + |
| 47 | + key = 'qgis/connections-wfs/test/' |
| 48 | + settings.setValue(key + 'url', 'ccc.ddd.com') |
| 49 | + settings.setValue(key + 'version', '1.1.0') |
| 50 | + settings.setValue(key + 'maxnumfeatures', '47') |
| 51 | + settings.setValue(key + 'ignoreAxisOrientation', True) |
| 52 | + settings.setValue(key + 'invertAxisOrientation', True) |
| 53 | + |
| 54 | + def testWmsConnection(self): |
| 55 | + c = QgsOwsConnection('WMS', 'test') |
| 56 | + uri = c.uri() |
| 57 | + |
| 58 | + self.assertEqual(uri.param('url'), 'aaa.bbb.com') |
| 59 | + self.assertEqual(uri.param('referer'), 'my_ref') |
| 60 | + self.assertEqual(uri.param('IgnoreGetMapUrl'), '1') |
| 61 | + self.assertEqual(uri.param('IgnoreGetFeatureInfoUrl'), '1') |
| 62 | + self.assertEqual(uri.param('SmoothPixmapTransform'), '1') |
| 63 | + self.assertEqual(uri.param('dpiMode'), '4') |
| 64 | + self.assertEqual(uri.param('IgnoreAxisOrientation'), '1') |
| 65 | + self.assertEqual(uri.param('InvertAxisOrientation'), '1') |
| 66 | + |
| 67 | + def testWmsSettings(self): |
| 68 | + uri = QgsDataSourceUri() |
| 69 | + QgsOwsConnection.addWmsWcsConnectionSettings(uri, 'qgis/connections-wms/test/') |
| 70 | + |
| 71 | + self.assertEqual(uri.param('referer'), 'my_ref') |
| 72 | + self.assertEqual(uri.param('IgnoreGetMapUrl'), '1') |
| 73 | + self.assertEqual(uri.param('IgnoreGetFeatureInfoUrl'), '1') |
| 74 | + self.assertEqual(uri.param('SmoothPixmapTransform'), '1') |
| 75 | + self.assertEqual(uri.param('dpiMode'), '4') |
| 76 | + self.assertEqual(uri.param('IgnoreAxisOrientation'), '1') |
| 77 | + self.assertEqual(uri.param('InvertAxisOrientation'), '1') |
| 78 | + |
| 79 | + def testWfsConnection(self): |
| 80 | + c = QgsOwsConnection('WFS', 'test') |
| 81 | + uri = c.uri() |
| 82 | + |
| 83 | + self.assertEqual(uri.param('url'), 'ccc.ddd.com') |
| 84 | + self.assertEqual(uri.param('version'), '1.1.0') |
| 85 | + self.assertEqual(uri.param('maxNumFeatures'), '47') |
| 86 | + self.assertEqual(uri.param('IgnoreAxisOrientation'), '1') |
| 87 | + self.assertEqual(uri.param('InvertAxisOrientation'), '1') |
| 88 | + |
| 89 | + def testWfsSettings(self): |
| 90 | + uri = QgsDataSourceUri() |
| 91 | + QgsOwsConnection.addWfsConnectionSettings(uri, 'qgis/connections-wfs/test/') |
| 92 | + |
| 93 | + self.assertEqual(uri.param('version'), '1.1.0') |
| 94 | + self.assertEqual(uri.param('maxNumFeatures'), '47') |
| 95 | + self.assertEqual(uri.param('IgnoreAxisOrientation'), '1') |
| 96 | + self.assertEqual(uri.param('InvertAxisOrientation'), '1') |
| 97 | + |
| 98 | + |
| 99 | +if __name__ == "__main__": |
| 100 | + unittest.main() |
0 commit comments