def test02_FolderExporterPostProcess(self): """Test folder exporter post processing""" e = FolderExporter() result = WriterResult() result.index_file = '/tmp/file.htm' e.postProcess(result) self.assertEqual(e.destinationUrl(), '/tmp/file.htm')
def test02_FolderExporterPostProcess(self): """Test folder exporter post processing""" e = FolderExporter() result = WriterResult() result.index_file = '/tmp/file.htm' e.postProcess(result) self.assertEqual(e.destinationUrl(), '/tmp/file.htm')
def test08_FtpExporterTempFolder(self): """Test FTP exporter generation of temp folder""" e = FtpExporter() e.host = None self.assertTrue(e.exportDirectory()) prev_folder = e.exportDirectory() result = WriterResult() result.index_file = '' e.postProcess(result) # a new export folder should be generated to avoid outdated files self.assertNotEqual(e.exportDirectory(), prev_folder)
def test08_FtpExporterTempFolder(self): """Test FTP exporter generation of temp folder""" e = FtpExporter() e.host = None self.assertTrue(e.exportDirectory()) prev_folder = e.exportDirectory() result = WriterResult() result.index_file = '' e.postProcess(result) # a new export folder should be generated to avoid outdated files self.assertNotEqual(e.exportDirectory(), prev_folder)
def test10_FtpUploadSubfolder(self): e = FtpExporter() e.host = 'localhost' e.port = TEST_PORT e.username = '******' e.password = '******' # copy some files to export directory export_folder = e.exportDirectory() try: os.makedirs(export_folder) except Exception: self.assertTrue(False, 'could not create export directory') out_file = os.path.join(export_folder, 'index.html') with open(out_file, 'w') as i: i.write('test') sub_folder = os.path.join(export_folder, 'sub') try: os.makedirs(sub_folder) except Exception: self.assertTrue(False, 'could not create export directory') sub_folder_out_file = os.path.join(sub_folder, 'index.html') with open(sub_folder_out_file, 'w') as i: i.write('test2') result = WriterResult() result.index_file = out_file result.folder = export_folder e.postProcess(result) expected_index_file = os.path.join(FTP_USER_FOLDER, 'public_html', 'index.html') self.assertTrue(os.path.exists(expected_index_file)) f = open(expected_index_file, 'r') content = f.readlines() f.close() self.assertEqual(content, ['test']) expected_sub_folder_index_file = os.path.join(FTP_USER_FOLDER, 'public_html', 'sub', 'index.html') self.assertTrue(os.path.exists(expected_sub_folder_index_file)) f = open(expected_sub_folder_index_file, 'r') content = f.readlines() f.close() self.assertEqual(content, ['test2'])
def test10_FtpUploadSubfolder(self): e = FtpExporter() e.host = 'localhost' e.port = TEST_PORT e.username = '******' e.password = '******' # copy some files to export directory export_folder = e.exportDirectory() try: os.makedirs(export_folder) except: self.assertTrue(False, 'could not create export directory') out_file = os.path.join(export_folder, 'index.html') with open(out_file, 'w') as i: i.write('test') sub_folder = os.path.join(export_folder, 'sub') try: os.makedirs(sub_folder) except: self.assertTrue(False, 'could not create export directory') sub_folder_out_file = os.path.join(sub_folder, 'index.html') with open(sub_folder_out_file, 'w') as i: i.write('test2') result = WriterResult() result.index_file = out_file result.folder = export_folder e.postProcess(result) expected_index_file = os.path.join( FTP_USER_FOLDER, 'public_html', 'index.html') self.assertTrue(os.path.exists(expected_index_file)) f = open(expected_index_file, 'r') content = f.readlines() f.close() self.assertEqual(content, ['test']) expected_sub_folder_index_file = os.path.join( FTP_USER_FOLDER, 'public_html', 'sub', 'index.html') self.assertTrue(os.path.exists(expected_sub_folder_index_file)) f = open(expected_sub_folder_index_file, 'r') content = f.readlines() f.close() self.assertEqual(content, ['test2'])
def write(self, iface, dest_folder, feedback=None): if not feedback: feedback = Feedback() feedback.showFeedback('Creating Mapbox map...') self.preview_file = self.writeMapbox( iface, feedback, layer_list=self.layers, popup=self.popup, visible=self.visible, json=self.json, cluster=self.cluster, getFeatureInfo=self.getFeatureInfo, params=self.params, folder=dest_folder) result = WriterResult() result.index_file = self.preview_file result.folder = os.path.dirname(self.preview_file) for dirpath, dirnames, filenames in os.walk(result.folder): result.files.extend([os.path.join(dirpath, f) for f in filenames]) return result
def write(self, iface, dest_folder, feedback=None): if not feedback: feedback = Feedback() feedback.showFeedback('Creating OpenLayers map...') self.preview_file = self.writeOL(iface, feedback, layers=self.layers, groups=self.groups, popup=self.popup, visible=self.visible, json=self.json, clustered=self.cluster, getFeatureInfo=self.getFeatureInfo, settings=self.params, folder=dest_folder) result = WriterResult() result.index_file = self.preview_file result.folder = os.path.dirname(self.preview_file) for dirpath, dirnames, filenames in os.walk(result.folder): result.files.extend([os.path.join(dirpath, f) for f in filenames]) return result