Skip to content

Commit

Permalink
add stub of module unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasmhughes committed Feb 13, 2024
1 parent 7b1ef60 commit 72aa24b
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions tests/unit/modules/test_github.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,51 @@
from unittest.mock import MagicMock
from unittest.mock import patch

import pytest
import salt.modules.test as testmod
import salt.modules.config as config_module
import saltext.github.modules.github as github_module
from salt.exceptions import CommandExecutionError


@pytest.fixture
def configure_loader_modules():
module_globals = {
"__salt__": {"test.echo": testmod.echo},
"__opts__": {
"valid": {"there": "found"},
"github": {
"token": "abc1234",
"org_name": "my_organization",
"repo_name": "my_repo",
"allow_repo_privacy_changes": False,
},
},
"__salt__": {"config.option": config_module.option},
}
return {
config_module: module_globals,
github_module: module_globals,
}


def test__get_config_value_bad_profile():
with pytest.raises(CommandExecutionError):
github_module._get_config_value("not_there", "didnt_get_here")


def test__get_config_value_bad_config_name():
with pytest.raises(CommandExecutionError):
github_module._get_config_value("valid", "not_there")


def test__get_config_value():
ret = github_module._get_config_value("valid", "there")
assert ret == "found"


def test__get_client():
mock_client = MagicMock()
assert not github_module.__context__
with patch("github.Github", mock_client):
github_module._get_client("github")
mock_client.assert_called_with("abc1234", per_page=100)
assert "github.abc1234:my_organization" in github_module.__context__

0 comments on commit 72aa24b

Please sign in to comment.