Allow config option for HTTP method for uploads (Artifactory) (#4553)

* allow for a config option for http method

* add tests

* fix tests with method

* Update dvc/tree/http.py

Co-authored-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Robert F. Dickerson
2020-09-10 05:11:41 +03:00
committed by GitHub
co-authored by Ruslan Kuprieiev
parent 54a48e3256
commit 7fa90e425d
3 changed files with 25 additions and 1 deletions
+1
View File
@@ -119,6 +119,7 @@ HTTP_COMMON = {
"password": str,
"ask_password": Bool,
"ssl_verify": Bool,
"method": str,
}
WEBDAV_COMMON = {
"user": str,
+2 -1
View File
@@ -54,6 +54,7 @@ class HTTPTree(BaseTree): # pylint:disable=abstract-method
self.ask_password = config.get("ask_password", False)
self.headers = {}
self.ssl_verify = config.get("ssl_verify", True)
self.method = config.get("method", "POST")
def _auth_method(self, path_info=None):
from requests.auth import HTTPBasicAuth, HTTPDigestAuth
@@ -194,7 +195,7 @@ class HTTPTree(BaseTree): # pylint:disable=abstract-method
break
yield chunk
response = self.request("POST", to_info.url, data=chunks())
response = self.request(self.method, to_info.url, data=chunks())
if response.status_code not in (200, 201):
raise HTTPError(response.status_code, response.reason)
+22
View File
@@ -103,3 +103,25 @@ def test_ssl_verify_disable(dvc):
tree = HTTPTree(dvc, config)
assert tree._session.verify is False
def test_http_method(dvc):
from requests.auth import HTTPBasicAuth
user = "username"
password = "password"
auth = HTTPBasicAuth(user, password)
config = {
"url": "http://example.com/",
"path_info": "file.html",
"auth": "basic",
"user": user,
"password": password,
"method": "PUT",
}
tree = HTTPTree(dvc, config)
assert tree._auth_method() == auth
assert tree.method == "PUT"
assert isinstance(tree._auth_method(), HTTPBasicAuth)