22
22
import tempfile
23
23
import random
24
24
import string
25
- import urllib
25
+ try :
26
+ from urllib .parse import quote
27
+ except :
28
+ from urllib import quote
26
29
27
30
__author__ = 'Alessandro Pasotti'
28
31
__date__ = '18/09/2016'
@@ -84,11 +87,14 @@ def setUpClass(cls):
84
87
cls .auth_config .setConfig ('username' , cls .username )
85
88
cls .auth_config .setConfig ('password' , cls .password )
86
89
assert (authm .storeAuthenticationConfig (cls .auth_config )[0 ])
90
+ cls .hostname = '127.0.0.1'
91
+ cls .protocol = 'http'
87
92
88
93
os .environ ['QGIS_SERVER_HTTP_BASIC_AUTH' ] = '1'
89
94
os .environ ['QGIS_SERVER_USERNAME' ] = cls .username
90
95
os .environ ['QGIS_SERVER_PASSWORD' ] = cls .password
91
96
os .environ ['QGIS_SERVER_PORT' ] = str (cls .port )
97
+ os .environ ['QGIS_SERVER_HOST' ] = cls .hostname
92
98
server_path = os .path .dirname (os .path .realpath (__file__ )) + \
93
99
'/qgis_wrapped_server.py'
94
100
cls .server = subprocess .Popen ([sys .executable , server_path ],
@@ -98,7 +104,7 @@ def setUpClass(cls):
98
104
cls .port = int (re .findall (b':(\d+)' , line )[0 ])
99
105
assert cls .port != 0
100
106
# Wait for the server process to start
101
- assert waitServer ('http ://127.0.0.1 :%s' % cls .port ), "Server is not responding! http ://127.0.0.1 :%s" % cls .port
107
+ assert waitServer ('%s ://%s :%s' % ( cls .protocol , cls . hostname , cls . port )) , "Server is not responding! '%s ://%s :%s" % ( cls .protocol , cls . hostname , cls . port )
102
108
103
109
@classmethod
104
110
def tearDownClass (cls ):
@@ -125,13 +131,16 @@ def _getWFSLayer(cls, type_name, layer_name=None, authcfg=None):
125
131
parms = {
126
132
'srsname' : 'EPSG:4326' ,
127
133
'typename' : type_name ,
128
- 'url' : 'http ://127.0.0.1 :%s/?map=%s' % (cls .port , cls .project_path ),
134
+ 'url' : '%s ://%s :%s/?map=%s' % (cls . protocol , cls . hostname , cls .port , cls .project_path ),
129
135
'version' : 'auto' ,
130
136
'table' : '' ,
131
137
}
132
138
if authcfg is not None :
133
139
parms .update ({'authcfg' : authcfg })
134
- uri = ' ' .join ([("%s='%s'" % (k , v .decode ('utf-8' ))) for k , v in list (parms .items ())])
140
+ try : # Py2
141
+ uri = ' ' .join ([("%s='%s'" % (k , v .decode ('utf-8' ))) for k , v in list (parms .items ())])
142
+ except AttributeError : # Py3
143
+ uri = ' ' .join ([("%s='%s'" % (k , v )) for k , v in list (parms .items ())])
135
144
wfs_layer = QgsVectorLayer (uri , layer_name , 'WFS' )
136
145
return wfs_layer
137
146
@@ -144,11 +153,11 @@ def _getWMSLayer(cls, layers, layer_name=None, authcfg=None):
144
153
layer_name = 'wms_' + layers .replace (',' , '' )
145
154
parms = {
146
155
'crs' : 'EPSG:4326' ,
147
- 'url' : 'http ://127.0.0.1 :%s/?map=%s' % (cls .port , cls .project_path ),
156
+ 'url' : '%s ://%s :%s/?map=%s' % (cls . protocol , cls . hostname , cls .port , cls .project_path ),
148
157
'format' : 'image/png' ,
149
158
# This is needed because of a really weird implementation in QGIS Server, that
150
159
# replaces _ in the the real layer name with spaces
151
- 'layers' : urllib . quote (layers .replace ('_' , ' ' )),
160
+ 'layers' : quote (layers .replace ('_' , ' ' )),
152
161
'styles' : '' ,
153
162
'version' : 'auto' ,
154
163
#'sql': '',
0 commit comments