Skip to content

Commit

Permalink
Include settings.globalChildGroups in test
Browse files Browse the repository at this point in the history
Fix container iteration
  • Loading branch information
jgrocha committed Sep 1, 2017
1 parent 59aa5d3 commit ce01bc0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/core/qgssettings.cpp
Expand Up @@ -20,6 +20,7 @@
#include <QDir>

#include "qgssettings.h"
#include "qgslogger.h"

QString QgsSettings::sGlobalSettingsPath = QString();

Expand Down Expand Up @@ -154,7 +155,7 @@ QStringList QgsSettings::globalChildGroups() const
QStringList keys;
if ( mGlobalSettings )
{
QStringList keys = mGlobalSettings->childGroups();
keys = mGlobalSettings->childGroups();
}
return keys;
}
Expand Down
4 changes: 2 additions & 2 deletions src/providers/wms/qgsxyzconnection.cpp
Expand Up @@ -47,10 +47,10 @@ QStringList QgsXyzConnectionUtils::connectionList()
settings.beginGroup( QStringLiteral( "qgis/connections-xyz" ) );
connList = settings.childGroups();

QStringList global = settings.globalChildGroups();
const QStringList global = settings.globalChildGroups();
settings.endGroup();

for ( auto &s : global )
for ( const auto &s : global )
{
settings.beginGroup( "qgis/connections-xyz/" + s );
bool isHidden = settings.value( QStringLiteral( "hidden" ), false ).toBool();
Expand Down
46 changes: 41 additions & 5 deletions tests/src/python/test_qgis_global_settings.py
Expand Up @@ -37,20 +37,56 @@ def createXYZLayerFromURL(url):

class TestQgsGlobalSettings(unittest.TestCase):

def test_global_settings_exist(self):
def setUp(self):
qDebug('QgsApplication.pkgDataPath(): {0}'.format(QgsApplication.pkgDataPath()))
# Path after deployment
# QgsSettings.setGlobalSettingsPath(QgsApplication.pkgDataPath() + '/qgis_global_settings.ini')
# Path before deployment
QgsSettings.setGlobalSettingsPath(QgsApplication.pkgDataPath() + '/resources/qgis_global_settings.ini')
assert QgsSettings.setGlobalSettingsPath(QgsApplication.pkgDataPath() + '/resources/qgis_global_settings.ini')
self.settings = QgsSettings('testqgissettings', 'testqgissettings')
settings = QgsSettings()
# qDebug('settings.allKeys(): {0}'.format(settings.allKeys()))
defaulturl = settings.value('qgis/connections-xyz/OpenStreetMap/url')

def test_global_settings_exist(self):
qDebug('settings.allKeys(): {0}'.format(self.settings.allKeys()))
defaulturl = self.settings.value('qgis/connections-xyz/OpenStreetMap/url')
self.assertEqual(defaulturl, 'http://a.tile.openstreetmap.org/{z}/{x}/{y}.png')
layer = createXYZLayerFromURL(defaulturl)
self.assertEqual(layer.name(), 'OpenStreetMap')

def test_global_settings_group(self):
self.assertEqual(['qgis'], self.settings.childGroups())
self.assertEqual(['qgis'], self.settings.globalChildGroups())

self.settings.beginGroup('qgis')
self.assertEqual(['connections-xyz'], self.settings.childGroups())
self.assertEqual(['connections-xyz'], self.settings.globalChildGroups())
# qDebug('settings.allKeys(): {0}'.format(self.settings.allKeys()))
self.settings.endGroup()

self.settings.beginGroup('qgis/connections-xyz')
self.assertEqual(['OpenStreetMap'], self.settings.childGroups())
self.assertEqual(['OpenStreetMap'], self.settings.globalChildGroups())
# qDebug('settings.allKeys(): {0}'.format(self.settings.allKeys()))
self.settings.endGroup()

# add group to user's settings
self.settings.beginGroup('qgis/connections-xyz')
self.settings.setValue('OSM/url', 'http://c.tile.openstreetmap.org/{z}/{x}/{y}.png')
self.settings.setValue('OSM/zmax', '19')
self.settings.setValue('OSM/zmin', '0')
self.settings.endGroup()

# groups should be different
self.settings.beginGroup('qgis/connections-xyz')
self.assertEqual(['OSM', 'OpenStreetMap'], self.settings.childGroups())
self.assertEqual(['OpenStreetMap'], self.settings.globalChildGroups())
# qDebug('settings.allKeys(): {0}'.format(self.settings.allKeys()))
self.settings.endGroup()

self.settings.beginGroup('qgis/connections-xyz')
self.settings.remove('OSM')
self.assertEqual(['OpenStreetMap'], self.settings.childGroups())
self.assertEqual(['OpenStreetMap'], self.settings.globalChildGroups())
self.settings.endGroup()

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

0 comments on commit ce01bc0

Please sign in to comment.