Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions owncloud/owncloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,11 @@ def __init__(self, url, **kwargs):

:param url: URL of the target ownCloud instance
:param verify_certs: True (default) to verify SSL certificates, False otherwise
:param dav_endpoint_version: None (default) to force using a specific endpoint version
:param dav_endpoint_version: 1 (default) to force using a specific endpoint version
instead of relying on capabilities
:param debug: set to True to print debugging messages to stdout, defaults to False
:param timeout: The number of seconds that the client will wait for to respond,
or None to not set any timeout.
"""
if not url.endswith('/'):
url += '/'
Expand All @@ -340,7 +342,8 @@ def __init__(self, url, **kwargs):
self._session = None
self._debug = kwargs.get('debug', False)
self._verify_certs = kwargs.get('verify_certs', True)
self._dav_endpoint_version = kwargs.get('dav_endpoint_version', True)
self._dav_endpoint_version = kwargs.get('dav_endpoint_version', 1)
self._timeout = kwargs.get('timeout', None)

self._capabilities = None
self._version = None
Expand Down Expand Up @@ -1784,7 +1787,8 @@ def _make_ocs_request(self, method, service, action, **kwargs):
print('OCS request: %s %s %s' % (method, self.url + path,
attributes))

res = self._session.request(method, self.url + path, **attributes)
res = self._session.request(
method, self.url + path, timeout=self._timeout, **attributes)
return res

def _make_dav_request(self, method, path, **kwargs):
Expand All @@ -1806,6 +1810,7 @@ def _make_dav_request(self, method, path, **kwargs):
res = self._session.request(
method,
self._webdav_url + parse.quote(self._encode_string(path)),
timeout=self._timeout,
**kwargs
)
if self._debug:
Expand Down
31 changes: 31 additions & 0 deletions owncloud/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import shutil
import owncloud
import datetime
import mock
import requests
import time
import tempfile
import random
Expand Down Expand Up @@ -1267,6 +1269,35 @@ def tearDown(self):
self.client.logout()


class TestTimeout(unittest.TestCase):
def setUp(self):
self.client = owncloud.Client(Config['owncloud_url'], timeout=15)

@mock.patch.object(requests.Session, 'request', autospec=True,
return_value=requests.Response())
def test_timeout_is_set_on_ocs_requests(self, mock_req):
mock_req.return_value.status_code = 404
try:
self.client.login(Config['owncloud_login'], Config['owncloud_password'])
except owncloud.owncloud.HTTPResponseError:
pass
mock_req.assert_called_with(
mock.ANY,
mock.ANY,
timeout=15,
)
@mock.patch.object(requests.Session, 'request', autospec=True,
return_value=requests.Response())
def test_timeout_is_set_on_dav_requests(self, mock_req):
mock_req.status_code = 404
self.client.list('/')
mock_req.assert_called_with(
mock.ANY,
mock.ANY,
timeout=15,
)


class TestOCSRequest(unittest.TestCase):

def setUp(self):
Expand Down