aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2014-09-11 07:05:59 +0200
committerGuido Günther <agx@sigxcpu.org>2014-09-11 07:15:15 +0200
commitf818d8a81c3cf1060c69868b9a1374cd232dbb5d (patch)
treec82e8b7025db12f3cd524828d5205f6b7914f2c3
parentf1f18f7ea5ad0ab400155587b66be77da6e36046 (diff)
Make sure paths are relativeHEADmaster
since posixpath.join only picks the absolute one otherwise
-rw-r--r--industriart/artifactory.py12
-rw-r--r--tests/test_artifactory.py11
2 files changed, 19 insertions, 4 deletions
diff --git a/industriart/artifactory.py b/industriart/artifactory.py
index ca409ca..9ca3e87 100644
--- a/industriart/artifactory.py
+++ b/industriart/artifactory.py
@@ -51,6 +51,12 @@ class Artifactory(object):
self.password = password
self.base = base
+ def _strslash(self, path):
+ """
+ Strip leading '/' since posixpath.join will treat it as absolute otherwise
+ """
+ return path.lstrip('/')
+
def search_gavc(self, groupid=None, artifactid=None, version=None, classifier=None):
"""
Query the artifactory via Groupid, ArtifacId, Version and classifier
@@ -105,7 +111,7 @@ class Artifactory(object):
:arg str file: The path of the file
"""
url = posixpath.join(self.base, 'api', 'storage',
- repo, file)
+ repo, self._strslash(file))
return self.get(url)
def _copy_or_move(self, action, source, target):
@@ -123,8 +129,8 @@ class Artifactory(object):
url = posixpath.join(self.base,
'api', action,
- source[0], source[1])
- dst = posixpath.join(target[0], target[1])
+ source[0], self._strslash(source[1]))
+ dst = posixpath.join(target[0], self._strslash(target[1]))
log.debug("%s %s", action.capitalize(), url)
# Parameter order matters for artifactory
diff --git a/tests/test_artifactory.py b/tests/test_artifactory.py
index 3e28e90..07b07e4 100644
--- a/tests/test_artifactory.py
+++ b/tests/test_artifactory.py
@@ -30,7 +30,7 @@ class TestArtifactory(unittest.TestCase):
a = Artifactory('http://a.exmple.com')
with patch.object(Artifactory, '_request') as mocked_request:
mocked_request.side_effect = request_mock
- ret = a.copy(('unstable','foo'), ('release', 'bar'))
+ ret = a.copy(('unstable','/foo'), ('release', 'bar'))
self.assertEquals(ret[0], 'POST')
self.assertEquals(ret[1], 'http://a.exmple.com/api/copy/unstable/foo')
self.assertDictEqual(ret[2], {'to': 'release/bar'})
@@ -56,3 +56,12 @@ class TestArtifactory(unittest.TestCase):
self.assertEquals(ret[0], 'POST')
self.assertEquals(ret[1], 'http://a.exmple.com/api/move/unstable/foo')
self.assertDictEqual(ret[2], {'to': 'release/bar'})
+
+ def test_filecopy(self):
+ a = Artifactory('http://a.exmple.com')
+ with patch.object(Artifactory, '_request') as mocked_request:
+ mocked_request.side_effect = request_mock
+ ret = a.get_fileinfo('unstable', '/foo')
+ self.assertEquals(ret[0], 'GET')
+ self.assertEquals(ret[1], 'http://a.exmple.com/api/storage/unstable/foo')
+ self.assertIsNone(ret[2])