Skip to content

Commit

Permalink
Add unit test for ticket functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurk93 committed Nov 9, 2023
1 parent 6cc9cbb commit c60d1d8
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/utilities/test_git_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from secureli.utilities.git_meta import git_user_email, origin_url, current_branch_name

mock_git_origin_url = r'[email protected]:my-org/repo%20with%20spaces.git'

@pytest.fixture()
def mock_subprocess(mocker: MockerFixture) -> MagicMock:
Expand Down Expand Up @@ -36,6 +37,17 @@ def mock_open_git_head(mocker: MockerFixture) -> MagicMock:
return mock_open_git_head


@pytest.fixture()
def mock_open_git_origin(mocker: MockerFixture) -> MagicMock:
mock_open_git_config = mocker.mock_open(
read_data='[remote "origin"]'
'\n url = ' + mock_git_origin_url +
'\n fetch = +refs/heads/*:refs/remotes/origin/*'
)
mocker.patch("builtins.open", mock_open_git_config)
return mock_open_git_config


@pytest.fixture()
def mock_open_io_error(mocker: MockerFixture) -> MagicMock:
mock_open_io_error = mocker.patch("builtins.open")
Expand Down Expand Up @@ -71,3 +83,10 @@ def test_current_branch_name_yields_unknown_due_to_io_error(
result = current_branch_name()

assert result == "UNKNOWN"


def test_configparser_can_read_origin_url_with_percent(
mock_open_git_origin
):
assert origin_url() == mock_git_origin_url
mock_open_git_origin.assert_called_once_with(".git/config", encoding='locale')

0 comments on commit c60d1d8

Please sign in to comment.