-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathparse.py
More file actions
123 lines (104 loc) · 2.96 KB
/
Copy pathparse.py
File metadata and controls
123 lines (104 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Imports
import unittest
from giturlparse import parse
# Test data
VALID_PARSE_URLS = (
# Valid SSH, HTTPS, GIT
('SSH', ('git@github.com:Org/Repo.git', {
'host': 'github.com',
'user': 'git',
'owner': 'Org',
'repo': 'Repo',
'protocol': 'ssh',
'github': True,
'bitbucket': False,
'assembla': False
})),
('HTTPS', ('https://github.com/Org/Repo.git', {
'host': 'github.com',
'user': 'git',
'owner': 'Org',
'repo': 'Repo',
'protocol': 'https',
'github': True,
'bitbucket': False,
'assembla': False
})),
('GIT', ('git://github.com/Org/Repo.git', {
'host': 'github.com',
'user': 'git',
'owner': 'Org',
'repo': 'Repo',
'protocol': 'git',
'github': True,
'bitbucket': False,
'assembla': False
})),
# BitBucket
('SSH', ('git@bitbucket.org:Org/Repo.git', {
'host': 'bitbucket.org',
'user': 'git',
'owner': 'Org',
'repo': 'Repo',
'protocol': 'ssh',
'platform': 'bitbucket'
})),
# Gitlab
('SSH', ('git@host.org:9999/Org/Repo.git', {
'host': 'host.org',
'user': 'git',
'owner': 'Org',
'repo': 'Repo',
'protocol': 'ssh',
'platform': 'gitlab'
})),
('SSH', ('git@host.org:Org/Repo.git', {
'host': 'host.org',
'user': 'git',
'owner': 'Org',
'repo': 'Repo',
'protocol': 'ssh',
'platform': 'gitlab'
})),
('SSH', ('ssh://git@host.org:9999/Org/Repo.git', {
'host': 'host.org',
'user': 'git',
'owner': 'Org',
'repo': 'Repo',
'protocol': 'ssh',
'platform': 'gitlab'
})),
('HTTPS', ('https://host.org/Org/Repo.git', {
'host': 'host.org',
'user': 'git',
'owner': 'Org',
'repo': 'Repo',
'protocol': 'https',
'platform': 'gitlab'
})),
)
INVALID_PARSE_URLS = (
('SSH Bad Username', 'gitx@github.com:Org/Repo.git'),
('SSH No Repo', 'git@github.com:Org'),
('HTTPS No Repo', 'https://github.com/Org'),
('GIT No Repo', 'git://github.com/Org'),
)
# Here's our "unit tests".
class UrlParseTestCase(unittest.TestCase):
def _test_valid(self, url, results):
p = parse(url)
self.failUnless(p.valid, "%s is not a valid URL" % url)
for k,v in results.items():
attr_v = getattr(p, k)
self.assertEqual(attr_v, v, "[%s] Property '%s' should be '%s' but is '%s'" % (url, k, attr_v, v))
def testValidUrls(self):
for test_type, data in VALID_PARSE_URLS:
self._test_valid(*data)
def _test_invalid(self, url):
p = parse(url)
self.failIf(p.valid)
def testInvalidUrls(self):
for problem, url in INVALID_PARSE_URLS:
self._test_invalid(url)
# Test Suite
suite = unittest.TestLoader().loadTestsFromTestCase(UrlParseTestCase)