-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathtest_convertapi.py
More file actions
77 lines (61 loc) · 2.6 KB
/
Copy pathtest_convertapi.py
File metadata and controls
77 lines (61 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import convertapi
import os
import io
import tempfile
import requests
import responses
from . import utils
from nose.tools import *
class TestConvertapi(utils.TestCase):
def setUp(self):
convertapi.api_credentials = os.environ['CONVERT_API_SECRET']
convertapi.max_parallel_uploads = 10
def test_defaults(self):
eq_('https://v2.convertapi.com/', convertapi.base_uri)
def test_configuration(self):
convertapi.api_credentials = 'TEST'
eq_('TEST', convertapi.api_credentials)
def test_convert_file(self):
result = convertapi.convert('pdf', { 'File': 'examples/files/test.docx' })
assert result.save_files(tempfile.gettempdir())
assert result.conversion_cost > 0
def test_convert_file_no_parallelizm(self):
convertapi.max_parallel_uploads = 1
result = convertapi.convert('pdf', { 'File': 'examples/files/test.docx' })
assert result.save_files(tempfile.gettempdir())
def test_convert_file_url(self):
result = convertapi.convert('pdf', { 'File': 'https://cdn.convertapi.com/cara/testfiles/document.docx?test=1' })
assert result.conversion_cost > 0
def test_convert_url(self):
result = convertapi.convert('pdf', { 'Url': 'http://convertapi.com' })
assert result.conversion_cost > 0
def test_convert_url_with_timeout_and_format(self):
result = convertapi.convert('pdf', { 'Url': 'https://www.w3.org/TR/PNG/iso_8859-1.txt' }, 'web', 100)
assert result.conversion_cost > 0
def test_upload_io(self):
bytes_io = io.BytesIO(b'test')
upload_io = convertapi.UploadIO(bytes_io, 'test.txt')
result = convertapi.convert('pdf', { 'File': upload_io })
assert result.conversion_cost > 0
def test_download_io(self):
result = convertapi.convert('pdf', { 'Url': 'https://www.w3.org/TR/PNG/iso_8859-1.txt' })
assert len(result.file.io.getvalue()) > 0
def test_zip_files(self):
files = ['examples/files/test.docx', 'examples/files/test.docx']
result = convertapi.convert('zip', { 'Files': files })
assert result.conversion_cost > 0
def test_chained_conversion(self):
result = convertapi.convert('pdf', { 'File': 'examples/files/test.docx' })
zip_result = convertapi.convert('zip', { 'Files': result.files })
eq_('test.zip', zip_result.file.filename)
def test_compare_files(self):
file = 'examples/files/test.docx'
result = convertapi.convert('compare', { 'File': file, 'CompareFile': file })
assert result.conversion_cost > 0
@raises(convertapi.ApiError)
def test_api_error(self):
convertapi.api_credentials = 'TEST'
convertapi.convert('pdf', { 'Url': 'https://www.w3.org/TR/PNG/iso_8859-1.txt' })
def test_user_info(self):
user_info = convertapi.user()
assert user_info['Active']