Skip to content
Permalink
Browse files

[SERVER] Fix encoding of query string for bindings

Fix an error when passing utf-8 chars in the query string
from python bindings

Adds a test for GetLegendGraphics
  • Loading branch information
elpaso committed Apr 1, 2016
1 parent 42e42f7 commit 5a72bc7d52d0ad837c2a411cdfeb3dff699b5df1
Showing with 26 additions and 10 deletions.
  1. +2 −2 src/server/qgsserver.cpp
  2. +24 −8 tests/src/python/test_qgsserver.py
@@ -441,9 +441,9 @@ bool QgsServer::init( int & argc, char ** argv )
void QgsServer::putenv( const QString &var, const QString &val )
{
#ifdef _MSC_VER
_putenv_s( var.toUtf8().data(), val.toUtf8().data() );
_putenv_s( var.toStdString().c_str(), val.toStdString().c_str() );
#else
setenv( var.toUtf8().data(), val.toUtf8().data(), 1 );
setenv( var.toStdString().c_str(), val.toStdString().c_str(), 1 );
#endif
}

@@ -41,6 +41,13 @@ def setUp(self):
pass
self.server = QgsServer()

def assert_headers(self, header, body):
headers = Message(StringIO(header))
if 'content-length' in headers:
content_length = int(headers['content-length'])
body_length = len(body)
self.assertEqual(content_length, body_length, msg="Header reported content-length: %d Actual body length was: %d" % (content_length, body_length))

def test_destructor_segfaults(self):
"""Segfault on destructor?"""
server = QgsServer()
@@ -294,20 +301,29 @@ def test_getfeature(self):
for id, req in tests:
self.wfs_getfeature_compare(id, req)

def assert_headers(self, header, body):
headers = Message(StringIO(header))
if 'content-length' in headers:
content_length = int(headers['content-length'])
body_length = len(body)
self.assertEqual(content_length, body_length, msg="Header reported content-length: %d Actual body length was: %d" % (content_length, body_length))
def test_getLegendGraphics(self):
"""Test that does not return an exception but an image"""
parms = {
'MAP': self.testdata_path + "test%2Bproject.qgs",
'SERVICE': 'WMS',
'VERSIONE': '1.0.0',
'REQUEST': 'GetLegendGraphic',
'FORMAT': 'image/png',
#'WIDTH': '20', # optional
#'HEIGHT': '20', # optional
'LAYER': u'testlayer+èé',
}
qs = '&'.join([u"%s=%s" % (k, v) for k, v in parms.iteritems()])
h, r = self.server.handleRequest(qs)
self.assertEquals(-1, h.find('Content-Type: text/xml; charset=utf-8'), "Header: %s\nResponse:\n%s" % (h, r))
self.assertNotEquals(-1, h.find('Content-Type: image/png'), "Header: %s\nResponse:\n%s" % (h, r))


# The following code was used to test type conversion in python bindings
# def test_qpair(self):
# """Test QPair bindings"""
# f, s = self.server.testQPair(('First', 'Second'))
# self.assertEqual(f, 'First')
# self.assertEqual(s, 'Second')


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

0 comments on commit 5a72bc7

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