Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Create module test; add more debug messages for travis
- Loading branch information
Showing
5 changed files
with
111 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters