File: test_git_browse_ci.py

package info (click to toggle)
git-extras 7.4.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 2,120 kB
  • sloc: sh: 4,312; python: 994; makefile: 146
file content (166 lines) | stat: -rw-r--r-- 7,728 bytes parent folder | download
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
from testpath import MockCommand, modified_env

UNKNOWN_SITE_ORIGIN = "https://unknown-site.com/tj/git-extras.git"


def get_ci_uri_by_domain(mode):
    if mode == "github":
        return "https://github.com/tj/git-extras/actions"
    if mode == "gitlab":
        return "https://gitlab.com/tj/git-extras/-/pipelines"
    if mode == "bitbucket":
        return "https://bitbucket.org/tj/git-extras/addon/pipelines/home"


class TestGitBrowse:
    def test_browse_github_ci_on_mac(self, temp_repo):
        with modified_env({"OSTYPE": "darwin"}), MockCommand("open") as openCommand:
            temp_repo.invoke_extras_command("browse-ci", "origin")
            expected_url = get_ci_uri_by_domain("github")
            openCommand.assert_called([expected_url])

    def test_browse_gitlab_ci_on_mac(self, temp_repo):
        temp_repo.change_origin_to_gitlab()
        with modified_env({"OSTYPE": "darwin"}), MockCommand("open") as openCommand:
            temp_repo.invoke_extras_command("browse-ci", "origin")
            expected_url = get_ci_uri_by_domain("gitlab")
            openCommand.assert_called([expected_url])

    def test_browse_bitbucket_ci_on_mac(self, temp_repo):
        temp_repo.change_origin_to_bitbucket()
        with modified_env({"OSTYPE": "darwin"}), MockCommand("open") as openCommand:
            temp_repo.invoke_extras_command("browse-ci", "origin")
            expected_url = get_ci_uri_by_domain("bitbucket")
            openCommand.assert_called([expected_url])

    def test_browse_github_ci_on_git_bash_on_window(self, temp_repo):
        temp_repo.change_origin_to_github()
        with modified_env({"OSTYPE": "msys"}), MockCommand("start") as openCommand:
            temp_repo.invoke_extras_command("browse-ci", "origin")
            expected_url = get_ci_uri_by_domain("github")
            openCommand.assert_called([expected_url])

    def test_browse_gitlab_ci_on_git_bash_on_window(self, temp_repo):
        temp_repo.change_origin_to_gitlab()
        with modified_env({"OSTYPE": "msys"}), MockCommand("start") as openCommand:
            temp_repo.invoke_extras_command("browse-ci", "origin")
            expected_url = get_ci_uri_by_domain("gitlab")
            openCommand.assert_called([expected_url])

    def test_browse_bitbucket_ci_on_git_bash_on_window(self, temp_repo):
        temp_repo.change_origin_to_bitbucket()
        with modified_env({"OSTYPE": "msys"}), MockCommand("start") as openCommand:
            temp_repo.invoke_extras_command("browse-ci", "origin")
            expected_url = get_ci_uri_by_domain("bitbucket")
            openCommand.assert_called([expected_url])

    def test_browse_github_ci_on_WSL_with_microsoft_key(self, temp_repo):
        temp_repo.change_origin_to_github()
        with (
            modified_env({"OSTYPE": "linux"}),
            MockCommand.fixed_output("uname", "microsoft"),
            MockCommand.fixed_output("command", "/powershell.exe"),
            MockCommand("powershell.exe") as openCommand,
        ):
            temp_repo.invoke_extras_command("browse-ci", "origin")
            expected_url = get_ci_uri_by_domain("github")
            openCommand.assert_called(["-NoProfile", "start", expected_url])

    def test_browse_gitlab_ci_on_WSL_with_microsoft_key(self, temp_repo):
        temp_repo.change_origin_to_gitlab()
        with (
            modified_env({"OSTYPE": "linux"}),
            MockCommand.fixed_output("uname", "microsoft"),
            MockCommand.fixed_output("command", "/powershell.exe"),
            MockCommand("powershell.exe") as openCommand,
        ):
            temp_repo.invoke_extras_command("browse-ci", "origin")
            expected_url = get_ci_uri_by_domain("gitlab")
            openCommand.assert_called(["-NoProfile", "start", expected_url])

    def test_browse_bitbucket_ci_on_WSL_with_microsoft_key(self, temp_repo):
        temp_repo.change_origin_to_bitbucket()
        with (
            modified_env({"OSTYPE": "linux"}),
            MockCommand.fixed_output("uname", "microsoft"),
            MockCommand.fixed_output("command", "/powershell.exe"),
            MockCommand("powershell.exe") as openCommand,
        ):
            temp_repo.invoke_extras_command("browse-ci", "origin")
            expected_url = get_ci_uri_by_domain("bitbucket")
            openCommand.assert_called(["-NoProfile", "start", expected_url])

    def test_browse_github_ci_on_WSL_without_microsoft_key(self, temp_repo):
        temp_repo.change_origin_to_github()
        with (
            modified_env({"OSTYPE": "linux"}),
            MockCommand.fixed_output("uname", "no-micro-soft"),
            MockCommand.fixed_output("command", "/powershell.exe"),
            MockCommand("xdg-open") as openCommand,
        ):
            temp_repo.invoke_extras_command("browse-ci", "origin")
            expected_url = get_ci_uri_by_domain("github")
            openCommand.assert_called([expected_url])

    def test_browse_gitlab_ci_on_WSL_without_microsoft_key(self, temp_repo):
        temp_repo.change_origin_to_gitlab()
        with (
            modified_env({"OSTYPE": "linux"}),
            MockCommand.fixed_output("uname", "no-micro-soft"),
            MockCommand.fixed_output("command", "/powershell.exe"),
            MockCommand("xdg-open") as openCommand,
        ):
            temp_repo.invoke_extras_command("browse-ci", "origin")
            expected_url = get_ci_uri_by_domain("gitlab")
            openCommand.assert_called([expected_url])

    def test_browse_bitbucket_ci_on_WSL_without_microsoft_key(self, temp_repo):
        temp_repo.change_origin_to_bitbucket()
        with (
            modified_env({"OSTYPE": "linux"}),
            MockCommand.fixed_output("uname", "no-micro-soft"),
            MockCommand.fixed_output("command", "/powershell.exe"),
            MockCommand("xdg-open") as openCommand,
        ):
            temp_repo.invoke_extras_command("browse-ci", "origin")
            expected_url = get_ci_uri_by_domain("bitbucket")
            openCommand.assert_called([expected_url])

    def test_browse_github_ci_not_mac_or_msys_or_linux(self, temp_repo):
        temp_repo.change_origin_to_github()
        with (
            modified_env({"OSTYPE": "unique-system"}),
            MockCommand("xdg-open") as openCommand,
        ):
            temp_repo.invoke_extras_command("browse-ci", "origin")
            expected_url = get_ci_uri_by_domain("github")
            openCommand.assert_called([expected_url])

    def test_browse_gitlab_ci_not_mac_or_msys_or_linux(self, temp_repo):
        temp_repo.change_origin_to_gitlab()
        with (
            modified_env({"OSTYPE": "unique-system"}),
            MockCommand("xdg-open") as openCommand,
        ):
            temp_repo.invoke_extras_command("browse-ci", "origin")
            expected_url = get_ci_uri_by_domain("gitlab")
            openCommand.assert_called([expected_url])

    def test_browse_bitbucket_ci_not_mac_or_msys_or_linux(self, temp_repo):
        temp_repo.change_origin_to_bitbucket()
        with (
            modified_env({"OSTYPE": "unique-system"}),
            MockCommand("xdg-open") as openCommand,
        ):
            temp_repo.invoke_extras_command("browse-ci", "origin")
            expected_url = get_ci_uri_by_domain("bitbucket")
            openCommand.assert_called([expected_url])

    def test_browse_unknown_site_file(self, temp_repo):
        temp_repo.change_origin(UNKNOWN_SITE_ORIGIN)
        with (
            modified_env({"OSTYPE": "unique-system"}),
            MockCommand("xdg-open") as openCommand,
        ):
            temp_repo.invoke_extras_command("browse-ci", "origin")
            openCommand.assert_called([""])