test_provider_wms.py

Alessandro Pasotti, 2018-01-16 05:52 PM

Download (1.85 KB)

 
1
# -*- coding: utf-8 -*-
2
"""QGIS Unit tests for WMS getcapabilities
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__ = 'Alessandro Pasotti'
10
__date__ = '2017-01-18'
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 os
16
import tempfile
17
import shutil
18
import glob
19
import osgeo.gdal
20
import osgeo.ogr
21
import sys
22

    
23
from qgis.core import QgsProviderRegistry, QgsRasterLayer, QgsNetworkAccessManager
24
from qgis.testing import start_app, unittest
25
from utilities import unitTestDataPath
26
from qgis.PyQt.QtCore import QTimer
27
from qgis.PyQt.QtTest import QSignalSpy
28

    
29
QGISAPP = start_app()
30
TEST_DATA_DIR = unitTestDataPath()
31

    
32

    
33
class TestPyQgsShapefileProvider(unittest.TestCase):
34

    
35
    wmsuri = ("contextualWMSLegend=0&crs=EPSG:4326&dpiMode=7&featureCount=10&format=image/jpeg"
36
          "&layers=s2cloudless&styles&tileMatrixSet=s2cloudless-wmsc-14"
37
          "&url=http://tiles.maps.eox.at/wms?" )
38

    
39
    @classmethod
40
    def setUpClass(cls):
41
        """Run before all tests"""
42
        pass
43

    
44
    @classmethod
45
    def tearDownClass(cls):
46
        """Run after all tests"""
47
        pass
48

    
49
    def setUp(self):
50
        """Run before each tests"""
51
        # Clear cache
52
        QgsNetworkAccessManager.instance().cache().clear()
53
    
54
       
55
    def testWmsGetCapabilitiesLayer(self):
56
        """Test GetCapabilities"""
57
        def _test():
58
            self.layer = QgsRasterLayer(self.wmsuri, 'mywms', 'wms')
59
            QGISAPP.exit()
60
        QTimer.singleShot(0, _test)
61
        QGISAPP.exec_()
62
        self.assertTrue(self.layer.isValid())
63
     
64

    
65
if __name__ == '__main__':
66
    unittest.main()