parent
fc14ed2be1
commit
f3e7d44276
3 changed files with 48 additions and 22 deletions
26
tests/test_multi_client_it.py
Normal file
26
tests/test_multi_client_it.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
import unittest
|
||||
|
||||
from tests.test_client_it import ClientTestCase
|
||||
from webdav3.client import Client
|
||||
|
||||
|
||||
class MultiClientTestCase(ClientTestCase):
|
||||
options2 = {
|
||||
'webdav_hostname': 'https://wrong.url.ru',
|
||||
'webdav_login': 'webdavclient.test2',
|
||||
'webdav_password': 'Qwerty123!',
|
||||
'webdav_override_methods': {
|
||||
'check': 'FAKE',
|
||||
'download': 'FAKE',
|
||||
'upload': 'FAKE',
|
||||
'clean': 'FAKE',
|
||||
}
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
super(ClientTestCase, self).setUp()
|
||||
self.second_client = Client(self.options2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -89,11 +89,8 @@ class Client(object):
|
|||
# controls whether to verify the server's TLS certificate or not
|
||||
verify = True
|
||||
|
||||
# Sets the session for subsequent requests
|
||||
session = requests.Session()
|
||||
|
||||
# HTTP headers for different actions
|
||||
http_header = {
|
||||
default_http_header = {
|
||||
'list': ["Accept: */*", "Depth: 1"],
|
||||
'free': ["Accept: */*", "Depth: 0", "Content-Type: text/xml"],
|
||||
'copy': ["Accept: */*"],
|
||||
|
@ -107,7 +104,7 @@ class Client(object):
|
|||
}
|
||||
|
||||
# mapping of actions to WebDAV methods
|
||||
requests = {
|
||||
default_requests = {
|
||||
'options': 'OPTIONS',
|
||||
'download': "GET",
|
||||
'upload': "PUT",
|
||||
|
@ -150,6 +147,9 @@ class Client(object):
|
|||
`webdav_verbose`: (optional) set verbose mode on.off. By default verbose mode is off.
|
||||
|
||||
"""
|
||||
self.session = requests.Session()
|
||||
self.http_header = Client.default_http_header.copy()
|
||||
self.requests = Client.default_requests.copy()
|
||||
webdav_options = get_options(option_type=WebDAVSettings, from_options=options)
|
||||
|
||||
self.webdav = WebDAVSettings(webdav_options)
|
||||
|
@ -164,11 +164,11 @@ class Client(object):
|
|||
the specified action.
|
||||
:return: the dictionary of headers for specified action.
|
||||
"""
|
||||
if action in Client.http_header:
|
||||
if action in self.http_header:
|
||||
try:
|
||||
headers = Client.http_header[action].copy()
|
||||
headers = self.http_header[action].copy()
|
||||
except AttributeError:
|
||||
headers = Client.http_header[action][:]
|
||||
headers = self.http_header[action][:]
|
||||
else:
|
||||
headers = list()
|
||||
|
||||
|
@ -211,7 +211,7 @@ class Client(object):
|
|||
if self.session.auth:
|
||||
self.session.request(method="GET", url=self.webdav.hostname, verify=self.verify) # (Re)Authenticates against the proxy
|
||||
response = self.session.request(
|
||||
method=Client.requests[action],
|
||||
method=self.requests[action],
|
||||
url=self.get_url(path),
|
||||
auth=(self.webdav.login, self.webdav.password),
|
||||
headers=self.get_headers(action, headers_ext),
|
||||
|
|
|
@ -27,20 +27,20 @@ class WebDAVSettings(ConnectionSettings):
|
|||
keys = {'hostname', 'login', 'password', 'token', 'root', 'cert_path', 'key_path', 'recv_speed', 'send_speed',
|
||||
'verbose', 'disable_check', 'override_methods'}
|
||||
|
||||
hostname = None
|
||||
login = None
|
||||
password = None
|
||||
token = None
|
||||
root = None
|
||||
cert_path = None
|
||||
key_path = None
|
||||
recv_speed = None
|
||||
send_speed = None
|
||||
verbose = None
|
||||
disable_check = False
|
||||
override_methods = {}
|
||||
|
||||
def __init__(self, options):
|
||||
self.hostname = None
|
||||
self.login = None
|
||||
self.password = None
|
||||
self.token = None
|
||||
self.root = None
|
||||
self.cert_path = None
|
||||
self.key_path = None
|
||||
self.recv_speed = None
|
||||
self.send_speed = None
|
||||
self.verbose = None
|
||||
self.disable_check = False
|
||||
self.override_methods = {}
|
||||
|
||||
self.options = dict()
|
||||
|
||||
for key in self.keys:
|
||||
|
|
Loading…
Add table
Reference in a new issue