def functionalTests(): ''' functional tests. e.g. intergration test or all tests that require user interacion ''' try: from qgistester.test import Test except: return [] _tests = [] function1Test = Test("Function 1 description") function1Test.addStep("do preparation step 1", function1Step1) function1Test.addStep( "Message to user to do some action => press 'next step'") function1Test.addStep("do previous step check", function1Step2) function1Test.setCleanup(cleanUpFunction1) _tests.append(function1Test) function2Test = Test("Function 2 description") function2Test.addStep("do preparation step 1", function2Step1) function2Test.addStep( "Message to user to do some action => press 'next step'") function2Test.addStep("do previous step check", function2Step2) function2Test.setCleanup(cleanUpFunction2) _tests.append(function2Test) return _tests
def functionalTests(): try: from qgistester.test import Test except: return [] allTests = [] dragdropTest = Test("Verify dragging browser element into workspace") dragdropTest.addStep("Setting up catalog and explorer", utils.setUpCatalogAndExplorer) dragdropTest.addStep("Setting up test data project", utils.loadTestData) dragdropTest.addStep( "Drag layer from browser 'Project home->qgis_plugin_test_pt1.shp' into\ntest_catalog->Workspaces->test_workspace" ) dragdropTest.addStep("Checking new layer", utils.checkNewLayer) dragdropTest.setCleanup(utils.clean) allTests.append(dragdropTest) for testProject in utils.testProjects(): renderingTest = Test("Verify rendering of uploaded style (%s)" % os.path.basename(testProject)) renderingTest.addStep("Preparing data", partial(utils.openAndUpload, testProject)) renderingTest.addStep("Check that WMS layer is correctly rendered") renderingTest.setCleanup(utils.clean) allTests.append(renderingTest) return allTests
def functionalTests(): try: from qgistester.test import Test except: return [] dragdropTest = Test("Verify dragging browser element into workspace") # pki context setup dragdropTest.addStep("Setting up pki auth context", utils.initAuthManager) dragdropTest.addStep("configuring pki auth context", utils.populatePKITestCerts) # normal steps dragdropTest.addStep("Setting up catalog and explorer", utils.setUpCatalogAndExplorer) dragdropTest.addStep("Setting up test data project", utils.loadTestData) dragdropTest.addStep("Drag layer from browser 'Project home->qgis_plugin_test_pt1.shp' into\ntest_catalog->Workspaces->test_workspace") dragdropTest.addStep("Checking new layer", utils.checkNewLayer) # cleaup with clean of pki context dragdropTest.setCleanup(utils.cleanAndPki) vectorRenderingTest = Test("Verify rendering of uploaded style") # pki context setup vectorRenderingTest.addStep("Setting up pki auth context", utils.initAuthManager) vectorRenderingTest.addStep("configuring pki auth context", utils.populatePKITestCerts) # normal steps vectorRenderingTest.addStep("Preparing data", utils.openAndUpload) vectorRenderingTest.addStep("Check that WMS layer is correctly rendered") # cleaup with clean of pki context vectorRenderingTest.setCleanup(utils.cleanAndPki) return [dragdropTest, vectorRenderingTest]
def functionalTests(): try: from qgistester.test import Test except: return [] passingTest = Test('This test should pass') passingTest.addStep('Click on "Test passes"') skippedTest = Test('This test should be skiped') skippedTest.addStep('Click on "Skip test"') def failingFunction(): assert False failingTest = Test('This test should fail') failingTest.addStep("Failing step", function=failingFunction) failingSetupTest = Test('This test should fail in the step setup') failingSetupTest.addStep("Failing prestep", prestep=failingFunction) def errorFunction(): raise Exception("Error in test") errorTest = Test('This test should error') errorTest.addStep("Error step", function=errorFunction) return [passingTest, skippedTest, failingTest, failingSetupTest, errorTest]
def _comparisonTestCompiled(n): test = Test("Compiled app test '%s'" % n, "Compiled app tests") test.addStep("Setting up project", lambda: loadTestProject("widgets")) test.addStep("Creating web app", lambda: _createWebAppCompiled(n), prestep = _checkConnect) test.addStep("Compare web app with expected app in browser", prestep=lambda: _openComparisonCompiled(n)) return test
def functionalTests(): try: from qgistester.test import Test except: return [] def _loadLayer(): layerfile = os.path.join(os.path.dirname(__file__), "data", "MGRS_100kmSQ_ID_02H.shp") layer = loadLayer(layerfile, provider="ogr") QgsMapLayerRegistry.instance().addMapLayer(layer) def _setTool(): plugins["mgrstools"].setTool() def _zoomTo(): plugins["mgrstools"].zoomTo() mgrsTest = Test("Test MRGS tools") mgrsTest.addStep("Load layer", _loadLayer) mgrsTest.addStep("Select map tool", _setTool) mgrsTest.addStep("Click within the upper left polygon. Verify that the computed mrgrs coord starts with 02HKK'", isVerifyStep=True) mgrsTest.addStep("Open panel", _zoomTo) mgrsTest.addStep("Enter '02HKK' and click on 'zoom to'. Verify it centers the view on to the upper left polygon and adds a marker") mgrsTest.addStep("Click on 'remove marker' and verify it removes the marker") return [mgrsTest]
def functionalTests(): try: from qgistester.test import Test except: return [] def _loadLayer(): layerfile = os.path.join(os.path.dirname(__file__), "w3w.shp") layer = loadLayer(layerfile, provider="ogr") QgsMapLayerRegistry.instance().addMapLayer(layer) def _setTool(): plugins["what3words"].setTool() def _zoomTo(): plugins["what3words"].zoomTo() w3wTest = Test("Test w3w") w3wTest.addStep("Load layer", _loadLayer) w3wTest.addStep("Select map tool", _setTool) w3wTest.addStep( "Click within the layer polygon and verify that the computed 3 coords are 'healings.distorting.harsher'", isVerifyStep=True) w3wTest.addStep("Move map canvas", lambda: iface.mapCanvas().setCenter(QgsPoint(0, 0))) w3wTest.addStep("Open panel", _zoomTo) w3wTest.addStep( "Enter 'healings.distorting.harsher' and click on 'zoom to'. Verify it zooms to the polygon layer" ) w3wTest.addStep( "Click on 'remove marker' and verify it removes the marker") return [w3wTest]
def testSetIssueUrl(self): """Test is issue url is set""" issueUrl = 'http://www.example.com' name = 'this is the test name' t = Test(name) t.setIssueUrl(issueUrl) self.assertEqual(t.issueUrl, issueUrl)
def _comparisonTest(n): test = Test("Symbology test '%s'" % n) test.addStep("Setting up project", lambda: loadTestProject(n)) test.addStep("Creating web app", lambda: _createWebApp(n)) test.addStep("Compare web app with expected app in browser", prestep=lambda: _openComparison(n)) return test
def test__str___(self): """Test __str__ method""" t = Test('Test that was skipped') t.addStep('Skipped', lambda: False) tr = TestResult(t) self.assertEqual( '{}'.format(tr), 'Test name: -Test that was skipped\nTest result:Test skipped')
def testSetIssueUrl(self): """test the issue url is set.""" issueUrl = 'http://www.example.com' name = "this is the test name" t = Test(name) # do test t.setIssueUrl(issueUrl) self.assertEqual(t.issueUrl, issueUrl)
def test__str___(self): """test __str__ that convert a status in readamble string.""" t = Test('Test that skipped is set') t.addStep('Skipped', lambda: False) tr = TestResult(t) self.assertEqual( u"%s" % tr, 'Test name: -Test that skipped is set\nTest result:Test skipped')
def _testWidget(n): aboutContent = widgetTestAbout.get(n, None) test = Test("Verify '%s' widget" % n, "Widget tests") test.addStep("Setting up project", lambda: loadTestProject("widgets")) test.addStep("Creating web app", lambda: _createWebApp(n, True, aboutContent)) test.addStep("Verify web app in browser", prestep=lambda: webbrowser.open_new( "file:///" + webAppFolder.replace("\\","/") + "/webapp/index_debug.html")) return test
def testSkipped(self): """check if the skipped is correctly set.""" t = Test('Test that skipped is set') t.addStep('Skipped', lambda: False) tr = TestResult(t) tr.skipped() self.assertEqual(tr.status, tr.SKIPPED) self.assertIsNone(tr.errorStep) self.assertIsNone(tr.errorMessage, 'PASSED')
def testPassed(self): """Check if the passed flag is correctly set""" t = Test('Test that passed') t.addStep('Passed', lambda: False) tr = TestResult(t) tr.passed() self.assertEqual(tr.status, tr.PASSED) self.assertIsNone(tr.errorStep) self.assertIsNone(tr.errorMessage)
def _test(n): test = Test("Verify '%s' tutorial" % n) test.addStep("Setting up project", lambda: loadTestProject(n)) test.addStep("Creating web app", lambda: _createWebApp(n)) test.addStep("Verify web app in browser", prestep=lambda: webbrowser.open_new("file:///" + webAppFolder.replace( "\\", "/") + "/webapp/index_debug.html")) return test
def testFailed(self): """check if the fail flag is correctly set.""" t = Test('Test that fail is set') t.addStep('Fail', lambda: False) tr = TestResult(t) tr.failed('fake_step', 'FAILED') self.assertEqual(tr.status, tr.FAILED) self.assertEqual(tr.errorStep, 'fake_step') self.assertEqual(tr.errorMessage, 'FAILED')
def testSetCleanup(self): """test the cleanup function is set.""" def testFunction1(): pass name = "this is the test name" t = Test(name) # do test t.setCleanup(testFunction1) self.assertEqual(t.cleanup, testFunction1)
def testSetCleanup(self): """Test if cleanup function is set""" def testFunction1(): pass name = 'this is the test name' t = Test(name) t.setCleanup(testFunction1) self.assertEqual(t.cleanup, testFunction1)
def testInit(self): """check if __init__ is correctly executed.""" name = "this is the test name" t = Test(name) self.assertEqual(len(t.steps), 0) self.assertEqual(t.name, name) self.assertEqual(t.group, '') self.assertIn('<function <lambda> at ', str(t.cleanup)) self.assertIsNone(t.cleanup()) self.assertIsNone(t.issueUrl)
def functionalTests(): try: from qgistester.test import Test from qgistester.utils import layerFromName except: return [] dragdropTest = Test("Verify dragging browser element into workspace") dragdropTest.addStep("Setting up catalog and explorer", _setUpCatalogAndExplorer) dragdropTest.addStep("Drag layer from browser into testing workspace of testing catalog") dragdropTest.addStep("Checking new layer", _checkNewLayer) dragdropTest.setCleanup(_clean) vectorRenderingTest = Test("Verify rendering of uploaded style") vectorRenderingTest.addStep("Preparing data", _openAndUpload) vectorRenderingTest.addStep("Check that WMS layer is correctly rendered") vectorRenderingTest.setCleanup(_clean) return [dragdropTest, vectorRenderingTest]
def functionalTests(): try: from qgistester.test import Test except: return [] spatialiteTest = Test("Test Spatialite. QGIS-72") spatialiteTest.addStep("Load Spatialite layer", prestep=lambda:_loadSpatialite()) spatialiteTest.addStep("Open DB Manager", prestep=lambda:_openDBManager()) spatialiteTest.addStep("Check that 'test' layer is available " "in DB manager, in 'Virtual layers/QGIS layers'", isVerifyStep=True) aboutTest = Test("Verify dependency versions and providers in About dialog. QGIS-53") aboutTest.addStep("Open About dialog", prestep=lambda:_openAboutDialog()) if sys.platform == 'darwin': filePath = os.path.join(testPath, "data", "about.mac") else: filePath = os.path.join(testPath, "data", "about.windows") with open(filePath) as f: content = f.readlines() data = "" for line in content: data += "<p>{}</p>".format(line) aboutTest.addStep("Verify that content of the About dialog matches" "following data\n{}\n\n".format(data), isVerifyStep=True) logTest = Test("Verify in-app message log has no errors for default install. QGIS-54") logTest.addStep("Open log messages panel", prestep=lambda:_openLogMessagesDialog()) logTest.addStep("Review 'General' tab output. Check it has no issues", isVerifyStep=True) logTest.addStep("Check there are no errors in 'Plugins' tab", isVerifyStep=True) logTest.addStep("Check there are no errors in 'Qt' tab", isVerifyStep=True) return [spatialiteTest, logTest, aboutTest]
def functionalTests(): try: from qgistester.test import Tests except: return [] infoTests = Test("Verify report dialog") infoTests.addStep( "Open the reporting dialog and verify that it shows system information" ) infoTests.addStep("Verify that 'Copy to clipboard' button works correctly") return [infoTests]
def functionalTests(): try: from qgistester.test import Test except: return [] dragdropTest = Test("Verify dragging browser element into workspace") dragdropTest.addStep("Setting up catalog and explorer", utils.setUpCatalogAndExplorer) dragdropTest.addStep("Setting up test data project", utils.loadTestData) dragdropTest.addStep( "Drag layer from browser 'Project home->qgis_plugin_test_pt1.shp' into\ntest_catalog->Workspaces->test_workspace" ) dragdropTest.addStep("Checking new layer", utils.checkNewLayer) dragdropTest.setCleanup(utils.clean) vectorRenderingTest = Test("Verify rendering of uploaded style") vectorRenderingTest.addStep("Preparing data", utils.openAndUpload) vectorRenderingTest.addStep("Check that WMS layer is correctly rendered") vectorRenderingTest.setCleanup(utils.clean) return [dragdropTest, vectorRenderingTest]
def functionalTests(): spatialiteTest = Test("Test Spatialite. QGIS-72") spatialiteTest.addStep("Load Spatialite layer", _loadSpatialite) spatialiteTest.addStep("Open DB Manager", _openDBManager) spatialiteTest.addStep("Check that 'elk' layer is available in DB manager") aboutTest = Test("Verify dependency versions and providers in About dialog. QGIS-53") aboutTest.addStep("Open About dialog", _openAboutDialog) if sys.platform == 'darwin': descriptionFile = os.path.join(os.path.dirname(__file__), "data", "about.mac") else: descriptionFile = os.path.join(os.path.dirname(__file__), "data", "about.windows") aboutTest.addStep(descriptionFile) logTest = Test("Verify in-app message log has no errors for default install. QGIS-54") logTest.addStep("Open log messages panel", _openLogMessagesDialog) logTest.addStep("Review 'General' tab output", isVerifyStep = True) logTest.addStep("Check there are no errors in 'Plugins' tab", isVerifyStep = True) logTest.addStep("Check there is no 'Python warning' tab", isVerifyStep = True) logTest.addStep("Check there is no 'Qt' tab", isVerifyStep = True) logTest.addStep("Check there is no other tab", isVerifyStep = True) return [spatialiteTest, aboutTest, logTest]
def functionalTests(): try: from qgistester.test import Test from qgistester.utils import layerFromName except: return [] def sampleMethod(self): pass sampleTest = Test("Sample test") sampleTest.addStep("Sample step", sampleMethod) return [sampleTest]
def testAddStep(self): """Check if a test is correclty added""" def testFunction1(): pass def testFunction2(): pass description1 = 'this is a step description' description2 = 'this is a step description' preStep = Step(description1, testFunction1) t = Test('this is the test name') t.addStep(description2, testFunction2, preStep, True) self.assertEqual(len(t.steps), 1) s = t.steps[0] self.assertEqual(s.description, description2) self.assertEqual(s.function, testFunction2) self.assertEqual(s.prestep, preStep) self.assertTrue(s.isVerifyStep)
def testAddStep(self): """check if a test is correclty added.""" def testFunction1(): pass def testFunction2(): pass description1 = "this is a step description" description2 = "this is a step description" preStep = Step(description1, testFunction1) t = Test('this is the test name') # do test t.addStep(description2, testFunction2, preStep, True) self.assertEqual(len(t.steps), 1) s = t.steps[0] self.assertTrue(s.description == description2) self.assertTrue(s.function == testFunction2) self.assertTrue(s.prestep == preStep) self.assertTrue(s.isVerifyStep)
def functionalTests(): try: from qgistester.test import Test except: return [] initial_models = None final_models = None def open_schema_import_dialog(models): plugin = qgis.utils.plugins['asistente_ladm_col'] plugin.show_dlg_import_schema(**models) def open_schema_import_dialog_model1(): open_schema_import_dialog({'selected_models': [LADMColModelRegistry().model(LADMNames.SUPPLIES_MODEL_KEY).full_name()]}) def open_schema_import_dialog_model2(): open_schema_import_dialog({'selected_models': [LADMColModelRegistry().model(LADMNames.SNR_DATA_SUPPLIES_MODEL_KEY).full_name()]}) def get_initial_models_in_cache(): global initial_models initial_models = get_models_in_cache() def get_models_in_cache(): plugin = qgis.utils.plugins['asistente_ladm_col'] models = [record[QueryNames.MODEL] for record in plugin.app.core.get_cached_layers()] models = set(models) if None in models: models.remove(None) return models def get_final_models_in_cache(): global final_models final_models = get_models_in_cache() def validate_initial_final_models(): global initial_models global final_models assert len(final_models -initial_models) > 0, "Modelos iniciales: {}, Modelos finales: {}".format(initial_models, final_models) layer_relations_cache_test = Test( 'CACHE DE CAPAS Y RELACIONES DEBE SER RECONSTRUIDO SI SE EJECUTÓ BIEN UN SCHEMA IMPORT.') layer_relations_cache_test.addStep("""INSTRUCCIONES:<br> 1. Se abrirá por 1era vez el diálogo Schema Import automáticamente.<br> 1.a Selecciona una conexión nueva (se recomienda a GPKG).<br> 1.b Dale click a Run para importar la estructura pre-seleccionada a la GPKG.<br> 1.c Cierra el diálogo.<br> 2. Se abrirá por 2da vez el diálogo Schema Import automáticamente.<br> 2.a Dale click a Run para importar la estructura pre-seleccionada a la GPKG.<br> 2.b Cierra el diálogo.<br><br> Luego de esto, el test evaluará automáticamente si el caché de capas y relaciones se reconstruyó. """) layer_relations_cache_test.addStep('Usar diálogo Schema Import (1era vez)...', open_schema_import_dialog_model1) layer_relations_cache_test.addStep('Obtener modelos en 1er Schema Import', get_initial_models_in_cache) layer_relations_cache_test.addStep('¿Todo va bien?', isVerifyStep=True) layer_relations_cache_test.addStep('Usar diálogo Schema Import (2da vez)...', open_schema_import_dialog_model2) layer_relations_cache_test.addStep('¿Hasta acá todo va bien?', isVerifyStep=True) layer_relations_cache_test.addStep('Obtener modelos en 2do Schema Import', get_final_models_in_cache) layer_relations_cache_test.addStep('Se reconstruyó el cache? Esto es, hay más modelos finales que iniciales?', validate_initial_final_models) return [layer_relations_cache_test]
def functionalTests(): try: from qgistester.test import Test from qgistester.utils import layerFromName except: return [] def _createWebApp(n): global webAppFolder webAppFolder = createAppFromTestAppdef(n) def _test(n): test = Test("Verify '%s' tutorial" % n) test.addStep("Setting up project", lambda: loadTestProject(n)) test.addStep("Creating web app", lambda: _createWebApp(n)) test.addStep("Verify web app in browser", prestep=lambda: webbrowser.open_new("file:///" + webAppFolder.replace( "\\", "/") + "/webapp/index_debug.html")) return test tests = [_test("bakeries"), _test("schools"), _test("fires")] unconfiguredBookmarksTest = Test( "Verify bookmarks widget cannot be used if no bookmarks defined") unconfiguredBookmarksTest.addStep("Load project", lambda: loadTestProject()) unconfiguredBookmarksTest.addStep("Open WAB", lambda: openWAB()) unconfiguredBookmarksTest.addStep( "Try to create an app with the bookmarks widget, without configuring it to add bookmarks.\n" "Verify it shows a warning.") unconfiguredBookmarksTest.setCleanup(closeWAB) tests.append(unconfiguredBookmarksTest) unsupportedSymbologyTest = Test("Verify warning for unsupported symbology") unsupportedSymbologyTest.addStep("Load project", lambda: loadTestProject()) unsupportedSymbologyTest.addStep("Open WAB", openWAB) unsupportedSymbologyTest.addStep( "Click on 'Preview'. Verify a warning about unsupported symbology is shown.\n" "Verify it shows a warning.") tests.append(unsupportedSymbologyTest) unsupportedSymbologyTest.setCleanup(closeWAB) wrongLogoTest = Test("Verify warning for wrong logo file") wrongLogoTest.addStep("Load project", lambda: loadTestProject()) wrongLogoTest.addStep("Open WAB", openWAB) wrongLogoTest.addStep( "Enter 'wrong' in the logo textbox and click on 'Preview'." "The logo texbox should get a yellow background.") wrongLogoTest.setCleanup(closeWAB) tests.append(wrongLogoTest) previewWithAllWidgetsTest = Test("Verify preview of an app with all tests") previewWithAllWidgetsTest.addStep("Load project", lambda: loadTestProject("layers")) appdef = testAppdef("allwidgets", False) previewWithAllWidgetsTest.addStep("Open WAB", lambda: openWAB(appdef)) previewWithAllWidgetsTest.addStep( "Click on 'Preview' and verify app is correctly shown and it works.") previewWithAllWidgetsTest.setCleanup(closeWAB) tests.append(previewWithAllWidgetsTest) return tests