Skip to content

Commit eac2877

Browse files
committed
Clean up local test server module and add more usage info
1 parent 4915c9e commit eac2877

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

tests/src/python/qgis_local_server.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,6 @@ def __init__(self, kind, exe, fcgi_bin, conf_dir, temp_dir):
190190
'qgs_mapserv.sock')
191191
if self._mac:
192192
self.set_startenv({'QGIS_LOG_FILE': '{0}/log/qgis_server.log'.format(temp_dir)})
193-
# self.set_startcmd([
194-
# exe, '-n', '-s', fcgi_sock, '--', temp_dir + fcgi_bin, '&'
195-
# ])
196-
# self.set_startcmd([init_scr, 'start', exe, fcgi_sock,
197-
# temp_dir + fcgi_bin, temp_dir])
198-
# self.set_startcmd([
199-
# '/bin/bash', 'exec' 'env', '-i',
200-
# 'QGIS_LOG_FILE=' + temp_dir + '/log/qgis_server.log',
201-
# exe, '-n', '-s', fcgi_sock, '--', temp_dir + fcgi_bin
202-
# ])
203-
# self.set_startcmd([
204-
# '/bin/bash', '-c',
205-
# "'exec env -i QGIS_LOG_FILE={0}/log/qgis_server.log {1} -n -s {2} -- {3}'".format(temp_dir, exe, fcgi_sock, temp_dir + fcgi_bin)])
206193
init_scr = os.path.join(conf_dir, 'fcgi', 'scripts',
207194
'spawn_fcgi_mac.sh')
208195
self.set_startcmd([init_scr, 'start', exe, fcgi_sock,
@@ -243,7 +230,7 @@ def __init__(self, fcgi_bin):
243230
self._web_dir = ''
244231

245232
servers = [
246-
('spawn-fcgi', 'lighttpd'),
233+
('spawn-fcgi', 'lighttpd')
247234
#('fcgiwrap', 'nginx'),
248235
#('uwsgi', 'nginx'),
249236
]
@@ -564,6 +551,10 @@ def getLocalServer():
564551
565552
If MAPSERV is already running the handle to it will be returned.
566553
554+
Before unit test class add:
555+
556+
MAPSERV = getLocalServer()
557+
567558
IMPORTANT: When using MAPSERV in a test class, ensure to set these:
568559
569560
@classmethod
@@ -576,12 +567,25 @@ def setUpClass(cls):
576567
def tearDownClass(cls):
577568
MAPSERV.shutdown()
578569
# or, when testing, instead of shutdown...
579-
MAPSERV.stop_processes()
580-
MAPSERV.open_temp_dir()
570+
# MAPSERV.stop_processes()
571+
# MAPSERV.open_temp_dir()
581572
582573
This ensures the subprocesses are stopped and the temp directory is removed.
583574
If this is not used, the server processes may continue to run after tests.
584575
576+
If you need to restart the qgis_mapserv.fcgi spawning process to show
577+
changes to project settings, consider adding:
578+
579+
def setUp(self):
580+
'''Run before each test.'''
581+
# web server stays up across all tests
582+
MAPSERV.fcgi_server_process().start()
583+
584+
def tearDown(self):
585+
'''Run after each test.'''
586+
# web server stays up across all tests
587+
MAPSERV.fcgi_server_process().stop()
588+
585589
:rtype: QgisLocalServer
586590
"""
587591
global SERVRUN # pylint: disable=W0603
@@ -645,13 +649,8 @@ def tearDownClass(cls):
645649
break
646650
except urllib2.URLError:
647651
pass
648-
# res = None
649-
# try:
650-
# res = urllib2.urlopen(srv.web_url(), timeout=30)
651-
# except urllib2.URLError:
652-
# pass
653652
msg = 'Web server basic access to root index.html failed'
654-
print repr(res)
653+
# print repr(res)
655654
assert (res is not None
656655
and res.getcode() == 200
657656
and 'Web Server Working' in res.read()), msg

0 commit comments

Comments
 (0)