def test_list_repos(): """ Checks results from list_repos """ # Valid source source_type = "deb" source_uri = "http://cdn-aws.deb.debian.org/debian/" source_line = "deb http://cdn-aws.deb.debian.org/debian/ stretch main\n" mock_source = MockSourceEntry(source_uri, source_type, source_line, False) mock_source_list = MockSourceList() mock_source_list.list = [mock_source] with patch("salt.modules.aptpkg.SourcesList", MagicMock(), create=True): with patch("salt.modules.aptpkg.SourceEntry", MagicMock(), create=True): with patch( "salt.modules.aptpkg.SourcesList", MagicMock(return_value=mock_source_list), create=True, ): repos = aptpkg.list_repos() assert source_uri in repos assert isinstance(repos[source_uri], list) assert len(repos[source_uri]) == 1 # Make sure last character in of the URI in line is still a / assert "line" in repos[source_uri][0] _uri = _get_uri(repos[source_uri][0]["line"]) assert _uri[-1] == "/" # Make sure last character in URI is still a / assert "uri" in repos[source_uri][0] assert repos[source_uri][0]["uri"][-1] == "/"
def test_list_repos(self): """ Checks results from list_repos """ # Valid source source_type = "deb" source_uri = "http://cdn-aws.deb.debian.org/debian/" source_line = "deb http://cdn-aws.deb.debian.org/debian/ stretch main\n" mock_source = MockSourceEntry(source_uri, source_type, source_line, False) mock_source_list = MockSourceList() mock_source_list.list = [mock_source] with patch("salt.modules.aptpkg._check_apt", MagicMock(return_value=True)): with patch("salt.modules.aptpkg.sourceslist", MagicMock(), create=True): with patch( "salt.modules.aptpkg.sourceslist.SourcesList", MagicMock(return_value=mock_source_list), create=True, ): repos = aptpkg.list_repos() self.assertIn(source_uri, repos) assert isinstance(repos[source_uri], list) assert len(repos[source_uri]) == 1 # Make sure last character in of the URI in line is still a / self.assertIn("line", repos[source_uri][0]) _uri = _get_uri(repos[source_uri][0]["line"]) self.assertEqual(_uri[-1], "/") # Make sure last character in URI is still a / self.assertIn("uri", repos[source_uri][0]) self.assertEqual(repos[source_uri][0]["uri"][-1], "/")
def test_list_repos(): """ Test aptpkg.list_repos """ ret = aptpkg.list_repos() repos = [x for x in ret if "http" in x] for repo in repos: check_repo = ret[repo][0] for key in [ "comps", "dist", "uri", "line", "architectures", "file", "type", ]: assert key in check_repo assert pathlib.Path(check_repo["file"]).is_file() assert check_repo["dist"] in check_repo["line"] if isinstance(check_repo["comps"], list): assert " ".join(check_repo["comps"]) in check_repo["line"] else: assert check_repo["comps"] in check_repo["line"]