72 changes: 58 additions & 14 deletions tests/src/python/qgis_local_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ def __init__(self, kind, exe, fcgi_bin, conf_dir, temp_dir):
fcgi_sock = os.path.join(temp_dir, 'var', 'run',
'qgs_mapserv.sock')
if self._mac:
self.set_startenv({'QGIS_LOG_FILE': '{0}/log/qgis_server.log'.format(temp_dir)})
self.set_startenv({
'QGIS_LOG_FILE':
'{0}/log/qgis_server.log'.format(temp_dir)})
init_scr = os.path.join(conf_dir, 'fcgi', 'scripts',
'spawn_fcgi_mac.sh')
self.set_startcmd([init_scr, 'start', exe, fcgi_sock,
Expand Down Expand Up @@ -450,19 +452,61 @@ def get_map(self, params, browser=False):
openInBrowserTab(url)
return False, ''

tmp = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
success = True
filepath = tmp.name
# print 'filepath: ' + filepath
tmp.close()
filepath2, headers = urllib.urlretrieve(url, tmp.name)

if (headers.getmaintype() != 'image' or
headers.getheader('Content-Type') != 'image/png'):
success = False
if os.path.exists(filepath):
os.unlink(filepath)
filepath = ''
# try until qgis_mapserv.fcgi process is available (for 20 seconds)
# on some platforms the fcgi_server_process is a daemon handling the
# launch of the fcgi-spawner, which may be running quickly, but the
# qgis_mapserv.fcgi spawned process is not yet accepting connections
resp = None
tmp_png = None
# noinspection PyUnusedLocal
filepath = ''
# noinspection PyUnusedLocal
success = False
start_time = time.time()
while time.time() - start_time < 20:
resp = None
try:
tmp_png = urllib2.urlopen(url)
except urllib2.HTTPError as resp:
if resp.code == 503 or resp.code == 500:
time.sleep(1)
else:
raise ServerProcessError(
'Web/FCGI Process Request HTTPError',
'Cound not connect to process: ' + str(resp.code),
resp.message
)
except urllib2.URLError as resp:
raise ServerProcessError(
'Web/FCGI Process Request URLError',
'Cound not connect to process: ' + str(resp.code),
resp.reason
)
else:
delta = time.time() - start_time
print 'Seconds elapsed for server GetMap: ' + str(delta)
break

if resp is not None:
raise ServerProcessError(
'Web/FCGI Process Request Error',
'Cound not connect to process: ' + str(resp.code)
)

if (tmp_png is not None
and tmp_png.info().getmaintype() == 'image'
and tmp_png.info().getheader('Content-Type') == 'image/png'):

tmp = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
filepath = tmp.name
tmp.write(tmp_png.read())
tmp.close()
success = True
else:
raise ServerProcessError(
'FCGI Process Request Error',
'No valid PNG output'
)

return success, filepath

Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_qgspallabeling_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def setUpClass(cls):
def setDefaultEngineSettings(cls):
"""Restore default settings for pal labelling"""
cls._Pal = QgsPalLabeling()
""":type: QgsPalLabeling"""
cls._MapRenderer.setLabelingEngine(cls._Pal)
cls._PalEngine = cls._MapRenderer.labelingEngine()

Expand Down
33 changes: 29 additions & 4 deletions tests/src/python/test_qgspallabeling_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import glob
import shutil
import tempfile
import time
from PyQt4.QtCore import *
from PyQt4.QtGui import *

Expand Down Expand Up @@ -58,8 +59,9 @@ class TestServerBase(TestQgsPalLabeling):
def setUpClass(cls):
TestQgsPalLabeling.setUpClass()
MAPSERV.startup()
MAPSERV.web_dir_install(os.listdir(cls._PalDataDir), cls._PalDataDir)
MAPSERV.web_dir_install(glob.glob(cls._PalDataDir + os.sep + '*.qml'))

# noinspection PyArgumentList
cls._TestProj = QgsProject.instance()
cls._TestProjName = 'pal_test.qgs'
cls._TestProj.setFileName(
Expand All @@ -70,6 +72,11 @@ def setUpClass(cls):
cls._CheckMismatch = 200 # default for server tests; mismatch expected
cls._CheckGroup = '' # default '' will check against server control

settings = QSettings()
# noinspection PyArgumentList
cls._CacheDir = settings.value(
"cache/directory", QgsApplication.qgisSettingsDirPath() + "cache")

@classmethod
def tearDownClass(cls):
"""Run after all tests"""
Expand All @@ -78,10 +85,24 @@ def tearDownClass(cls):
cls._TestProj.write()
if "PAL_REPORT" in os.environ:
MAPSERV.stop_processes()
# MAPSERV.fcgi_server_process().stop()
MAPSERV.open_temp_dir()
else:
MAPSERV.shutdown()

def setUp(self):
"""Run before each test."""
# web server stays up across all tests
# MAPSERV.fcgi_server_process().stop()
# self.deleteCache()

# noinspection PyPep8Naming
def deleteCache(self):
for item in os.listdir(self._CacheDir):
shutil.rmtree(os.path.join(self._CacheDir, item),
ignore_errors=True)

# noinspection PyPep8Naming
def defaultWmsParams(self, layername):
return {
'SERVICE': 'WMS',
Expand Down Expand Up @@ -128,12 +149,14 @@ def checkTest(self, **kwargs):
self.lyr.writeToLayer(self.layer)
# save project file
self._TestProj.write()
# always restart FCGI before tests, so settings can be applied
# MAPSERV.fcgi_server_process().start()
# get server results
# print self.params.__repr__()
res, self._TestImage = MAPSERV.get_map(self.params, False)
res_m, self._TestImage = MAPSERV.get_map(self.params, False)
# print self._TestImage.__repr__()
self.saveContolImage(self._TestImage)
self.assertTrue(res, 'Failed to retrieve/save image from test server')
self.assertTrue(res_m, 'Failed to retrieve/save image from test server')
# gp = kwargs['grpprefix'] if 'grpprefix' in kwargs else ''
self.assertTrue(*self.renderCheck(mismatch=self._CheckMismatch,
imgpath=self._TestImage,
Expand All @@ -152,7 +175,9 @@ def setUpClass(cls):
# NOTE: unless PAL_SUITE env var is set all test class methods will be run
# ex: 'TestGroup(Point|Line|Curved|Polygon|Feature).test_method'
suite = [
'TestServerVsCanvasPoint.test_text_size_map_unit'
# 'TestServerVsCanvasPoint.test_text_size_map_unit',
'TestServerPoint.test_partials_labels_enabled',
'TestServerPoint.test_partials_labels_disabled'
]
res = runSuite(sys.modules[__name__], suite)
# if SPAWN:
Expand Down
20 changes: 13 additions & 7 deletions tests/src/python/test_qgspallabeling_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *

from qgis.core import (
QgsPalLayerSettings,
)
from qgis.core import *


class TestPointBase(object):

def __init__(self):
"""Dummy assignments, intended to be overriden in subclasses"""
self.lyr = QgsPalLayerSettings()
""":type: QgsPalLayerSettings"""
self._TestFont = QApplication.font() # will become a standard test font
self.params = dict()
self._Pal = None
""":type: QgsPalLabeling"""
self._Canvas = None
""":type: QgsMapCanvas"""

def checkTest(self, **kwargs):
"""Intended to be overriden in subclasses"""
Expand All @@ -55,20 +59,22 @@ def test_text_color(self):
def test_partials_labels_enabled(self):
# Set Big font size
font = QFont(self._TestFont)
font.setPointSizeF(90)
font.setPointSizeF(120)
self.lyr.textFont = font
# Enable partials labels
self._PalEngine.setShowingPartialsLabels(True)
self._Pal.setShowingPartialsLabels(True)
self._Pal.saveEngineSettings()
# Check
self.checkTest()

def test_partials_labels_disabled(self):
# Set Big font size
font = QFont(self._TestFont)
font.setPointSizeF(90)
font.setPointSizeF(120)
self.lyr.textFont = font
# Disable partials labels
self._PalEngine.setShowingPartialsLabels(False)
self._Pal.setShowingPartialsLabels(False)
self._Pal.saveEngineSettings()
# Check
self.checkTest()

Expand Down

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.