Skip to content

Commit 45c2deb

Browse files
author
Laurynas Butkus
committed
Adjust timeout param naming
1 parent 3760c0b commit 45c2deb

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

convertapi/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .task import Task
22

3-
def convert(to_format, params, from_format = None, conversion_timeout = None):
4-
task = Task(from_format, to_format, params, conversion_timeout = conversion_timeout)
3+
def convert(to_format, params, from_format = None, timeout = None):
4+
task = Task(from_format, to_format, params, timeout = timeout)
55
return task.run()

convertapi/task.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
DEFAULT_URL_FORMAT = 'url'
77

88
class Task:
9-
def __init__(self, from_format, to_format, params, conversion_timeout = None):
9+
def __init__(self, from_format, to_format, params, timeout = None):
1010
self.from_format = from_format
1111
self.to_format = to_format
1212
self.params = params
13-
self.conversion_timeout = conversion_timeout or convertapi.conversion_timeout
13+
self.timeout = timeout or convertapi.conversion_timeout
1414

1515
self.default_params = {
16-
'Timeout': self.conversion_timeout,
16+
'Timeout': self.timeout,
1717
'StoreFile': True,
1818
}
1919

2020
def run(self):
2121
params = self.__normalize_params()
2222
from_format = self.from_format or self.__detect_format()
23-
timeout = self.conversion_timeout + convertapi.conversion_timeout_delta
23+
timeout = self.timeout + convertapi.conversion_timeout_delta
2424
path = "convert/%s/to/%s" % (from_format, self.to_format)
2525

2626
response = convertapi.client.post(path, params, timeout = timeout)

tests/test_convertapi.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def test_convert_url(self):
2626
result = convertapi.convert('pdf', { 'Url': 'http://convertapi.com' })
2727
assert result.conversion_cost > 0
2828

29+
def test_convert_url_with_timeout_and_format(self):
30+
result = convertapi.convert('pdf', { 'Url': 'https://www.w3.org/TR/PNG/iso_8859-1.txt' }, 'web', 100)
31+
assert result.conversion_cost > 0
32+
2933
def test_upload_io(self):
3034
bytes_io = io.BytesIO(b'test')
3135
upload_io = convertapi.UploadIO(bytes_io, 'test.txt')
@@ -36,3 +40,8 @@ def test_zip_files(self):
3640
files = ['examples/files/test.docx', 'examples/files/test.docx']
3741
result = convertapi.convert('zip', { 'Files': files })
3842
assert result.conversion_cost > 0
43+
44+
def test_chained_conversion(self):
45+
result = convertapi.convert('pdf', { 'File': 'examples/files/test.docx' })
46+
zip_result = convertapi.convert('zip', { 'Files': result.files })
47+
eq_('test.zip', zip_result.file.filename)

0 commit comments

Comments
 (0)