From 5a19d4ddd0b58c7db5d336e424d084b4716b8ba5 Mon Sep 17 00:00:00 2001 From: vanpipy Date: Thu, 22 Feb 2024 01:51:22 +0800 Subject: [PATCH] refactor: simplify the case code * test_git_browse_ci.py * test_git_browse.py --- tests/test_git_browse.py | 290 ++++++++++++++++-------------------- tests/test_git_browse_ci.py | 223 +++++++++++---------------- 2 files changed, 216 insertions(+), 297 deletions(-) diff --git a/tests/test_git_browse.py b/tests/test_git_browse.py index b2e2d70fb..ff4b4db9c 100644 --- a/tests/test_git_browse.py +++ b/tests/test_git_browse.py @@ -1,231 +1,195 @@ import os, subprocess from testpath import MockCommand, modified_env -github_origin = "https://github.com/tj/git-extras" -gitlab_origin = "https://gitlab.com/tj/git-extras" -bitbucket_origin = "https://bitbucket.org/tj/git-extras" -unknown_site_origin = "https://unknown-site.com/tj/git-extras" +UNKNOWN_SITE_ORIGIN = "https://unknown-site.com/tj/git-extras.git" -def set_origin_url(git, url): - git.remote("set-url", "origin", url + ".git") - -def create_expected_filename(git, origin, mode, filename): +def get_file_uri(mode, filename, git): commit_hash = git.rev_parse("HEAD") - connector = "" if mode == "github": - connector = "/blob/" + return "https://github.com/tj/git-extras/blob/" + commit_hash + '/' + filename if mode == "gitlab": - connector = "/-/blob/" + return "https://gitlab.com/tj/git-extras/-/blob/" + commit_hash + '/' + filename if mode == "bitbucket": - connector = "/src/" - return origin + connector + commit_hash + filename + return "https://bitbucket.org/tj/git-extras/src/" + commit_hash + '/' + filename class TestGitBrowse: def test_browse_github_file_on_mac(self, temp_repo): git = temp_repo.get_repo_git() - git.remote("add", "origin", github_origin + ".git") - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "darwin" }): - with MockCommand("open") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:]) - expected_url = create_expected_filename(git, github_origin, "github", tmp_file) - openCommand.assert_called([expected_url]) + filename = temp_repo.get_filename(0) + with modified_env({ "OSTYPE": "darwin" }), MockCommand("open") as openCommand: + temp_repo.invoke_extras_command("browse", "origin", filename) + expected_url = get_file_uri("github", filename, git) + openCommand.assert_called([expected_url]) def test_browse_gitlab_file_on_mac(self, temp_repo): + temp_repo.change_origin_to_gitlab() git = temp_repo.get_repo_git() - set_origin_url(git, gitlab_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "darwin" }): - with MockCommand("open") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:]) - expected_url = create_expected_filename(git, gitlab_origin, "gitlab", tmp_file) - openCommand.assert_called([expected_url]) + filename = temp_repo.get_filename(0) + with modified_env({ "OSTYPE": "darwin" }), MockCommand("open") as openCommand: + temp_repo.invoke_extras_command("browse", "origin", filename) + expected_url = get_file_uri("gitlab", filename, git) + openCommand.assert_called([expected_url]) def test_browse_bitbucket_file_on_mac(self, temp_repo): + temp_repo.change_origin_to_bitbucket() git = temp_repo.get_repo_git() - set_origin_url(git, bitbucket_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "darwin" }): - with MockCommand("open") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:]) - expected_url = create_expected_filename(git, bitbucket_origin, "bitbucket", tmp_file) - openCommand.assert_called([expected_url]) + filename = temp_repo.get_filename(0) + with modified_env({ "OSTYPE": "darwin" }), MockCommand("open") as openCommand: + temp_repo.invoke_extras_command("browse", "origin", filename) + expected_url = get_file_uri("bitbucket", filename, git) + openCommand.assert_called([expected_url]) def test_browse_github_file_on_git_bash_on_window(self, temp_repo): + temp_repo.change_origin_to_github() git = temp_repo.get_repo_git() - set_origin_url(git, github_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "msys" }): - with MockCommand("start") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:]) - expected_url = create_expected_filename(git, github_origin, "github", tmp_file) - openCommand.assert_called([expected_url]) + filename = temp_repo.get_filename(0) + with modified_env({ "OSTYPE": "msys" }), MockCommand("start") as openCommand: + temp_repo.invoke_extras_command("browse", "origin", filename) + expected_url = get_file_uri("github", filename, git) + openCommand.assert_called([expected_url]) def test_browse_gitlab_file_on_git_bash_on_window(self, temp_repo): + temp_repo.change_origin_to_gitlab() git = temp_repo.get_repo_git() - set_origin_url(git, gitlab_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "msys" }): - with MockCommand("start") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:]) - expected_url = create_expected_filename(git, gitlab_origin, "gitlab", tmp_file) - openCommand.assert_called([expected_url]) + filename = temp_repo.get_filename(0) + with modified_env({ "OSTYPE": "msys" }), MockCommand("start") as openCommand: + temp_repo.invoke_extras_command("browse", "origin", filename) + expected_url = get_file_uri("gitlab", filename, git) + openCommand.assert_called([expected_url]) def test_browse_bitbucket_file_on_git_bash_on_window(self, temp_repo): + temp_repo.change_origin_to_bitbucket() git = temp_repo.get_repo_git() - set_origin_url(git, bitbucket_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "msys" }): - with MockCommand("start") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:]) - expected_url = create_expected_filename(git, bitbucket_origin, "bitbucket", tmp_file) - openCommand.assert_called([expected_url]) + filename = temp_repo.get_filename(0) + with modified_env({ "OSTYPE": "msys" }), MockCommand("start") as openCommand: + temp_repo.invoke_extras_command("browse", "origin", filename) + expected_url = get_file_uri("bitbucket", filename, git) + openCommand.assert_called([expected_url]) def test_browse_github_file_on_WSL_with_microsoft_key(self, temp_repo): + temp_repo.change_origin_to_github() git = temp_repo.get_repo_git() - set_origin_url(git, github_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "linux" }): - with MockCommand.fixed_output("uname", "microsoft"): - with MockCommand.fixed_output("command", "/powershell.exe"): - with MockCommand("powershell.exe") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:]) - expected_url = create_expected_filename(git, github_origin, "github", tmp_file) - openCommand.assert_called(["-NoProfile", "start", expected_url]) + filename = temp_repo.get_filename(0) + 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", "origin", filename) + expected_url = get_file_uri("github", filename, git) + openCommand.assert_called(["-NoProfile", "start", expected_url]) def test_browse_gitlab_file_on_WSL_with_microsoft_key(self, temp_repo): + temp_repo.change_origin_to_gitlab() git = temp_repo.get_repo_git() - set_origin_url(git, gitlab_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "linux" }): - with MockCommand.fixed_output("uname", "microsoft"): - with MockCommand.fixed_output("command", "/powershell.exe"): - with MockCommand("powershell.exe") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:]) - expected_url = create_expected_filename(git, gitlab_origin, "gitlab", tmp_file) - openCommand.assert_called(["-NoProfile", "start", expected_url]) + filename = temp_repo.get_filename(0) + 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", "origin", filename) + expected_url = get_file_uri("gitlab", filename, git) + openCommand.assert_called(["-NoProfile", "start", expected_url]) def test_browse_bitbucket_file_on_WSL_with_microsoft_key(self, temp_repo): + temp_repo.change_origin_to_bitbucket() git = temp_repo.get_repo_git() - set_origin_url(git, bitbucket_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "linux" }): - with MockCommand.fixed_output("uname", "microsoft"): - with MockCommand.fixed_output("command", "/powershell.exe"): - with MockCommand("powershell.exe") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:]) - expected_url = create_expected_filename(git, bitbucket_origin, "bitbucket", tmp_file) - openCommand.assert_called(["-NoProfile", "start", expected_url]) + filename = temp_repo.get_filename(0) + 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", "origin", filename) + expected_url = get_file_uri("bitbucket", filename, git) + openCommand.assert_called(["-NoProfile", "start", expected_url]) def test_browse_github_file_on_WSL_without_microsoft_key(self, temp_repo): + temp_repo.change_origin_to_github() git = temp_repo.get_repo_git() - set_origin_url(git, github_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "linux" }): - with MockCommand.fixed_output("uname", "no-micro-soft"): - with MockCommand.fixed_output("command", "/powershell.exe"): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:]) - expected_url = create_expected_filename(git, github_origin, "github", tmp_file) - openCommand.assert_called([expected_url]) + filename = temp_repo.get_filename(0) + 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", "origin", filename) + expected_url = get_file_uri("github", filename, git) + openCommand.assert_called([expected_url]) def test_browse_gitlab_file_on_WSL_without_microsoft_key(self, temp_repo): + temp_repo.change_origin_to_gitlab() git = temp_repo.get_repo_git() - set_origin_url(git, gitlab_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "linux" }): - with MockCommand.fixed_output("uname", "no-micro-soft"): - with MockCommand.fixed_output("command", "/powershell.exe"): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:]) - expected_url = create_expected_filename(git, gitlab_origin, "gitlab", tmp_file) - openCommand.assert_called([expected_url]) + filename = temp_repo.get_filename(0) + 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", "origin", filename) + expected_url = get_file_uri("gitlab", filename, git) + openCommand.assert_called([expected_url]) def test_browse_bitbucket_file_on_WSL_without_microsoft_key(self, temp_repo): + temp_repo.change_origin_to_bitbucket() git = temp_repo.get_repo_git() - set_origin_url(git, bitbucket_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "linux" }): - with MockCommand.fixed_output("uname", "no-micro-soft"): - with MockCommand.fixed_output("command", "/powershell.exe"): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:]) - expected_url = create_expected_filename(git, bitbucket_origin, "bitbucket", tmp_file) - openCommand.assert_called([expected_url]) + filename = temp_repo.get_filename(0) + 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", "origin", filename) + expected_url = get_file_uri("bitbucket", filename, git) + openCommand.assert_called([expected_url]) def test_browse_github_file_not_mac_or_msys_or_linux(self, temp_repo): + temp_repo.change_origin_to_github() git = temp_repo.get_repo_git() - set_origin_url(git, github_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "unique-system" }): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:]) - expected_url = create_expected_filename(git, github_origin, "github", tmp_file) - openCommand.assert_called([expected_url]) + filename = temp_repo.get_filename(0) + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: + temp_repo.invoke_extras_command("browse", "origin", filename) + expected_url = get_file_uri("github", filename, git) + openCommand.assert_called([expected_url]) def test_browse_gitlab_file_not_mac_or_msys_or_linux(self, temp_repo): + temp_repo.change_origin_to_gitlab() git = temp_repo.get_repo_git() - set_origin_url(git, gitlab_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "unique-system" }): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:]) - expected_url = create_expected_filename(git, gitlab_origin, "gitlab", tmp_file) - openCommand.assert_called([expected_url]) + filename = temp_repo.get_filename(0) + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: + temp_repo.invoke_extras_command("browse", "origin", filename) + expected_url = get_file_uri("gitlab", filename, git) + openCommand.assert_called([expected_url]) def test_browse_bitbucket_file_not_mac_or_msys_or_linux(self, temp_repo): + temp_repo.change_origin_to_bitbucket() git = temp_repo.get_repo_git() - set_origin_url(git, bitbucket_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "unique-system" }): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:]) - expected_url = create_expected_filename(git, bitbucket_origin, "bitbucket", tmp_file) - openCommand.assert_called([expected_url]) + filename = temp_repo.get_filename(0) + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: + temp_repo.invoke_extras_command("browse", "origin", filename) + expected_url = get_file_uri("bitbucket", filename, git) + openCommand.assert_called([expected_url]) def test_browse_github_file_with_line_number(self, temp_repo): + temp_repo.change_origin_to_github() git = temp_repo.get_repo_git() - set_origin_url(git, github_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "unique-system" }): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:], "10", "20") - expected_url = create_expected_filename(git, github_origin, "github", tmp_file) - openCommand.assert_called([expected_url + "#L10-20"]) + filename = temp_repo.get_filename(0) + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: + temp_repo.invoke_extras_command("browse", "origin", filename, "10", "20") + expected_url = get_file_uri("github", filename, git) + openCommand.assert_called([expected_url + "#L10-L20"]) def test_browse_gitlab_file_with_line_number(self, temp_repo): + temp_repo.change_origin_to_gitlab() git = temp_repo.get_repo_git() - set_origin_url(git, gitlab_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "unique-system" }): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:], "10", "20") - expected_url = create_expected_filename(git, gitlab_origin, "gitlab", tmp_file) - openCommand.assert_called([expected_url + "#L10-20"]) + filename = temp_repo.get_filename(0) + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: + temp_repo.invoke_extras_command("browse", "origin", filename, "10", "20") + expected_url = get_file_uri("gitlab", filename, git) + openCommand.assert_called([expected_url + "#L10-20"]) - def test_browse_github_file_with_line_number(self, temp_repo): + def test_browse_bitbucket_file_with_line_number(self, temp_repo): + temp_repo.change_origin_to_bitbucket() git = temp_repo.get_repo_git() - set_origin_url(git, bitbucket_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "unique-system" }): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:], "10", "20") - expected_url = create_expected_filename(git, bitbucket_origin, "bitbucket", tmp_file) - openCommand.assert_called([expected_url + "#lines-10:20"]) + filename = temp_repo.get_filename(0) + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: + temp_repo.invoke_extras_command("browse", "origin", filename, "10", "20") + expected_url = get_file_uri("bitbucket", filename, git) + openCommand.assert_called([expected_url + "#lines-10:20"]) def test_browse_unknown_site_file(self, temp_repo): + temp_repo.change_origin(UNKNOWN_SITE_ORIGIN) git = temp_repo.get_repo_git() - set_origin_url(git, unknown_site_origin) - with modified_env({ "OSTYPE": "unique-system" }): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse", "origin") - openCommand.assert_called([unknown_site_origin]) + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: + temp_repo.invoke_extras_command("browse", "origin") + openCommand.assert_called([UNKNOWN_SITE_ORIGIN[0:-4]]) def test_browse_unknown_site_file_with_line_number(self, temp_repo): git = temp_repo.get_repo_git() - set_origin_url(git, unknown_site_origin) - tmp_file = temp_repo.get_file(0) - with modified_env({ "OSTYPE": "unique-system" }): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:], "10", "20") - openCommand.assert_called([unknown_site_origin]) + filename = temp_repo.get_filename(0) + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: + temp_repo.invoke_extras_command("browse", "origin", filename, "10", "20") + openCommand.assert_called([UNKNOWN_SITE_ORIGIN[0:-4]]) diff --git a/tests/test_git_browse_ci.py b/tests/test_git_browse_ci.py index 0a840e6c1..761d86d64 100644 --- a/tests/test_git_browse_ci.py +++ b/tests/test_git_browse_ci.py @@ -1,174 +1,129 @@ import os, subprocess from testpath import MockCommand, modified_env -github_origin = "https://github.com/tj/git-extras" -gitlab_origin = "https://gitlab.com/tj/git-extras" -bitbucket_origin = "https://bitbucket.org/tj/git-extras" -unknown_site_origin = "https://unknown-site.com/tj/git-extras" +UNKNOWN_SITE_ORIGIN = "https://unknown-site.com/tj/git-extras.git" -def set_origin_url(git, url): - git.remote("set-url", "origin", url + ".git") - -def create_expected_action_url(git, mode): +def get_ci_uri_by_domain(mode): if mode == "github": - return github_origin + '/actions' + return "https://github.com/tj/git-extras/actions" if mode == "gitlab": - return gitlab_origin + '/-/pipelines' + return "https://gitlab.com/tj/git-extras/-/pipelines" if mode == "bitbucket": - return bitbucket_origin + '/addon/pipelines/home' + return "https://bitbucket.org/tj/git-extras/addon/pipelines/home" class TestGitBrowse: def test_browse_github_ci_on_mac(self, temp_repo): - git = temp_repo.get_repo_git() - git.remote("add", "origin", github_origin + ".git") - with modified_env({ "OSTYPE": "darwin" }): - with MockCommand("open") as openCommand: - temp_repo.invoke_extras_command("browse-ci", "origin") - expected_url = create_expected_action_url(git, "github") - openCommand.assert_called([expected_url]) + 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): - git = temp_repo.get_repo_git() - set_origin_url(git, gitlab_origin) - with modified_env({ "OSTYPE": "darwin" }): - with MockCommand("open") as openCommand: - temp_repo.invoke_extras_command("browse-ci", "origin") - expected_url = create_expected_action_url(git, "gitlab") - openCommand.assert_called([expected_url]) + 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): - git = temp_repo.get_repo_git() - set_origin_url(git, bitbucket_origin) - with modified_env({ "OSTYPE": "darwin" }): - with MockCommand("open") as openCommand: - temp_repo.invoke_extras_command("browse-ci", "origin") - expected_url = create_expected_action_url(git, "bitbucket") - openCommand.assert_called([expected_url]) + 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): - git = temp_repo.get_repo_git() - set_origin_url(git, github_origin) - with modified_env({ "OSTYPE": "msys" }): - with MockCommand("start") as openCommand: - temp_repo.invoke_extras_command("browse-ci", "origin") - expected_url = create_expected_action_url(git, "github") - openCommand.assert_called([expected_url]) + 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): - git = temp_repo.get_repo_git() - set_origin_url(git, gitlab_origin) - with modified_env({ "OSTYPE": "msys" }): - with MockCommand("start") as openCommand: - temp_repo.invoke_extras_command("browse-ci", "origin") - expected_url = create_expected_action_url(git, "gitlab") - openCommand.assert_called([expected_url]) + 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): - git = temp_repo.get_repo_git() - set_origin_url(git, bitbucket_origin) - with modified_env({ "OSTYPE": "msys" }): - with MockCommand("start") as openCommand: - temp_repo.invoke_extras_command("browse-ci", "origin") - expected_url = create_expected_action_url(git, "bitbucket") - openCommand.assert_called([expected_url]) + 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): - git = temp_repo.get_repo_git() - set_origin_url(git, github_origin) - with modified_env({ "OSTYPE": "linux" }): - with MockCommand.fixed_output("uname", "microsoft"): - with MockCommand.fixed_output("command", "/powershell.exe"): - with MockCommand("powershell.exe") as openCommand: - temp_repo.invoke_extras_command("browse-ci", "origin") - expected_url = create_expected_action_url(git, "github") - openCommand.assert_called(["-NoProfile", "start", expected_url]) + 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): - git = temp_repo.get_repo_git() - set_origin_url(git, gitlab_origin) - with modified_env({ "OSTYPE": "linux" }): - with MockCommand.fixed_output("uname", "microsoft"): - with MockCommand.fixed_output("command", "/powershell.exe"): - with MockCommand("powershell.exe") as openCommand: - temp_repo.invoke_extras_command("browse-ci", "origin") - expected_url = create_expected_action_url(git, "gitlab") - openCommand.assert_called(["-NoProfile", "start", expected_url]) + 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): - git = temp_repo.get_repo_git() - set_origin_url(git, bitbucket_origin) - with modified_env({ "OSTYPE": "linux" }): - with MockCommand.fixed_output("uname", "microsoft"): - with MockCommand.fixed_output("command", "/powershell.exe"): - with MockCommand("powershell.exe") as openCommand: - temp_repo.invoke_extras_command("browse-ci", "origin") - expected_url = create_expected_action_url(git, "bitbucket") - openCommand.assert_called(["-NoProfile", "start", expected_url]) + 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): - git = temp_repo.get_repo_git() - set_origin_url(git, github_origin) - with modified_env({ "OSTYPE": "linux" }): - with MockCommand.fixed_output("uname", "no-micro-soft"): - with MockCommand.fixed_output("command", "/powershell.exe"): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse-ci", "origin") - expected_url = create_expected_action_url(git, "github") - openCommand.assert_called([expected_url]) + 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): - git = temp_repo.get_repo_git() - set_origin_url(git, gitlab_origin) - with modified_env({ "OSTYPE": "linux" }): - with MockCommand.fixed_output("uname", "no-micro-soft"): - with MockCommand.fixed_output("command", "/powershell.exe"): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse-ci", "origin") - expected_url = create_expected_action_url(git, "gitlab") - openCommand.assert_called([expected_url]) + 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): - git = temp_repo.get_repo_git() - set_origin_url(git, bitbucket_origin) - with modified_env({ "OSTYPE": "linux" }): - with MockCommand.fixed_output("uname", "no-micro-soft"): - with MockCommand.fixed_output("command", "/powershell.exe"): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse-ci", "origin") - expected_url = create_expected_action_url(git, "bitbucket") - openCommand.assert_called([expected_url]) + 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): - git = temp_repo.get_repo_git() - set_origin_url(git, github_origin) - with modified_env({ "OSTYPE": "unique-system" }): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse-ci", "origin") - expected_url = create_expected_action_url(git, "github") - openCommand.assert_called([expected_url]) + 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): - git = temp_repo.get_repo_git() - set_origin_url(git, gitlab_origin) - with modified_env({ "OSTYPE": "unique-system" }): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse-ci", "origin") - expected_url = create_expected_action_url(git, "gitlab") - openCommand.assert_called([expected_url]) + 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): - git = temp_repo.get_repo_git() - set_origin_url(git, bitbucket_origin) - with modified_env({ "OSTYPE": "unique-system" }): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse-ci", "origin") - expected_url = create_expected_action_url(git, "bitbucket") - openCommand.assert_called([expected_url]) + 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): - git = temp_repo.get_repo_git() - set_origin_url(git, unknown_site_origin) - with modified_env({ "OSTYPE": "unique-system" }): - with MockCommand("xdg-open") as openCommand: - temp_repo.invoke_extras_command("browse-ci", "origin") - openCommand.assert_called(['']) + 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([''])