Skip to content

Commit b7afe39

Browse files
committedJul 2, 2015
[tests] Switch composer picture remote url test to use a local
python server, avoids dependance on remote service
1 parent 9b976cf commit b7afe39

File tree

4 files changed

+96
-20
lines changed

4 files changed

+96
-20
lines changed
 

‎tests/src/core/testqgscomposerpicture.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ class TestQgsComposerPicture : public QObject
6060
void pictureExpression();
6161
void pictureInvalidExpression();
6262

63-
void pictureRemoteUrl(); //test fetching picture from a url
64-
6563
private:
6664
QgsComposition* mComposition;
6765
QgsComposerPicture* mComposerPicture;
@@ -386,19 +384,5 @@ void TestQgsComposerPicture::pictureInvalidExpression()
386384
mComposerPicture->setUsePictureExpression( false );
387385
}
388386

389-
void TestQgsComposerPicture::pictureRemoteUrl()
390-
{
391-
//test picture source via bad expression
392-
mComposition->addComposerPicture( mComposerPicture );
393-
394-
mComposerPicture->setPicturePath( "http://www.qgis.org/en/_static/logo.png" );
395-
396-
QgsCompositionChecker checker( "composerpicture_remote", mComposition );
397-
QVERIFY( checker.testComposition( mReport, 0, 0 ) );
398-
399-
mComposition->removeItem( mComposerPicture );
400-
mComposerPicture->setUsePictureExpression( false );
401-
}
402-
403387
QTEST_MAIN( TestQgsComposerPicture )
404388
#include "testqgscomposerpicture.moc"

‎tests/src/python/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ ADD_PYTHON_TEST(PyQgsComposition test_qgscomposition.py)
2727
ADD_PYTHON_TEST(PyQgsAnalysis test_qgsanalysis.py)
2828
ADD_PYTHON_TEST(PyQgsColorScheme test_qgscolorscheme.py)
2929
ADD_PYTHON_TEST(PyQgsColorSchemeRegistry test_qgscolorschemeregistry.py)
30-
ADD_PYTHON_TEST(PyQgsComposerMap test_qgscomposermap.py)
31-
ADD_PYTHON_TEST(PyQgsComposerMapGrid test_qgscomposermapgrid.py)
32-
ADD_PYTHON_TEST(PyQgsComposerEffects test_qgscomposereffects.py)
33-
ADD_PYTHON_TEST(PyQgsComposerShapes test_qgscomposershapes.py)
30+
ADD_PYTHON_TEST(PyQgsComposerMap test_qgscomposermap.py)
31+
ADD_PYTHON_TEST(PyQgsComposerMapGrid test_qgscomposermapgrid.py)
32+
ADD_PYTHON_TEST(PyQgsComposerEffects test_qgscomposereffects.py)
33+
ADD_PYTHON_TEST(PyQgsComposerShapes test_qgscomposershapes.py)
34+
ADD_PYTHON_TEST(PyQgsComposerPicture test_qgscomposerpicture.py)
3435
ADD_PYTHON_TEST(PyQgsSymbolLayerV2 test_qgssymbollayerv2.py)
3536
ADD_PYTHON_TEST(PyQgsPoint test_qgspoint.py)
3637
ADD_PYTHON_TEST(PyQgsAtlasComposition test_qgsatlascomposition.py)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit tests for QgsComposerPicture.
3+
4+
.. note:: This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; either version 2 of the License, or
7+
(at your option) any later version.
8+
"""
9+
__author__ = '(C) 2015 by Nyall Dawson'
10+
__date__ = '02/07/2015'
11+
__copyright__ = 'Copyright 2015, The QGIS Project'
12+
# This will get replaced with a git SHA1 when you do a git archive
13+
__revision__ = '$Format:%H$'
14+
15+
import qgis
16+
import os
17+
import sys
18+
import SocketServer
19+
import threading
20+
import SimpleHTTPServer
21+
from PyQt4.QtGui import QPainter, QColor
22+
from PyQt4.QtCore import QRectF, QCoreApplication
23+
24+
from qgis.core import (QgsComposerPicture,
25+
QgsComposition,
26+
QgsMapSettings
27+
)
28+
from utilities import (unitTestDataPath,
29+
getQgisTestApp,
30+
TestCase,
31+
unittest
32+
)
33+
from qgscompositionchecker import QgsCompositionChecker
34+
35+
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
36+
TEST_DATA_DIR = unitTestDataPath()
37+
38+
class TestQgsComposerPicture(TestCase):
39+
40+
@classmethod
41+
def setUpClass(cls):
42+
# Bring up a simple HTTP server, for remote picture tests
43+
os.chdir( unitTestDataPath() + '' )
Code has comments. Press enter to view.
44+
handler = SimpleHTTPServer.SimpleHTTPRequestHandler
45+
46+
cls.httpd = SocketServer.TCPServer(('localhost', 0), handler)
47+
cls.port = cls.httpd.server_address[1]
48+
49+
cls.httpd_thread = threading.Thread( target=cls.httpd.serve_forever )
50+
cls.httpd_thread.setDaemon( True )
51+
cls.httpd_thread.start()
52+
53+
def __init__(self, methodName):
54+
"""Run once on class initialisation."""
55+
unittest.TestCase.__init__(self, methodName)
56+
57+
TEST_DATA_DIR = unitTestDataPath()
58+
self.pngImage = TEST_DATA_DIR + "/sample_image.png";
59+
60+
# create composition
61+
self.mapSettings = QgsMapSettings()
62+
self.composition = QgsComposition(self.mapSettings)
63+
self.composition.setPaperSize(297, 210)
64+
65+
self.composerPicture = QgsComposerPicture( self.composition )
66+
self.composerPicture.setPicturePath( self.pngImage )
67+
self.composerPicture.setSceneRect( QRectF( 70, 70, 100, 100 ) )
68+
self.composerPicture.setFrameEnabled( True )
69+
self.composition.addComposerPicture(self.composerPicture)
70+
71+
def testResizeZoom(self):
72+
"""Test picture resize zoom mode."""
73+
self.composerPicture.setResizeMode( QgsComposerPicture.Zoom )
74+
75+
checker = QgsCompositionChecker('composerpicture_resize_zoom', self.composition)
76+
testResult, message = checker.testComposition()
77+
78+
assert testResult, message
79+
80+
def testRemoteImage(self):
81+
"""Test fetching remote picture."""
82+
self.composerPicture.setPicturePath( 'http://localhost:' + str( TestQgsComposerPicture.port ) + '/qgis_local_server/logo.png' )
83+
84+
checker = QgsCompositionChecker('composerpicture_remote', self.composition)
85+
testResult, message = checker.testComposition()
86+
87+
self.composerPicture.setPicturePath( self.pngImage )
88+
assert testResult, message
89+
90+
if __name__ == '__main__':
91+
unittest.main()
4.61 KB
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.