Repository: devopshq/artifactory

Issue:
repo is not updated when apply joinpath
Hi @allburov 
there is a problem that `repo` property is not updated when we use `joinpath`.
I tried to debug the issue by myself, but cannot really figure out how to refresh `ArtifactoryPath `when we apply `joinpath `method

here is test code to reproduce:
~~~python
from artifactory import ArtifactoryPath

path = ArtifactoryPath("http://repo.jfrog.org/artifactory")
repo_name = str(path.get_repositories()[0])

path = path.joinpath(repo_name)

print(path)
print(path.repo) # repo is empty

path = ArtifactoryPath(str(path))  # pass already existing path as new string
print(path)
print(path.repo)   # repo exists
~~~


Discussion:

Patch:
diff --git a/artifactory.py b/artifactory.py
index 0628f59..58001bf 100755
--- a/artifactory.py
+++ b/artifactory.py
@@ -407,6 +407,10 @@ class _ArtifactoryFlavour(pathlib._Flavour):
         drv2, root2, parts2 = super(_ArtifactoryFlavour, self).join_parsed_parts(
             drv, root, parts, drv2, root2, parts2
         )
+
+        if not root2 and len(parts2) > 1:
+            root2 = self.sep + parts2.pop(1) + self.sep
+
         # quick hack for https://github.com/devopshq/artifactory/issues/29
         # drive or repository must start with / , if not - add it
         if not drv2.endswith("/") and not root2.startswith("/"):


Test patch:
diff --git a/tests/unit/test_artifactory_path.py b/tests/unit/test_artifactory_path.py
index cb0f0ce..f157fce 100644
--- a/tests/unit/test_artifactory_path.py
+++ b/tests/unit/test_artifactory_path.py
@@ -667,6 +667,20 @@ class ArtifactoryPathTest(unittest.TestCase):
         b = P("http://b/artifactory/reponame/folder/path.xml")
         self.assertEqual(b.path_in_repo, "/folder/path.xml")
 
+    def test_joinpath_repo(self):
+        """
+        https://github.com/devopshq/artifactory/issues/239
+        """
+
+        P = self.cls
+        artis = ["", "artifactory", "artifactory/"]
+        reponames = ["reponame", "/reponame", "reponame/", "/reponame/"]
+
+        for arti in artis:
+            for reponame in reponames:
+                c = P("http://b/" + arti).joinpath(reponame)
+                self.assertEqual(c.root, "/reponame/")
+
 
 class ArtifactorySaaSPathTest(unittest.TestCase):