Skip to content

Commit 2e95e95

Browse files
committed
fix unit tests
1 parent 88313e4 commit 2e95e95

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

cxone_api/util.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ def json_on_ok(response : Response, specific_responses : list = None):
1111
class CloneUrlParser:
1212

1313
__parsers = {
14-
"bitbucket" : re.compile("^(?P<scheme>.+)://((?P<cred>.+)@)?.+/(scm/)?(?P<org>.+)/(?P<repo>.+)(\\.git)?$"),
15-
"azure" : re.compile("^(?P<scheme>.+)://((?P<cred>.+)@)?.+/(?P<org>.+)/(?P<project>.+)/_git/(?P<repo>.+)(\\.git)?$")
14+
"bitbucket" : re.compile("^(?P<scheme>.+)://((?P<cred>.+)@)?.+/(scm/)?(?P<org>.+)/(?P<repo>.+?)(\\.git)?$"),
15+
"azure" : re.compile("^(?P<scheme>.+)://((?P<cred>.+)@)?.+/(?P<org>.+)/(?P<project>.+)/_git/(?P<repo>.+?)(\\.git)?$")
1616
}
1717

18-
__default = re.compile("^.*[/:]{1}(?P<org>.+)/(?P<repo>.+)(\\.git)?$")
18+
__default = re.compile("^.*[/:]{1}(?P<org>.+)/(?P<repo>.+?)(\\.git)?$")
1919

2020
def __init__(self, repo_type, clone_url):
2121
matcher = CloneUrlParser.__parsers[repo_type] if repo_type in CloneUrlParser.__parsers.keys() else CloneUrlParser.__default

tests/cloneurl_parses_test.py

+21-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ def test_http_with_port(self):
1212
and parse.org == "the_org"
1313
and parse.repo == "the_repo")
1414

15+
def test_http_with_port_no_git(self):
16+
parse = CloneUrlParser("unknown", "http://the_host:7990/scm/the_org/the_repo")
17+
self.assertTrue(parse.scheme is None
18+
and parse.creds is None
19+
and parse.org == "the_org"
20+
and parse.repo == "the_repo")
21+
1522
class TestCloneUrlBitBucket(unittest.TestCase):
1623

1724
def test_canary(self):
@@ -24,6 +31,13 @@ def test_http_with_port(self):
2431
and parse.org == "the_org"
2532
and parse.repo == "the_repo")
2633

34+
def test_http_with_port_no_git(self):
35+
parse = CloneUrlParser("bitbucket", "http://the_host:7990/scm/the_org/the_repo")
36+
self.assertTrue(parse.scheme == "http"
37+
and parse.creds is None
38+
and parse.org == "the_org"
39+
and parse.repo == "the_repo")
40+
2741
def test_https_with_port(self):
2842
parse = CloneUrlParser("bitbucket", "https://the_host:7990/scm/the_org/the_repo.git")
2943
self.assertTrue(parse.scheme == "https"
@@ -45,13 +59,6 @@ def test_https_url_rewirte(self):
4559
and parse.org == "the_org"
4660
and parse.repo == "the_repo")
4761

48-
def test_https_malformed(self):
49-
parse = CloneUrlParser("bitbucket", "https://the_host/some/other/endpoint/scm/the_org/the_repo")
50-
self.assertTrue(parse.scheme is None
51-
and parse.creds is None
52-
and parse.org is None
53-
and parse.repo is None)
54-
5562
def test_ssh_with_port(self):
5663
parse = CloneUrlParser("bitbucket", "ssh://the_user@the_host:7999/the_org/the_repo.git")
5764
self.assertTrue(parse.scheme == "ssh"
@@ -72,6 +79,13 @@ def test_http_with_port(self):
7279
and parse.org == "the_org"
7380
and parse.repo == "the_repo")
7481

82+
def test_http_with_port_add_git(self):
83+
parse = CloneUrlParser("azure", "http://the_server:8080/tfs/the_org/the_project/_git/the_repo.git")
84+
self.assertTrue(parse.scheme == "http"
85+
and parse.creds is None
86+
and parse.org == "the_org"
87+
and parse.repo == "the_repo")
88+
7589
def test_https_with_port(self):
7690
parse = CloneUrlParser("azure", "https://someone@the_server:8080/tfs/the_org/the_project/_git/the_repo")
7791
self.assertTrue(parse.scheme == "https"

0 commit comments

Comments
 (0)