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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
#!/usr/bin/python3
# Copyright (C) 2018 Jelmer Vernooij <jelmer@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
from unittest import TestCase
from upstream_ontologist.vcs import (
plausible_url,
fixup_rcp_style_git_repo_url,
is_gitlab_site,
canonical_git_repo_url,
find_public_repo_url,
guess_repo_from_url,
fixup_broken_git_details,
browse_url_from_repo_url,
)
class PlausibleUrlTests(TestCase):
def test_url(self):
self.assertFalse(plausible_url("the"))
self.assertFalse(plausible_url("1"))
self.assertTrue(plausible_url("git@foo:blah"))
self.assertTrue(plausible_url("git+ssh://git@foo/blah"))
self.assertTrue(plausible_url("https://foo/blah"))
class TestIsGitLabSite(TestCase):
def test_not_gitlab(self):
self.assertFalse(is_gitlab_site("foo.example.com"))
self.assertFalse(is_gitlab_site("github.com"))
def test_gitlab(self):
self.assertTrue(is_gitlab_site("gitlab.somehost.com"))
self.assertTrue(is_gitlab_site("salsa.debian.org"))
class CanonicalizeVcsUrlTests(TestCase):
def test_github(self):
self.assertEqual(
"https://github.com/jelmer/example.git",
canonical_git_repo_url("https://github.com/jelmer/example"),
)
def test_salsa(self):
self.assertEqual(
"https://salsa.debian.org/jelmer/example.git",
canonical_git_repo_url("https://salsa.debian.org/jelmer/example"),
)
self.assertEqual(
"https://salsa.debian.org/jelmer/example.git",
canonical_git_repo_url("https://salsa.debian.org/jelmer/example.git"),
)
class FindPublicVcsUrlTests(TestCase):
def test_github(self):
self.assertEqual(
"https://github.com/jelmer/example",
find_public_repo_url("ssh://git@github.com/jelmer/example"),
)
self.assertEqual(
"https://github.com/jelmer/example",
find_public_repo_url("https://github.com/jelmer/example"),
)
self.assertEqual(
"https://github.com/jelmer/example",
find_public_repo_url("git@github.com:jelmer/example"),
)
def test_salsa(self):
self.assertEqual(
"https://salsa.debian.org/jelmer/example",
find_public_repo_url("ssh://salsa.debian.org/jelmer/example"),
)
self.assertEqual(
"https://salsa.debian.org/jelmer/example",
find_public_repo_url("https://salsa.debian.org/jelmer/example"),
)
class FixupRcpStyleUrlTests(TestCase):
def test_fixup(self):
try:
import breezy # noqa: F401
except ModuleNotFoundError:
self.skipTest("breezy is not available")
self.assertEqual(
"ssh://github.com/jelmer/example",
fixup_rcp_style_git_repo_url("github.com:jelmer/example"),
)
self.assertEqual(
"ssh://git@github.com/jelmer/example",
fixup_rcp_style_git_repo_url("git@github.com:jelmer/example"),
)
def test_leave(self):
try:
import breezy # noqa: F401
except ModuleNotFoundError:
self.skipTest("breezy is not available")
self.assertEqual(
"https://salsa.debian.org/jelmer/example",
fixup_rcp_style_git_repo_url("https://salsa.debian.org/jelmer/example"),
)
self.assertEqual(
"ssh://git@salsa.debian.org/jelmer/example",
fixup_rcp_style_git_repo_url("ssh://git@salsa.debian.org/jelmer/example"),
)
class GuessRepoFromUrlTests(TestCase):
def test_travis_ci_org(self):
self.assertEqual(
'https://github.com/jelmer/dulwich',
guess_repo_from_url(
'https://travis-ci.org/jelmer/dulwich'))
def test_coveralls(self):
self.assertEqual(
'https://github.com/jelmer/dulwich',
guess_repo_from_url(
'https://coveralls.io/r/jelmer/dulwich'))
def test_gitlab(self):
self.assertEqual(
'https://gitlab.com/jelmer/dulwich',
guess_repo_from_url(
'https://gitlab.com/jelmer/dulwich'))
self.assertEqual(
'https://gitlab.com/jelmer/dulwich',
guess_repo_from_url(
'https://gitlab.com/jelmer/dulwich/tags'))
class FixupBrokenGitDetailsTests(TestCase):
def test_github(self):
self.assertEqual(
('https://github.com/jelmer/dulwich', None, None),
fixup_broken_git_details('git://github.com/jelmer/dulwich', None, None))
class BrowseUrlFromRepoUrl(TestCase):
def test_github(self):
self.assertEqual(
"https://github.com/jelmer/dulwich",
browse_url_from_repo_url("https://github.com/jelmer/dulwich"))
self.assertEqual(
"https://github.com/jelmer/dulwich",
browse_url_from_repo_url("https://github.com/jelmer/dulwich.git"))
self.assertEqual(
"https://github.com/jelmer/dulwich/tree/foo",
browse_url_from_repo_url(
"https://github.com/jelmer/dulwich.git", branch="foo"))
self.assertEqual(
"https://github.com/jelmer/dulwich/tree/HEAD/foo",
browse_url_from_repo_url(
"https://github.com/jelmer/dulwich.git", subpath="foo"))
|