Skip to content
Permalink
Browse files

server access control test: replace hardcoded temporary directory

  • Loading branch information
jef-n committed Nov 22, 2015
1 parent 00715a6 commit eb3e8ed3584b14ea15199a0926e8a2456040a683
Showing with 14 additions and 11 deletions.
  1. +3 −1 src/server/qgsserver.cpp
  2. +11 −10 tests/src/python/test_qgsserver_accesscontrol.py
@@ -268,6 +268,7 @@ QString QgsServer::configPath( const QString& defaultConfigPath, const QMap<QStr
if ( !projectFile.isEmpty() )
{
cfPath = projectFile;
QgsDebugMsg( QString( "QGIS_PROJECT_FILE:%1" ).arg( cfPath ) );
}
else
{
@@ -279,6 +280,7 @@ QString QgsServer::configPath( const QString& defaultConfigPath, const QMap<QStr
else
{
cfPath = paramIt.value();
QgsDebugMsg( QString( "MAP:%1" ).arg( cfPath ) );
}
}
return cfPath;
@@ -357,7 +359,7 @@ bool QgsServer::init( int & argc, char ** argv )
QgsMessageLog::logMessage( "PkgData PATH: " + QgsApplication::pkgDataPath(), "Server", QgsMessageLog::INFO );
QgsMessageLog::logMessage( "User DB PATH: " + QgsApplication::qgisUserDbFilePath(), "Server", QgsMessageLog::INFO );
QgsMessageLog::logMessage( "Auth DB PATH: " + QgsApplication::qgisAuthDbFilePath(), "Server", QgsMessageLog::INFO );
QgsMessageLog::logMessage( "SVG PATHS: " + QgsApplication::svgPaths().join( ":" ), "Server", QgsMessageLog::INFO );
QgsMessageLog::logMessage( "SVG PATHS: " + QgsApplication::svgPaths().join( QDir::separator() ), "Server", QgsMessageLog::INFO );

QgsApplication::createDB(); //init qgis.db (e.g. necessary for user crs)

@@ -22,6 +22,7 @@
from osgeo.gdalconst import GA_ReadOnly
from qgis.server import QgsServer, QgsAccessControlFilter
from qgis.core import QgsRenderChecker
import tempfile


XML_NS = \
@@ -990,7 +991,7 @@ def _post_restricted(self, data, query_string=None):
return result

def _img_diff(self, image, control_image, max_diff):
temp_image = "/tmp/%s_result.png" % control_image
temp_image = path.join(tempfile.gettempdir(), "%s_result.png" % control_image)
with open(temp_image, "w") as f:
f.write(image)

@@ -1006,23 +1007,23 @@ def _img_diff_error(self, response, headers, image, max_diff=10):
"Content type is wrong: %s" % headers.get("Content-Type"))
test, report = self._img_diff(response, image, max_diff)

result_img = check_output(["base64", "/tmp/" + image + "_result.png"])
message = "Image is wrong\n%s\nImage:\necho '%s' | base64 -d > /tmp/%s_result.png" % (
report, result_img.strip(), image
result_img = check_output(["base64", path.join(tempfile.gettempdir(), image + "_result.png")])
message = "Image is wrong\n%s\nImage:\necho '%s' | base64 -d >%s/%s_result.png" % (
report, result_img.strip(), tempfile.gettempdir(), image
)

if path.isfile("/tmp/" + image + "_result_diff.png"):
diff_img = check_output(["base64", "/tmp/" + image + "_result_diff.png"])
message += "\nDiff:\necho '%s' | base64 -d > /tmp/%s_result_diff.png" % (
diff_img.strip(), image
if path.isfile(path.join(tempfile.gettempdir(), image + "_result_diff.png")):
diff_img = check_output(["base64", path.join(tempfile.gettempdir(), image + "_result_diff.png")])
message += "\nDiff:\necho '%s' | base64 -d > %s/%s_result_diff.png" % (
diff_img.strip(), tempfile.gettempdir(), image
)
self.assertTrue(test, message)

def _geo_img_diff(self, image_1, image_2):

with open("/tmp/" + image_2, "w") as f:
with open(path.join(tempfile.gettempdir(), image_2), "w") as f:
f.write(image_1)
image_1 = gdal.Open("/tmp/" + image_2, GA_ReadOnly)
image_1 = gdal.Open(path.join(tempfile.gettempdir(), image_2), GA_ReadOnly)

image_2 = gdal.Open(self.testdata_path + "/results/" + image_2, GA_ReadOnly)

0 comments on commit eb3e8ed

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