def testFetchReloadUrl(self):
        def writeSimpleFile(content):
            with open('qgis_local_server/simple_content.txt', 'w') as f:
                f.write(content)
            self.file_content = content

        registry = QgsApplication.networkContentFetcherRegistry()
        content = registry.fetch('http://localhost:' + str(self.port) + '/qgis_local_server/simple_content.txt')
        self.loaded = False
        writeSimpleFile('my initial content')

        def check_reply():
            self.loaded = True
            self.assertEqual(content.status(), QgsFetchedContent.Finished)
            self.assertEqual(content.error(), QNetworkReply.NoError)
            self.assertNotEqual(content.filePath(), '')
            with open(content.filePath(), encoding="utf-8") as file:
                self.assertEqual(file.readline().rstrip(), self.file_content)

        content.fetched.connect(check_reply)
        content.download()
        while not self.loaded:
            app.processEvents()

        writeSimpleFile('my second content')
        content.download()
        with open(content.filePath(), encoding="utf-8") as file:
            self.assertNotEqual(file.readline().rstrip(), self.file_content)

        content.download(True)
        while not self.loaded:
            app.processEvents()

        os.remove('qgis_local_server/simple_content.txt')
    def testFormUi(self):
        layer = self.createLayer()
        config = layer.editFormConfig()

        config.setLayout(QgsEditFormConfig.GeneratedLayout)
        self.assertEqual(config.layout(), QgsEditFormConfig.GeneratedLayout)

        uiLocal = os.path.join(
            unitTestDataPath(), '/qgis_local_server/layer_attribute_form.ui')
        config.setUiForm(uiLocal)
        self.assertEqual(config.layout(), QgsEditFormConfig.UiFileLayout)

        config.setLayout(QgsEditFormConfig.GeneratedLayout)
        self.assertEqual(config.layout(), QgsEditFormConfig.GeneratedLayout)

        uiUrl = 'http://localhost:' + \
            str(self.port) + '/qgis_local_server/layer_attribute_form.ui'
        config.setUiForm(uiUrl)
        self.assertEqual(config.layout(), QgsEditFormConfig.UiFileLayout)
        content = QgsApplication.networkContentFetcherRegistry().fetch(uiUrl)
        self.assertTrue(content is not None)
        while True:
            if content.status() in (QgsFetchedContent.Finished, QgsFetchedContent.Failed):
                break
            app.processEvents()
        self.assertEqual(content.status(), QgsFetchedContent.Finished)
Example #3
0
    def testFetchReloadUrl(self):
        def writeSimpleFile(content):
            with open('qgis_local_server/simple_content.txt', 'w') as f:
                f.write(content)
            self.file_content = content

        registry = QgsApplication.networkContentFetcherRegistry()
        content = registry.fetch('http://localhost:' + str(self.port) + '/qgis_local_server/simple_content.txt')
        self.loaded = False
        writeSimpleFile('my initial content')

        def check_reply():
            self.loaded = True
            self.assertEqual(content.status(), QgsFetchedContent.Finished)
            self.assertEqual(content.error(), QNetworkReply.NoError)
            self.assertNotEqual(content.filePath(), '')
            with open(content.filePath(), encoding="utf-8") as file:
                self.assertEqual(file.readline().rstrip(), self.file_content)

        content.fetched.connect(check_reply)
        content.download()
        while not self.loaded:
            app.processEvents()

        writeSimpleFile('my second content')
        content.download()
        with open(content.filePath(), encoding="utf-8") as file:
            self.assertNotEqual(file.readline().rstrip(), self.file_content)

        content.download(True)
        while not self.loaded:
            app.processEvents()

        os.remove('qgis_local_server/simple_content.txt')
Example #4
0
    def testFormUi(self):
        layer = self.createLayer()
        config = layer.editFormConfig()

        config.setLayout(QgsEditFormConfig.GeneratedLayout)
        self.assertEqual(config.layout(), QgsEditFormConfig.GeneratedLayout)

        uiLocal = os.path.join(unitTestDataPath(),
                               '/qgis_local_server/layer_attribute_form.ui')
        config.setUiForm(uiLocal)
        self.assertEqual(config.layout(), QgsEditFormConfig.UiFileLayout)

        config.setLayout(QgsEditFormConfig.GeneratedLayout)
        self.assertEqual(config.layout(), QgsEditFormConfig.GeneratedLayout)

        uiUrl = 'http://localhost:' + str(
            self.port) + '/qgis_local_server/layer_attribute_form.ui'
        config.setUiForm(uiUrl)
        self.assertEqual(config.layout(), QgsEditFormConfig.UiFileLayout)
        content = QgsApplication.networkContentFetcherRegistry().fetch(uiUrl)
        self.assertTrue(content is not None)
        while True:
            if content.status() in (QgsFetchedContent.Finished,
                                    QgsFetchedContent.Failed):
                break
            app.processEvents()
        self.assertEqual(content.status(), QgsFetchedContent.Finished)
    def testLocalPath(self):
        registry = QgsApplication.networkContentFetcherRegistry()
        filePath = 'qgis_local_server/index.html'
        self.assertEqual(registry.localPath(filePath), filePath)

        # a non existent download shall return untouched the path
        self.assertEqual(registry.localPath('xxxx'), 'xxxx')

        # an existent but unfinished download should return an empty path
        content = registry.fetch('xxxx')
        self.assertEqual(registry.localPath('xxxx'), '')
    def testLocalPath(self):
        registry = QgsApplication.networkContentFetcherRegistry()
        filePath = 'qgis_local_server/index.html'
        self.assertEqual(registry.localPath(filePath), filePath)

        # a non existent download shall return untouched the path
        self.assertEqual(registry.localPath('xxxx'), 'xxxx')

        # an existent but unfinished download should return an empty path
        content = registry.fetch('xxxx')
        self.assertEqual(registry.localPath('xxxx'), '')
    def testFetchBadUrl(self):
        registry = QgsApplication.networkContentFetcherRegistry()
        content = registry.fetch('http://x')
        self.loaded = False

        def check_reply():
            self.assertEqual(content.status(), QgsFetchedContent.Failed)
            self.assertNotEqual(content.error(), QNetworkReply.NoError)
            self.assertEqual(content.filePath(), '')
            self.loaded = True

        content.fetched.connect(check_reply)
        content.download()
        while not self.loaded:
            app.processEvents()
    def testFetchBadUrl(self):
        registry = QgsApplication.networkContentFetcherRegistry()
        content = registry.fetch('http://x')
        self.loaded = False

        def check_reply():
            self.assertEqual(content.status(), QgsFetchedContent.Failed)
            self.assertNotEqual(content.error(), QNetworkReply.NoError)
            self.assertEqual(content.filePath(), '')
            self.loaded = True

        content.fetched.connect(check_reply)
        content.download()
        while not self.loaded:
            app.processEvents()
    def testFetchGoodUrl(self):
        url = 'http://localhost:' + str(self.port) + '/qgis_local_server/index.html'
        registry = QgsApplication.networkContentFetcherRegistry()
        content = registry.fetch(url)
        self.loaded = False

        def check_reply():
            self.loaded = True
            self.assertEqual(content.status(), QgsFetchedContent.Finished)
            self.assertEqual(content.error(), QNetworkReply.NoError)
            self.assertNotEqual(content.filePath(), '')

        content.fetched.connect(check_reply)
        content.download()
        while not self.loaded:
            app.processEvents()

        self.assertEqual(registry.localPath(url), content.filePath())

        # create new content with same URL
        contentV2 = registry.fetch(url)
        self.assertEqual(contentV2.status(), QgsFetchedContent.Finished)
    def testFetchGoodUrl(self):
        url = 'http://localhost:' + str(self.port) + '/qgis_local_server/index.html'
        registry = QgsApplication.networkContentFetcherRegistry()
        content = registry.fetch(url)
        self.loaded = False

        def check_reply():
            self.loaded = True
            self.assertEqual(content.status(), QgsFetchedContent.Finished)
            self.assertEqual(content.error(), QNetworkReply.NoError)
            self.assertNotEqual(content.filePath(), '')

        content.fetched.connect(check_reply)
        content.download()
        while not self.loaded:
            app.processEvents()

        self.assertEqual(registry.localPath(url), content.filePath())

        # create new content with same URL
        contentV2 = registry.fetch(url)
        self.assertEqual(contentV2.status(), QgsFetchedContent.Finished)