# -*- coding: utf-8 -*-
"""QGIS Unit tests for WMS getcapabilities

.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = 'Alessandro Pasotti'
__date__ = '2017-01-18'
__copyright__ = 'Copyright 2015, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os
import tempfile
import shutil
import glob
import osgeo.gdal
import osgeo.ogr
import sys

from qgis.core import QgsProviderRegistry, QgsRasterLayer, QgsNetworkAccessManager
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath
from qgis.PyQt.QtCore import QTimer
from qgis.PyQt.QtTest import QSignalSpy

QGISAPP = start_app()
TEST_DATA_DIR = unitTestDataPath()


class TestPyQgsShapefileProvider(unittest.TestCase):

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

    @classmethod
    def setUpClass(cls):
        """Run before all tests"""
        pass

    @classmethod
    def tearDownClass(cls):
        """Run after all tests"""
        pass

    def setUp(self):
        """Run before each tests"""
        # Clear cache
        QgsNetworkAccessManager.instance().cache().clear()
    
       
    def testWmsGetCapabilitiesLayer(self):
        """Test GetCapabilities"""
        def _test():
            self.layer = QgsRasterLayer(self.wmsuri, 'mywms', 'wms')
            QGISAPP.exit()
        QTimer.singleShot(0, _test)
        QGISAPP.exec_()
        self.assertTrue(self.layer.isValid())
     

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