Skip to content

Commit

Permalink
server access control test: replace hardcoded temporary directory
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Nov 22, 2015
1 parent 00715a6 commit eb3e8ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/server/qgsserver.cpp
Expand Up @@ -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
{
Expand All @@ -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;
Expand Down Expand Up @@ -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)

Expand Down
21 changes: 11 additions & 10 deletions tests/src/python/test_qgsserver_accesscontrol.py
Expand Up @@ -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 = \
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down

0 comments on commit eb3e8ed

Please sign in to comment.