Ejemplo n.º 1
0
    def test08_FtpExporterTempFolder(self):
        """Test FTP exporter generation of temp folder"""
        e = FtpExporter()
        e.host = None
        self.assertTrue(e.exportDirectory())
        prev_folder = e.exportDirectory()

        e.postProcess('')
        # a new export folder should be generated to avoid outdated files
        self.assertNotEqual(e.exportDirectory(), prev_folder)
Ejemplo n.º 2
0
    def test05_RegistrySaveReadFromProject(self):
        """ test saving and restoring current exporter in project"""
        e = FolderExporter()
        e.folder = '/my_folder'
        EXPORTER_REGISTRY.writeToProject(e)

        restored = EXPORTER_REGISTRY.createFromProject()
        self.assertEqual(type(restored), FolderExporter)
        self.assertEqual(restored.exportDirectory(), '/my_folder')

        # try with a non-folder exporter
        f = FtpExporter()
        EXPORTER_REGISTRY.writeToProject(f)
        restored = EXPORTER_REGISTRY.createFromProject()
        self.assertEqual(type(restored), FtpExporter)
Ejemplo n.º 3
0
    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))
        content = open(expected_index_file, 'r').readlines()
        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))
        content = open(expected_sub_folder_index_file, 'r').readlines()
        self.assertEqual(content, ['test2'])
Ejemplo n.º 4
0
    def test07_FtpExporterSaveReadFromProject(self):
        """Test saving and restoring FTP exporter settings in project"""
        e = FtpExporter()
        e.host = 'geocities.com'
        e.username = '******'
        e.port = 123
        e.remote_folder = 'test_folder'
        e.writeToProject()

        restored = FtpExporter()
        restored.readFromProject()

        self.assertEqual(restored.host, 'geocities.com')
        self.assertEqual(restored.username, 'sup3Raw3s0m64')
        self.assertEqual(restored.remote_folder, 'test_folder')
        self.assertEqual(restored.port, 123)
Ejemplo n.º 5
0
    def test09_FtpUpload(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')

        e.postProcess(out_file)

        expected_index_file = os.path.join(FTP_USER_FOLDER, 'public_html',
                                           'index.html')
        self.assertTrue(os.path.exists(expected_index_file))
        content = open(expected_index_file, 'r').readlines()
        self.assertEqual(content, ['test'])

        # try overwriting existing file
        with open(out_file, 'w') as i:
            i.write('test2')
        e.postProcess(out_file)
        self.assertTrue(expected_index_file)
        content = open(expected_index_file, 'r').readlines()
        self.assertEqual(content, ['test2'])