Skip to content

Commit 0150dfb

Browse files
committed
Create module test; add more debug messages for travis
1 parent 560adba commit 0150dfb

File tree

5 files changed

+111
-20
lines changed

5 files changed

+111
-20
lines changed

src/server/qgsserver.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,10 @@ bool QgsServer::init( )
349349

350350
sServerInterface = new QgsServerInterfaceImpl( sCapabilitiesCache, &sServiceRegistry );
351351

352-
// Load service modules
353-
sServiceRegistry.init( QgsApplication::libexecPath() + "/server", sServerInterface );
352+
// Load service module
353+
QString modulePath = QgsApplication::libexecPath() + "server";
354+
qDebug() << "Initializing server modules from " << modulePath << endl;
355+
sServiceRegistry.init( modulePath, sServerInterface );
354356

355357
sInitialised = true;
356358
QgsMessageLog::logMessage( QStringLiteral( "Server initialized" ), QStringLiteral( "Server" ), QgsMessageLog::INFO );

src/server/qgsservicenativeloader.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <QLibrary>
2121
#include <QDir>
22+
#include <QDebug>
2223

2324
#include "qgsservicenativeloader.h"
2425
#include "qgsserviceregistry.h"
@@ -67,7 +68,8 @@ void QgsServiceNativeLoader::loadModules( const QString& modulePath, QgsServiceR
6768
moduleDir.setNameFilters( QStringList( "*.so" ) );
6869
#endif
6970

70-
QgsDebugMsg( QString( "Checking %1 for native services modules" ).arg( moduleDir.path() ) );
71+
qDebug() << QString( "Checking %1 for native services modules" ).arg( moduleDir.path() );
72+
//QgsDebugMsg( QString( "Checking %1 for native services modules" ).arg( moduleDir.path() ) );
7173

7274
Q_FOREACH ( const QFileInfo& fi, moduleDir.entryInfoList() )
7375
{
@@ -92,9 +94,11 @@ QgsServiceModule* QgsServiceNativeLoader::loadNativeModule( const QString& locat
9294
}
9395

9496
QLibrary lib( location );
95-
QgsDebugMsg( QString( "Loading native module %1" ).arg( location ) );
97+
//QgsDebugMsg( QString( "Loading native module %1" ).arg( location ) );
98+
qDebug() << QString( "Loading native module %1" ).arg( location );
9699
if ( !lib.load() )
97100
{
101+
qDebug() << QString( "Failed to load library %1: %2" ).arg( lib.fileName(), lib.errorString());
98102
QgsMessageLog::logMessage( QString( "Failed to load library %1: %2" ).arg( lib.fileName(), lib.errorString() ) );
99103
return nullptr;
100104
}

tests/src/python/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,6 @@ IF (WITH_SERVER)
172172
ADD_PYTHON_TEST(PyQgsAuthManagerPasswordOWSTest test_authmanager_password_ows.py)
173173
ADD_PYTHON_TEST(PyQgsAuthManagerPKIOWSTest test_authmanager_pki_ows.py)
174174
ADD_PYTHON_TEST(PyQgsAuthManagerPKIPostgresTest test_authmanager_pki_postgres.py)
175-
ADD_PYTHON_TEST(PyQgsServicesTest test_services.py)
175+
ADD_PYTHON_TEST(PyQgsServerServices test_qgsserver_services.py)
176+
ADD_PYTHON_TEST(PyQgsServerModules test_qgsserver_modules.py)
176177
ENDIF (WITH_SERVER)
+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
""" QGIS test for server services
2+
"""
3+
import os
4+
from qgis.PyQt.QtCore import QBuffer, QIODevice, QTextStream
5+
from qgis.testing import unittest
6+
from qgis.core import QgsApplication
7+
from qgis.server import (QgsServer,
8+
QgsServiceRegistry,
9+
QgsService,
10+
QgsServerRequest,
11+
QgsServerResponse)
12+
13+
from utilities import unitTestDataPath
14+
15+
class Response(QgsServerResponse):
16+
17+
def __init__( self ):
18+
QgsServerResponse.__init__(self)
19+
self._buffer = QBuffer()
20+
self._buffer.open(QIODevice.ReadWrite)
21+
22+
23+
def setReturnCode( self, code ):
24+
pass
25+
26+
def setHeader( self, key, val ):
27+
pass
28+
29+
def sendError( self, code, message ):
30+
pass
31+
32+
def io(self):
33+
return self._buffer
34+
35+
36+
class MyService(QgsService):
37+
38+
def __init__(self, name, version, response):
39+
QgsService.__init__(self)
40+
self._response = response
41+
self._name = name
42+
self._version = version
43+
44+
def name(self):
45+
return self._name
46+
47+
def version(self):
48+
return self._version
49+
50+
def executeRequest( self, request, response ):
51+
52+
url = request.url()
53+
54+
response.setReturnCode(201)
55+
response.write(self._response)
56+
57+
58+
class TestModules(unittest.TestCase):
59+
"""
60+
"""
61+
62+
@classmethod
63+
def setUpClass(cls):
64+
cls.app = QgsApplication([], False)
65+
66+
@classmethod
67+
def tearDownClass(cls):
68+
cls.app.exitQgis()
69+
70+
def setUp(self):
71+
"""Create the server instance"""
72+
self.testdata_path = unitTestDataPath('qgis_server') + '/'
73+
74+
d = unitTestDataPath('qgis_server_accesscontrol') + '/'
75+
self.projectPath = os.path.join(d, "project.qgs")
76+
77+
# Clean env just to be sure
78+
env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
79+
for ev in env_vars:
80+
try:
81+
del os.environ[ev]
82+
except KeyError:
83+
pass
84+
self.server = QgsServer()
85+
86+
def test_modules(self):
87+
""" Tests that modules are loaded """
88+
89+
# Check that our 'SampleService is registered
90+
iface = self.server.serverInterface()
91+
service = iface.serviceRegistry().getService('SampleService')
92+
93+
self.assertIsNotNone(service)
94+
95+
96+
97+
if __name__ == '__main__':
98+
unittest.main()

tests/src/python/test_services.py renamed to tests/src/python/test_qgsserver_services.py

+1-15
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
"""
33
from qgis.PyQt.QtCore import QBuffer, QIODevice, QTextStream
44
from qgis.testing import unittest
5-
from qgis.core import QgsApplication
6-
from qgis.server import (QgsServer,
7-
QgsServiceRegistry,
5+
from qgis.server import (QgsServiceRegistry,
86
QgsService,
97
QgsServerRequest,
108
QgsServerResponse)
@@ -124,18 +122,6 @@ def test_1_unregister_services(self):
124122
# Check that there is no more services available
125123
service = reg.getService("STUFF")
126124
self.assertIsNone(service)
127-
128-
def test_2_server_initialization(self):
129-
130-
qgisapp = QgsApplication([], False)
131-
server = QgsServer()
132-
133-
# Check that our 'SampleService is registered
134-
iface = server.serverInterface()
135-
service = iface.serviceRegistry().getService('SampleService')
136-
137-
self.assertIsNotNone(service)
138-
139125

140126

141127
if __name__ == '__main__':

0 commit comments

Comments
 (0)