Anton Shestakov <av6@dwimlabs.net>, Sun, 19 Jun 2016 15:52:04 +0800
incoming: parse_project_url() function to extract domain, user and name, tests
--- a/incoming.py Sun Jun 19 14:41:11 2016 +0800
+++ b/incoming.py Sun Jun 19 15:52:04 2016 +0800
return datetime.strptime(value, '%Y-%m-%dT%H:%M:%S+00:00')
+def parse_project_url(url):
+ domain = parsed.hostname
+ parts = [part for part in parsed.path.split('/') if part]
+ name = '/'.join(parts[1:])
+ return domain, user, name
result.append((cls, line))
- domain = parsed.hostname
- parts = [part for part in parsed.path.split('/') if part]
- user, name = parts[-2:]
+ domain, user, name = parse_project_url(url)
with database.transaction():
project, created = Project.create_or_get(
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_incoming.py Sun Jun 19 15:52:04 2016 +0800
+from incoming import parse_project_url
+def test_parse_project_url():
+ result = parse_project_url('https://example.com/alice/hello-world')
+ assert result == ('example.com', 'alice', 'hello-world')
+ result = parse_project_url('~alice/hello-world')
+ assert result == ('self', '~alice', 'hello-world')
+ result = parse_project_url('https://code.example.com/hello-world')
+ assert result == ('code.example.com', None, 'hello-world')
+ result = parse_project_url('https://example.com/scm/projects/hello-world')
+ assert result == ('example.com', 'scm', 'projects/hello-world')
+ result = parse_project_url('https://example.com///hello-world//')
+ assert result == ('example.com', None, 'hello-world')