From f818d8a81c3cf1060c69868b9a1374cd232dbb5d Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Thu, 11 Sep 2014 07:05:59 +0200 Subject: Make sure paths are relative since posixpath.join only picks the absolute one otherwise --- industriart/artifactory.py | 12 +++++++++--- tests/test_artifactory.py | 11 ++++++++++- 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]) -- cgit v1.2.3