class Test_1_DataStore(unittest.TestCase): UCONF = 'TEST' LGVAL = 'v:x100' DESTNAME = 'PostgreSQL' def setUp(self): testlog.debug('LDSDataStore_Test.setUp') self.ldsdatastore = LDSDataStore(None, self.UCONF) def tearDown(self): testlog.debug('LDSDataStore_Test.tearDown') def test_1_getLayerOptions(self): cfl = [ 'CPL_DEBUG=OFF', 'GDAL_HTTP_USERAGENT=LDSReplicate/0.0.9.0', 'OGR_WFS_PAGING_ALLOWED=OFF', 'OGR_WFS_PAGE_SIZE=10000', 'OGR_WFS_USE_STREAMING=NO', 'OGR_WFS_LOAD_MULTIPLE_LAYER_DEFN=OFF', 'OGR_WFS_BASE_START_INDEX=0' ] self.assertEqual(self.ldsdatastore.getConfigOptions()[1], cfl[1], 'config options 1') self.assertEqual(self.ldsdatastore.getConfigOptions()[2], cfl[2], 'config options 2') self.assertEqual(self.ldsdatastore.getConfigOptions()[3], cfl[3], 'config options 3') self.assertEqual(self.ldsdatastore.getConfigOptions()[4], cfl[4], 'config options 4') self.assertEqual(self.ldsdatastore.getConfigOptions()[5], cfl[5], 'config options 5') def test_2_getCapabilities(self): self.assertEqual(self.ldsdatastore.getCapabilities()[74:77], 'WFS', 'uri service') self.assertEqual(self.ldsdatastore.getCapabilities()[86:91], '1.1.0', 'uri version') self.assertEqual(self.ldsdatastore.getCapabilities()[100:115], 'GetCapabilities', 'uri getcapabilities') def test_3_fetchLayerInfo(self): rsl = [ ('v:x845', '12 Mile Territorial Sea Limit Basepoints', ['New Zealand', 'Hydrographic & Maritime', 'Maritime Boundaries']), ('v:x846', '12 Mile Territorial Sea Outer Limit', ['New Zealand', 'Hydrographic & Maritime', 'Maritime Boundaries']) ] gcu = self.ldsdatastore.getCapabilities() res = self.ldsdatastore.fetchLayerInfo(gcu) self.assertEqual(res[0][0], rsl[0][0], 'res 00') self.assertEqual(res[1][1], rsl[1][1], 'res 11') self.assertEqual(res[0][2][0], rsl[0][2][0], 'res 020') self.assertEqual(res[1][2][1], rsl[1][2][1], 'res 121')
def testConnection(self): if not self.usrdefradio.isChecked(): return True if not any(f for f in (self.hostEdit.isModified(),self.portEdit.isModified(), self.usrEdit.isModified(),self.pwdEdit.isModified())): return False proxydata = {'type':'USER','host':str(self.hostEdit.text()),'port':str(self.portEdit.text()), 'auth':str(WFSDataStore.PROXY_AUTH[self.authSelect.currentIndex()-1]), 'user':str(self.usrEdit.text()),'pass':str(self.pwdEdit.text())} wfsdata = {'key':'00112233445566778899aabbccddeeff'}#key not necessary but config tester checks format lds = LDSDataStore(None,{'Proxy':proxydata,'WFS':wfsdata}) lds.applyConfigOptions() try: #use website likely to be up (that isn't LDS so error is distinct) lds.initDS('http://www.google.com/',False) except DatasourceConnectException as dce: QMessageBox.warning(self, 'Connection Error', 'Cannot connect to network using proxy parameters provided {}'.format(dce), 'OK') return False except DatasourceOpenException as dse: QMessageBox.info(self, 'Connection Warning', 'Connection parameters confirmed, Datasource initialisation untested. Continuing.\n{}'.format(dse), 'OK') return True except RuntimeError as rte: QMessageBox.warning(self, 'RuntimeError', 'Error connecting to network: '+str(rte), 'OK') return False return True
class Test_1_DataStore(unittest.TestCase): UCONF = 'TEST' LGVAL = 'v:x100' DESTNAME = 'PostgreSQL' def setUp(self): testlog.debug('LDSDataStore_Test.setUp') self.ldsdatastore = LDSDataStore(None,self.UCONF) def tearDown(self): testlog.debug('LDSDataStore_Test.tearDown') def test_1_getLayerOptions(self): cfl = ['CPL_DEBUG=OFF', 'GDAL_HTTP_USERAGENT=LDSReplicate/0.0.9.0', 'OGR_WFS_PAGING_ALLOWED=OFF', 'OGR_WFS_PAGE_SIZE=10000', 'OGR_WFS_USE_STREAMING=NO', 'OGR_WFS_LOAD_MULTIPLE_LAYER_DEFN=OFF', 'OGR_WFS_BASE_START_INDEX=0'] self.assertEqual(self.ldsdatastore.getConfigOptions()[1],cfl[1],'config options 1') self.assertEqual(self.ldsdatastore.getConfigOptions()[2],cfl[2],'config options 2') self.assertEqual(self.ldsdatastore.getConfigOptions()[3],cfl[3],'config options 3') self.assertEqual(self.ldsdatastore.getConfigOptions()[4],cfl[4],'config options 4') self.assertEqual(self.ldsdatastore.getConfigOptions()[5],cfl[5],'config options 5') def test_2_getCapabilities(self): self.assertEqual(self.ldsdatastore.getCapabilities()[74:77],'WFS','uri service') self.assertEqual(self.ldsdatastore.getCapabilities()[86:91],'1.1.0','uri version') self.assertEqual(self.ldsdatastore.getCapabilities()[100:115],'GetCapabilities','uri getcapabilities') def test_3_fetchLayerInfo(self): rsl = [('v:x845', '12 Mile Territorial Sea Limit Basepoints', ['New Zealand', 'Hydrographic & Maritime', 'Maritime Boundaries']), ('v:x846', '12 Mile Territorial Sea Outer Limit', ['New Zealand', 'Hydrographic & Maritime', 'Maritime Boundaries'])] gcu = self.ldsdatastore.getCapabilities() res = self.ldsdatastore.fetchLayerInfo(gcu) self.assertEqual(res[0][0],rsl[0][0],'res 00') self.assertEqual(res[1][1],rsl[1][1],'res 11') self.assertEqual(res[0][2][0],rsl[0][2][0],'res 020') self.assertEqual(res[1][2][1],rsl[1][2][1],'res 121')
def _newSRC(self): '''Initialise a new source, LDS nominally''' src = LDSDataStore(self.cs, self.uc) #src.setPartitionSize(partition_size)#partitionsize may not exist when this is called but thats okay! src.applyConfigOptions() return src
def setUp(self): testlog.debug('LDSDataStore_Test.setUp') self.ldsdatastore = LDSDataStore(None,self.UCONF)
def _newSRC(self): '''Initialise a new source, LDS nominally''' src = LDSDataStore(self.cs,self.uc) #src.setPartitionSize(partition_size)#partitionsize may not exist when this is called but thats okay! src.applyConfigOptions() return src
def readCapsDoc(self,src): '''Fetch, format and store the capabilities document''' if not hasattr(self,'lds_caps'): self.lds_caps = LU.treeDecode(LDSDataStore.fetchLayerInfo(src.getCapabilities(),src.ver,src.pxy))