예제 #1
0
 def test_convert_only_jas(self):
     """Runs the converter and verifies the output."""
     # test with the English OBS
     zip_file = os.path.join(self.resources_dir, 'eight_bible_books.zip')
     zip_file = self.make_duplicate_zip_that_can_be_deleted(zip_file)
     out_zip_file = tempfile.mktemp('.zip', dir=self.temp_dir)
     source_url = 'http://test.com/preconvert/22f3d09f7a.zip?convert_only=60-JAS.usfm'
     with closing(Usfm2HtmlConverter(source_url, 'udb',
                                     out_zip_file)) as tx:
         tx.input_zip_file = zip_file
         results = tx.run()
     # verify the output
     self.assertTrue(os.path.isfile(out_zip_file),
                     "There was no output zip file produced.")
     self.assertIsNotNone(results)
     self.out_dir = tempfile.mkdtemp(prefix='udb_', dir=self.temp_dir)
     unzip(out_zip_file, self.out_dir)
     files_to_verify = ['60-JAS.html']
     for file_to_verify in files_to_verify:
         file_name = os.path.join(self.out_dir, file_to_verify)
         self.assertTrue(os.path.isfile(file_name),
                         'UDB HTML file not found: {0}'.format(file_name))
     files_to_not_verify = [
         '61-1PE.html', '62-2PE.html', '63-1JN.html', '64-2JN.html',
         '65-3JN.html', '66-JUD.html', '67-REV.html'
     ]
     for file_to_verify in files_to_not_verify:
         file_name = os.path.join(self.out_dir, file_to_verify)
         self.assertFalse(os.path.isfile(file_name),
                          'UDB HTML file not found: {0}'.format(file_name))
     self.assertEqual(tx.source, source_url.split('?')[0])
예제 #2
0
 def test_bad_source(self):
     """This tests giving a bad source to the converter"""
     with closing(Usfm2HtmlConverter('bad_source', 'bad_resource')) as tx:
         result = tx.run()
     self.assertFalse(result['success'])
     self.assertEqual(result['errors'], [
         u'Conversion process ended abnormally: Failed to download bad_source'
     ])
예제 #3
0
    def test_close(self):
        """This tests that the temp directories are deleted when the class is closed."""

        with closing(Usfm2HtmlConverter('', '')) as tx:
            download_dir = tx.download_dir
            files_dir = tx.files_dir
            out_dir = tx.output_dir

            # verify the directories are present
            self.assertTrue(os.path.isdir(download_dir))
            self.assertTrue(os.path.isdir(files_dir))
            self.assertTrue(os.path.isdir(out_dir))

        # now they should have been deleted
        self.assertFalse(os.path.isdir(download_dir))
        self.assertFalse(os.path.isdir(files_dir))
        self.assertFalse(os.path.isdir(out_dir))
예제 #4
0
 def test_matt_complete_with_backslash(self):
     """
     Runs the converter and verifies the output
     """
     zip_file = os.path.join(self.resources_dir, 'kpb_mat_text_udb.zip')
     zip_file = self.make_duplicate_zip_that_can_be_deleted(zip_file)
     out_zip_file = tempfile.mktemp('.zip', dir=self.temp_dir)
     with closing(Usfm2HtmlConverter('', 'udb', out_zip_file)) as tx:
         tx.input_zip_file = zip_file
         results = tx.run()
     # verify the output
     self.assertTrue(os.path.isfile(out_zip_file),
                     "There was no output zip file produced.")
     self.assertIsNotNone(results)
     self.out_dir = tempfile.mkdtemp(prefix='udb_', dir=self.temp_dir)
     unzip(out_zip_file, self.out_dir)
     files_to_verify = ['41-MAT.html']
     self.verify_files(files_to_verify)
예제 #5
0
 def test_php_illegal_url(self):
     """
     Runs the converter and verifies the output
     """
     # test with the English OBS
     zip_file = os.path.join(self.resources_dir, '51-PHP.zip')
     zip_file = self.make_duplicate_zip_that_can_be_deleted(zip_file)
     out_zip_file = tempfile.mktemp('.zip', dir=self.temp_dir)
     with closing(Usfm2HtmlConverter(' ', 'udb', out_zip_file)) as tx:
         tx.input_zip_file = zip_file
         results = tx.run()
     # verify the output
     self.assertTrue(os.path.isfile(out_zip_file),
                     "There was no output zip file produced.")
     self.assertIsNotNone(results)
     self.out_dir = tempfile.mkdtemp(prefix='udb_', dir=self.temp_dir)
     unzip(out_zip_file, self.out_dir)
     files_to_verify = ['51-PHP.html']
     self.verify_files(files_to_verify)
예제 #6
0
 def get_converter(self, params):
     source = params['source']
     resource = params['resource_type']
     cdn_file = params['cdn_file']
     options = params['options']
     identifier = None if 'identifier' not in params else params[
         'identifier']
     convert_callback = None if 'convert_callback' not in params else params[
         'convert_callback']
     converter = Usfm2HtmlConverter(source,
                                    resource,
                                    cdn_file=cdn_file,
                                    options=options,
                                    convert_callback=convert_callback,
                                    identifier=identifier)
     converter.download_return = True
     converter.upload_return = True
     converter.convert_return = True
     return converter