Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds enabled kwarg #207

Merged
merged 1 commit into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions salt/modules/aptpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2353,6 +2353,8 @@ def mod_repo(repo, saltenv='base', **kwargs):

if 'disabled' in kwargs:
kwargs['disabled'] = salt.utils.data.is_true(kwargs['disabled'])
elif 'enabled' in kwargs:
kwargs['disabled'] = not salt.utils.data.is_true(kwargs['enabled'])

kw_type = kwargs.get('type')
kw_dist = kwargs.get('dist')
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/modules/test_aptpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,30 @@ def test_show(self):
self.assert_called_once(refresh_mock)
refresh_mock.reset_mock()

def test_mod_repo_enabled(self):
'''
Checks if a repo is enabled or disabled depending on the passed kwargs.
'''
with patch.dict(aptpkg.__salt__, {'config.option': MagicMock(), 'no_proxy': MagicMock(return_value=False)}):
with patch('salt.modules.aptpkg._check_apt', MagicMock(return_value=True)):
with patch('salt.modules.aptpkg.refresh_db', MagicMock(return_value={})):
with patch('salt.utils.data.is_true', MagicMock(return_value=True)) as data_is_true:
with patch('salt.modules.aptpkg.sourceslist', MagicMock(), create=True):
repo = aptpkg.mod_repo('foo', enabled=False)
data_is_true.assert_called_with(False)
# with disabled=True; should call salt.utils.data.is_true True
data_is_true.reset_mock()
repo = aptpkg.mod_repo('foo', disabled=True)
data_is_true.assert_called_with(True)
# with enabled=True; should call salt.utils.data.is_true with False
data_is_true.reset_mock()
repo = aptpkg.mod_repo('foo', enabled=True)
data_is_true.assert_called_with(True)
# with disabled=True; should call salt.utils.data.is_true False
data_is_true.reset_mock()
repo = aptpkg.mod_repo('foo', disabled=False)
data_is_true.assert_called_with(False)

@patch('salt.utils.path.os_walk', MagicMock(return_value=[('test', 'test', 'test')]))
@patch('os.path.getsize', MagicMock(return_value=123456))
@patch('os.path.getctime', MagicMock(return_value=1234567890.123456))
Expand Down