class testApi(unittest.TestCase): ## test helpers def setUp(self): self.api = Api(api_key=os.environ.get('API_KEY')) def tearDown(self): self.api = None def test_01_if_request_without_auth_works(self): response = self.api.get("/conversiontypes", { 'inputformat': 'pdf', 'outputformat': 'jpg' }, False) self.assertIsNotNone(response) def test_02_if_request_with_auth_works(self): response = self.api.post("/process", { 'inputformat': 'pdf', 'outputformat': 'jpg' }, True) self.assertIsNotNone(response) def test_03_if_process_creation_works(self): process = self.api.createProcess({ 'inputformat': 'pdf', 'outputformat': 'jpg' }) self.assertIsInstance(process, Process) def test_04_if_process_creation_with_invalid_format_throws_the_right_exception(self): with self.assertRaises(BadRequest): self.api.createProcess({ 'inputformat': 'invalid', 'outputformat': 'jpg' })
class testApi(unittest.TestCase): ## test helpers def setUp(self): self.api = Api(api_key=os.environ.get('API_KEY')) def tearDown(self): self.api = None def test_01_if_request_without_auth_works(self): response = self.api.get("/conversiontypes", { 'inputformat': 'pdf', 'outputformat': 'jpg' }, False) self.assertIsNotNone(response) def test_02_if_request_with_auth_works(self): response = self.api.post("/process", { 'inputformat': 'pdf', 'outputformat': 'jpg' }, True) self.assertIsNotNone(response) def test_03_if_process_creation_works(self): process = self.api.createProcess({ 'inputformat': 'pdf', 'outputformat': 'jpg' }) self.assertIsInstance(process, Process) def test_04_if_process_creation_with_invalid_format_throws_the_right_exception( self): with self.assertRaises(BadRequest): self.api.createProcess({ 'inputformat': 'invalid', 'outputformat': 'jpg' })
def setUp(self): self.api = Api(api_key=os.environ.get('API_KEY'))
class testProcess(unittest.TestCase): ## test helpers def setUp(self): self.api = Api(api_key=os.environ.get('API_KEY')) def tearDown(self): self.api = None def test_01_if_process_with_input_download_works(self): process = self.api.createProcess({ 'inputformat': 'png', 'outputformat': 'jpg' }) process.start({ 'input': 'download', 'outputformat': 'jpg', 'wait': True, 'file': 'https://cloudconvert.com/blog/wp-content/themes/cloudconvert/img/logo_96x60.png' }) self.assertEqual(process['step'], 'finished') self.assertEqual(process['output']['ext'], 'jpg') ## cleanup process.delete() def test_02_if_process_with_input_upload_works(self): process = self.api.createProcess({ 'inputformat': 'png', 'outputformat': 'jpg' }) process.start({ 'input': 'upload', 'outputformat': 'jpg', 'wait': True, 'file': open('tests/input.png', 'rb') }) self.assertEqual(process['step'], 'finished') self.assertEqual(process['output']['ext'], 'jpg') ## cleanup process.delete() def test_03_if_process_with_input_upload_and_custom_options_works(self): process = self.api.createProcess({ 'inputformat': 'png', 'outputformat': 'jpg' }) process.start({ 'input': 'upload', 'outputformat': 'jpg', 'wait': True, 'file': open('tests/input.png', 'rb'), 'converteroptions': { 'quality': 10 } }) self.assertEqual(process['step'], 'finished') self.assertEqual(process['output']['ext'], 'jpg') self.assertEqual(int(process['converter']['options']['quality']), 10) ## cleanup process.delete() def test_04_if_download_of_output_file_works(self): process = self.api.createProcess({ 'inputformat': 'png', 'outputformat': 'pdf' }) process.start({ 'input': 'upload', 'outputformat': 'pdf', 'file': open('tests/input.png', 'rb') }) process.wait() process.download("output.pdf") self.assertTrue(os.path.isfile("output.pdf")) ## cleanup os.remove("output.pdf") process.delete() def test_05_if_download_of_multiple_output_file_works(self): process = self.api.createProcess({ 'inputformat': 'pdf', 'outputformat': 'jpg' }) process.start({ 'input': 'upload', 'outputformat': 'jpg', 'file': open('tests/input.pdf', 'rb'), 'converteroptions': { 'page_range': '1-2' } }) process.wait() process.downloadAll() self.assertTrue(os.path.isfile("input-0.jpg")) self.assertTrue(os.path.isfile("input-1.jpg")) ## cleanup os.remove("input-0.jpg") os.remove("input-1.jpg") process.delete() def test_06_if_convert_shortcut_works(self): process = self.api.convert({ 'inputformat': 'png', 'outputformat': 'jpg', 'input': 'upload', 'file': open('tests/input.png', 'rb') }).wait() self.assertEqual(process['step'], 'finished') self.assertEqual(process['output']['ext'], 'jpg') ## cleanup process.delete()
class testProcess(unittest.TestCase): ## test helpers def setUp(self): self.api = Api(api_key=os.environ.get('API_KEY')) def tearDown(self): self.api = None def test_01_if_process_with_input_download_works(self): process = self.api.createProcess({ 'inputformat': 'png', 'outputformat': 'jpg' }) process.start({ 'input': 'download', 'outputformat': 'jpg', 'wait': True, 'file': 'https://cloudconvert.com/blog/wp-content/themes/cloudconvert/img/logo_96x60.png' }) self.assertEqual(process['step'],'finished') self.assertEqual(process['output']['ext'],'jpg') ## cleanup process.delete() def test_02_if_process_with_input_upload_works(self): process = self.api.createProcess({ 'inputformat': 'png', 'outputformat': 'jpg' }) process.start({ 'input': 'upload', 'outputformat': 'jpg', 'wait': True, 'file': open('tests/input.png', 'rb') }) self.assertEqual(process['step'],'finished') self.assertEqual(process['output']['ext'],'jpg') ## cleanup process.delete() def test_03_if_process_with_input_upload_and_custom_options_works(self): process = self.api.createProcess({ 'inputformat': 'png', 'outputformat': 'jpg' }) process.start({ 'input': 'upload', 'outputformat': 'jpg', 'wait': True, 'file': open('tests/input.png', 'rb'), 'converteroptions': { 'quality': 10 } }) self.assertEqual(process['step'],'finished') self.assertEqual(process['output']['ext'],'jpg') self.assertEqual(int(process['converter']['options']['quality']),10) ## cleanup process.delete() def test_04_if_download_of_output_file_works(self): process = self.api.createProcess({ 'inputformat': 'png', 'outputformat': 'pdf' }) process.start({ 'input': 'upload', 'outputformat': 'pdf', 'file': open('tests/input.png', 'rb') }) process.wait() process.download("output.pdf") self.assertTrue(os.path.isfile("output.pdf")) ## cleanup os.remove("output.pdf") process.delete() def test_05_if_download_of_multiple_output_file_works(self): process = self.api.createProcess({ 'inputformat': 'pdf', 'outputformat': 'jpg' }) process.start({ 'input': 'upload', 'outputformat': 'jpg', 'file': open('tests/input.pdf', 'rb'), 'converteroptions': { 'page_range': '1-2' } }) process.wait() process.downloadAll() self.assertTrue(os.path.isfile("input-0.jpg")) self.assertTrue(os.path.isfile("input-1.jpg")) ## cleanup os.remove("input-0.jpg") os.remove("input-1.jpg") process.delete() def test_06_if_convert_shortcut_works(self): process = self.api.convert({ 'inputformat': 'png', 'outputformat': 'jpg', 'input': 'upload', 'file': open('tests/input.png', 'rb') }).wait() self.assertEqual(process['step'],'finished') self.assertEqual(process['output']['ext'],'jpg') ## cleanup process.delete()