"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/unit/modules/test_opkg.py" between
salt-3002.1.tar.gz and salt-3002.2.tar.gz

About: SaltStack is a systems management software for data center automation, cloud orchestration, server provisioning, configuration management and more. Community version.

test_opkg.py  (salt-3002.1):test_opkg.py  (salt-3002.2)
""" """
:synopsis: Unit Tests for Package Management module 'module.opkg' :synopsis: Unit Tests for Package Management module 'module.opkg'
:platform: Linux :platform: Linux
""" """
import collections import collections
import copy import copy
import os import os
import textwrap
import salt.modules.opkg as opkg import salt.modules.opkg as opkg
import salt.utils.platform
from tests.support.mixins import LoaderModuleMockMixin from tests.support.mixins import LoaderModuleMockMixin
from tests.support.mock import MagicMock, patch from tests.support.mock import MagicMock, mock_open, patch
from tests.support.unit import TestCase from tests.support.unit import TestCase, skipIf
@skipIf(not salt.utils.platform.is_linux(), "Must be on Linux!")
class OpkgTestCase(TestCase, LoaderModuleMockMixin): class OpkgTestCase(TestCase, LoaderModuleMockMixin):
""" """
Test cases for salt.modules.opkg Test cases for salt.modules.opkg
""" """
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
cls.opkg_vim_info = { cls.opkg_vim_info = {
"vim": { "vim": {
"Package": "vim", "Package": "vim",
skipping to change at line 278 skipping to change at line 281
""" """
Test - Return the information of version_clean Test - Return the information of version_clean
""" """
self.assertEqual(opkg.version_clean("1.0.1"), "1.0.1") self.assertEqual(opkg.version_clean("1.0.1"), "1.0.1")
def test_check_extra_requirements(self): def test_check_extra_requirements(self):
""" """
Test - Return the information of check_extra_requirements Test - Return the information of check_extra_requirements
""" """
self.assertEqual(opkg.check_extra_requirements("vim", "1.0.1"), True) self.assertEqual(opkg.check_extra_requirements("vim", "1.0.1"), True)
def _get_repo(self, enabled, compressed, name, uri, file, trusted=None):
feed = {
"enabled": enabled,
"compressed": compressed,
"name": name,
"uri": uri,
"file": file,
}
if trusted is not None:
feed["trusted"] = trusted
return feed
def test_list_repos(self):
feeds_content = textwrap.dedent(
"""\
src/gz name1 url1
src name2 url2
#src/gz name3 url3
src/gz name4 url4 [trusted=yes]
src/gz "name5 space" url5 [trusted=no]
"""
)
expected_feed1 = self._get_repo(
True, True, "name1", "url1", "/etc/opkg/test.conf"
)
expected_feed2 = self._get_repo(
True, False, "name2", "url2", "/etc/opkg/test.conf"
)
expected_feed3 = self._get_repo(
False, True, "name3", "url3", "/etc/opkg/test.conf"
)
expected_feed4 = self._get_repo(
True, True, "name4", "url4", "/etc/opkg/test.conf", True
)
expected_feed5 = self._get_repo(
True, True, "name5 space", "url5", "/etc/opkg/test.conf", False
)
file_mock = mock_open(read_data={"/etc/opkg/test.conf": feeds_content})
with patch.object(
opkg.os, "listdir", MagicMock(return_value=["test.conf", "test"])
):
with patch.object(opkg.salt.utils.files, "fopen", file_mock):
repos = opkg.list_repos()
self.assertDictEqual(expected_feed1, repos["url1"][0])
self.assertDictEqual(expected_feed2, repos["url2"][0])
self.assertDictEqual(expected_feed3, repos["url3"][0])
self.assertDictEqual(expected_feed4, repos["url4"][0])
self.assertDictEqual(expected_feed5, repos["url5"][0])
def test_mod_repo_add_new_repo(self):
kwargs = {"uri": "url", "compressed": True, "enabled": True, "trusted":
True}
file_mock = mock_open()
expected = "src/gz repo url [trusted=yes]\n"
with patch.object(opkg, "list_repos", MagicMock(return_value=[])):
with patch.object(opkg.salt.utils.files, "fopen", file_mock):
opkg.mod_repo("repo", **kwargs)
handle = file_mock.filehandles["/etc/opkg/repo.conf"][0]
handle.write.assert_called_once_with(expected)
def test_mod_repo_set_trusted(self):
file_content = textwrap.dedent(
"""\
src/gz repo url
"""
)
file_mock = mock_open(read_data={"/etc/opkg/repo.conf": file_content})
kwargs = {"trusted": True}
expected = "src/gz repo url [trusted=yes]\n"
with patch.object(opkg.os, "listdir", MagicMock(return_value=["repo.conf
"])):
with patch.object(opkg.salt.utils.files, "fopen", file_mock):
opkg.mod_repo("repo", **kwargs)
handle = file_mock.filehandles["/etc/opkg/repo.conf"][2]
handle.writelines.assert_called_once_with([expected])
def test_mod_repo_repo_exists(self):
file_content = textwrap.dedent(
"""\
src/gz repo url
"""
)
file_mock = mock_open(read_data={"/etc/opkg/repo.conf": file_content})
kwargs = {"uri": "url"}
expected = "Repository 'url' already exists as 'repo'."
with patch.object(opkg.os, "listdir", MagicMock(return_value=["repo.conf
"])):
with patch.object(opkg.salt.utils.files, "fopen", file_mock):
with self.assertRaisesRegex(opkg.CommandExecutionError, expected
):
opkg.mod_repo("repo2", **kwargs)
def test_mod_repo_uri_not_provided(self):
expected = "Repository 'repo' not found and no URI passed to create one.
"
with patch.object(opkg, "list_repos", MagicMock(return_value=[])):
with self.assertRaisesRegex(opkg.CommandExecutionError, expected):
opkg.mod_repo("repo")
 End of changes. 5 change blocks. 
2 lines changed or deleted 5 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)