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_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_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_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")