-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_submodule_to_project.py
More file actions
59 lines (48 loc) · 2.21 KB
/
test_submodule_to_project.py
File metadata and controls
59 lines (48 loc) · 2.21 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
from unittest import TestCase
from unittest.mock import MagicMock
from gitlab import Gitlab
from gitlab.v4.objects import ProjectManager
from gitlab_submodule import Submodule
from gitlab_submodule.submodule_to_project import host_url_to_domain
from gitlab_submodule.submodule_to_project import (
match_submodule_to_client_and_format_project_path)
def test_host_url_to_domain():
assert host_url_to_domain("https://myhost.com/") == "myhost.com"
class TestSubmoduleToProject(TestCase):
def mock_submodule(self, url: str) -> MagicMock:
submodule = MagicMock(Submodule)
submodule.url = url
return submodule
def test__submodule_url_to_path_with_namespace(self):
# Normal gitlab host
_, path_with_namespace = \
match_submodule_to_client_and_format_project_path(
self.mock_submodule('https://gitlab.com/namespace/repo.git'),
gls=Gitlab()
)
self.assertEqual(path_with_namespace, 'namespace/repo')
# Self-managed gitlab URL, wrong client
match = match_submodule_to_client_and_format_project_path(
self.mock_submodule('https://custom-gitlab/namespace/repo.git'),
gls=Gitlab())
self.assertEqual(match, None)
# Self-managed gitlab URL that includes the URL of the wrong client
match = \
match_submodule_to_client_and_format_project_path(
self.mock_submodule(
'https://custom-gitlab.com/namespace/repo.git'),
gls=Gitlab()
)
self.assertEqual(match, None)
# Self-managed gitlab URL with self_managed_gitlab_host
self_hosted_client = MagicMock(ProjectManager)
self_hosted_client.gitlab = MagicMock(Gitlab)
self_hosted_client.gitlab._base_url = "https://custom-gitlab.com"
client, path_with_namespace = \
match_submodule_to_client_and_format_project_path(
self.mock_submodule(
'https://custom-gitlab.com/namespace/repo.git'),
gls=[Gitlab(), self_hosted_client],
)
self.assertEqual(path_with_namespace, 'namespace/repo')
self.assertEqual(client, self_hosted_client)