Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Aug 27, 2020
1 parent 904000c commit 3efd98d
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 19 deletions.
3 changes: 3 additions & 0 deletions python/server/auto_additions/qgsserversettings.py
@@ -0,0 +1,3 @@
# The following has been generated automatically from src/server/qgsserversettings.h
QgsServerSettingsEnv.Source.baseClass = QgsServerSettingsEnv
QgsServerSettingsEnv.EnvVar.baseClass = QgsServerSettingsEnv
42 changes: 40 additions & 2 deletions python/server/auto_generated/qgsserversettings.sip.in
Expand Up @@ -11,6 +11,44 @@



class QgsServerSettingsEnv : QObject
{

%TypeHeaderCode
#include "qgsserversettings.h"
%End
public:
enum Source
{
DEFAULT_VALUE,
ENVIRONMENT_VARIABLE,
INI_FILE
};

enum EnvVar
{
QGIS_OPTIONS_PATH,
QGIS_SERVER_PARALLEL_RENDERING,
QGIS_SERVER_MAX_THREADS,
QGIS_SERVER_LOG_LEVEL,
QGIS_SERVER_LOG_FILE,
QGIS_SERVER_LOG_STDERR,
QGIS_PROJECT_FILE,
MAX_CACHE_LAYERS,
QGIS_SERVER_IGNORE_BAD_LAYERS,
QGIS_SERVER_CACHE_DIRECTORY,
QGIS_SERVER_CACHE_SIZE,
QGIS_SERVER_SHOW_GROUP_SEPARATOR,
QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE,
QGIS_SERVER_WMS_MAX_HEIGHT,
QGIS_SERVER_WMS_MAX_WIDTH,
QGIS_SERVER_API_RESOURCES_DIRECTORY,
QGIS_SERVER_API_WFS3_MAX_LIMIT,
QGIS_SERVER_TRUST_LAYER_METADATA,
QGIS_SERVER_LANDING_PAGE_PROJECTS_DIRECTORIES,
QGIS_SERVER_LANDING_PAGE_PROJECTS_PG_CONNECTIONS
};
};

class QgsServerSettings
{
Expand Down Expand Up @@ -155,7 +193,7 @@ Returns the server-wide max width of a WMS GetMap request. The lower one of this
.. versionadded:: 3.6.2
%End

QString projectsDirectories() const;
QString landingPageProjectsDirectories() const;
%Docstring
Returns the directories used by the landing page service to find .qgs
and .qgz projects. Multiple directories can be specified by separating
Expand All @@ -164,7 +202,7 @@ them with '||'.
.. versionadded:: 3.16
%End

QString projectsPgConnections() const;
QString landingPageProjectsPgConnections() const;
%Docstring
Returns the PostgreSQL connection strings used by the landing page
service to find projects. Multiple connections can be specified by
Expand Down
4 changes: 2 additions & 2 deletions src/server/qgsserversettings.cpp
Expand Up @@ -479,12 +479,12 @@ int QgsServerSettings::wmsMaxWidth() const
return value( QgsServerSettingsEnv::QGIS_SERVER_WMS_MAX_WIDTH ).toInt();
}

QString QgsServerSettings::projectsDirectories() const
QString QgsServerSettings::landingPageProjectsDirectories() const
{
return value( QgsServerSettingsEnv::QGIS_SERVER_LANDING_PAGE_PROJECTS_DIRECTORIES, true ).toString();
}

QString QgsServerSettings::projectsPgConnections() const
QString QgsServerSettings::landingPageProjectsPgConnections() const
{
return value( QgsServerSettingsEnv::QGIS_SERVER_LANDING_PAGE_PROJECTS_PG_CONNECTIONS, true ).toString();
}
Expand Down
8 changes: 4 additions & 4 deletions src/server/qgsserversettings.h
Expand Up @@ -33,7 +33,7 @@
* \brief Provides some enum describing the environment currently supported for configuration.
* \since QGIS 3.0
*/
#ifndef SIP_RUN
// #ifndef SIP_RUN
class SERVER_EXPORT QgsServerSettingsEnv : public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -75,7 +75,7 @@ class SERVER_EXPORT QgsServerSettingsEnv : public QObject
};
Q_ENUM( EnvVar )
};
#endif
// #endif

/**
* \ingroup server
Expand Down Expand Up @@ -213,15 +213,15 @@ class SERVER_EXPORT QgsServerSettings
* them with '||'.
* \since QGIS 3.16
*/
QString projectsDirectories() const;
QString landingPageProjectsDirectories() const;

/**
* Returns the PostgreSQL connection strings used by the landing page
* service to find projects. Multiple connections can be specified by
* separating them with '||'.
* \since QGIS 3.16
*/
QString projectsPgConnections() const;
QString landingPageProjectsPgConnections() const;

/**
* Returns the server-wide base directory where HTML templates and static assets (e.g. images, js and css files) are searched for.
Expand Down
4 changes: 2 additions & 2 deletions src/server/services/landingpage/qgslandingpageutils.cpp
Expand Up @@ -54,7 +54,7 @@ QMap<QString, QString> QgsLandingPageUtils::projects( const QgsServerSettings &s
} );


const QString projectDir { settings.projectsDirectories() };
const QString projectDir { settings.landingPageProjectsDirectories() };

// Clear cache if QGIS_SERVER_PROJECTS_DIRECTORIES has changed
if ( projectDir != QGIS_SERVER_PROJECTS_DIRECTORIES )
Expand All @@ -65,7 +65,7 @@ QMap<QString, QString> QgsLandingPageUtils::projects( const QgsServerSettings &s
dirWatcher.removePaths( cWatchedDirs );
}

const QString pgConnections { settings.projectsPgConnections() };
const QString pgConnections { settings.landingPageProjectsPgConnections() };

// Clear cache if QGIS_SERVER_PROJECTS_PG_CONNECTIONS has changed
if ( pgConnections != QGIS_SERVER_PROJECTS_PG_CONNECTIONS )
Expand Down
23 changes: 14 additions & 9 deletions tests/src/python/test_qgsserver_settings.py
Expand Up @@ -17,7 +17,7 @@

from utilities import unitTestDataPath
from qgis.testing import unittest
from qgis.server import QgsServerSettings
from qgis.server import QgsServerSettings, QgsServerSettingsEnv


class TestQgsServerSettings(unittest.TestCase):
Expand Down Expand Up @@ -237,32 +237,37 @@ def test_options_path_conf1(self):
os.environ.pop(env)

def test_env_actual(self):
env = "QGIS_SERVER_PROJECTS_DIRECTORIES"
env2 = "QGIS_SERVER_PROJECTS_PG_CONNECTIONS"
env = "QGIS_SERVER_LANDING_PAGE_PROJECTS_DIRECTORIES"
env2 = "QGIS_SERVER_LANDING_PAGE_PROJECTS_PG_CONNECTIONS"

os.environ[env] = "/tmp/initial"
os.environ[env2] = "pg:initial"

# test intial value
self.settings.load()
self.assertEqual(self.settings.projectsDirectories(), "/tmp/initial")
self.assertEqual(self.settings.projectsPgConnections(), "pg:initial")
self.assertEqual(self.settings.landingPageProjectsDirectories(), "/tmp/initial")
self.assertEqual(self.settings.landingPageProjectsPgConnections(), "pg:initial")

# set new environment variable
os.environ[env] = "/tmp/new"
os.environ[env2] = "pg:new"

# test new environment variable
self.assertEqual(self.settings.projectsDirectories(), "/tmp/new")
self.assertEqual(self.settings.projectsPgConnections(), "pg:new")
self.assertEqual(self.settings.landingPageProjectsDirectories(), "/tmp/new")
self.assertEqual(self.settings.landingPageProjectsPgConnections(), "pg:new")

# current environment variable are popped
os.environ.pop(env)
os.environ.pop(env2)

# fallback to initial values
self.assertEqual(self.settings.projectsDirectories(), "/tmp/initial")
self.assertEqual(self.settings.projectsPgConnections(), "pg:initial")
self.assertEqual(self.settings.landingPageProjectsDirectories(), "/tmp/initial")
self.assertEqual(self.settings.landingPageProjectsPgConnections(), "pg:initial")

def test_env_name(self):
env = QgsServerSettingsEnv.QGIS_SERVER_LANDING_PAGE_PROJECTS_DIRECTORIES
name = QgsServerSettings.name(env)
self.assertEqual(name, "QGIS_SERVER_LANDING_PAGE_PROJECTS_DIRECTORIES")


if __name__ == '__main__':
Expand Down

0 comments on commit 3efd98d

Please sign in to comment.