Skip to content
Permalink
Browse files

Create module test; add more debug messages for travis

  • Loading branch information
dmarteau committed Jan 10, 2017
1 parent 560adba commit 0150dfb728d594c331636c33efc5c21759e3b0b1
@@ -349,8 +349,10 @@ bool QgsServer::init( )

sServerInterface = new QgsServerInterfaceImpl( sCapabilitiesCache, &sServiceRegistry );

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

sInitialised = true;
QgsMessageLog::logMessage( QStringLiteral( "Server initialized" ), QStringLiteral( "Server" ), QgsMessageLog::INFO );
@@ -19,6 +19,7 @@

#include <QLibrary>
#include <QDir>
#include <QDebug>

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

QgsDebugMsg( QString( "Checking %1 for native services modules" ).arg( moduleDir.path() ) );
qDebug() << QString( "Checking %1 for native services modules" ).arg( moduleDir.path() );
//QgsDebugMsg( QString( "Checking %1 for native services modules" ).arg( moduleDir.path() ) );

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

QLibrary lib( location );
QgsDebugMsg( QString( "Loading native module %1" ).arg( location ) );
//QgsDebugMsg( QString( "Loading native module %1" ).arg( location ) );
qDebug() << QString( "Loading native module %1" ).arg( location );
if ( !lib.load() )
{
qDebug() << QString( "Failed to load library %1: %2" ).arg( lib.fileName(), lib.errorString());
QgsMessageLog::logMessage( QString( "Failed to load library %1: %2" ).arg( lib.fileName(), lib.errorString() ) );
return nullptr;
}
@@ -172,5 +172,6 @@ IF (WITH_SERVER)
ADD_PYTHON_TEST(PyQgsAuthManagerPasswordOWSTest test_authmanager_password_ows.py)
ADD_PYTHON_TEST(PyQgsAuthManagerPKIOWSTest test_authmanager_pki_ows.py)
ADD_PYTHON_TEST(PyQgsAuthManagerPKIPostgresTest test_authmanager_pki_postgres.py)
ADD_PYTHON_TEST(PyQgsServicesTest test_services.py)
ADD_PYTHON_TEST(PyQgsServerServices test_qgsserver_services.py)
ADD_PYTHON_TEST(PyQgsServerModules test_qgsserver_modules.py)
ENDIF (WITH_SERVER)
@@ -0,0 +1,98 @@
""" QGIS test for server services
"""
import os
from qgis.PyQt.QtCore import QBuffer, QIODevice, QTextStream
from qgis.testing import unittest
from qgis.core import QgsApplication
from qgis.server import (QgsServer,
QgsServiceRegistry,
QgsService,
QgsServerRequest,
QgsServerResponse)

from utilities import unitTestDataPath

class Response(QgsServerResponse):

def __init__( self ):
QgsServerResponse.__init__(self)
self._buffer = QBuffer()
self._buffer.open(QIODevice.ReadWrite)


def setReturnCode( self, code ):
pass

def setHeader( self, key, val ):
pass

def sendError( self, code, message ):
pass

def io(self):
return self._buffer


class MyService(QgsService):

def __init__(self, name, version, response):
QgsService.__init__(self)
self._response = response
self._name = name
self._version = version

def name(self):
return self._name

def version(self):
return self._version

def executeRequest( self, request, response ):

url = request.url()

response.setReturnCode(201)
response.write(self._response)


class TestModules(unittest.TestCase):
"""
"""

@classmethod
def setUpClass(cls):
cls.app = QgsApplication([], False)

@classmethod
def tearDownClass(cls):
cls.app.exitQgis()

def setUp(self):
"""Create the server instance"""
self.testdata_path = unitTestDataPath('qgis_server') + '/'

d = unitTestDataPath('qgis_server_accesscontrol') + '/'
self.projectPath = os.path.join(d, "project.qgs")

# Clean env just to be sure
env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
for ev in env_vars:
try:
del os.environ[ev]
except KeyError:
pass
self.server = QgsServer()

def test_modules(self):
""" Tests that modules are loaded """

# Check that our 'SampleService is registered
iface = self.server.serverInterface()
service = iface.serviceRegistry().getService('SampleService')

self.assertIsNotNone(service)



if __name__ == '__main__':
unittest.main()
@@ -2,9 +2,7 @@
"""
from qgis.PyQt.QtCore import QBuffer, QIODevice, QTextStream
from qgis.testing import unittest
from qgis.core import QgsApplication
from qgis.server import (QgsServer,
QgsServiceRegistry,
from qgis.server import (QgsServiceRegistry,
QgsService,
QgsServerRequest,
QgsServerResponse)
@@ -124,18 +122,6 @@ def test_1_unregister_services(self):
# Check that there is no more services available
service = reg.getService("STUFF")
self.assertIsNone(service)

def test_2_server_initialization(self):

qgisapp = QgsApplication([], False)
server = QgsServer()

# Check that our 'SampleService is registered
iface = server.serverInterface()
service = iface.serviceRegistry().getService('SampleService')

self.assertIsNotNone(service)



if __name__ == '__main__':

0 comments on commit 0150dfb

Please sign in to comment.
You can’t perform that action at this time.