def test_valid_apt_deb(self): repo = PackageRepositoryApt( architectures=["amd64", "i386"], components=["main", "multiverse"], formats=["deb", "deb-src"], key_id="test-key-id", key_server="keyserver.ubuntu.com", name="test-name", suites=["xenial", "xenial-updates"], url="http://archive.ubuntu.com/ubuntu", ) self.assertThat( repo.marshal(), Equals({ "architectures": ["amd64", "i386"], "components": ["main", "multiverse"], "formats": ["deb", "deb-src"], "key-id": "test-key-id", "key-server": "keyserver.ubuntu.com", "name": "test-name", "suites": ["xenial", "xenial-updates"], "type": "apt", "url": "http://archive.ubuntu.com/ubuntu", }), )
def get_required_package_repositories(self) -> List[PackageRepository]: return [ PackageRepositoryApt( deb_types=["deb"], components=["main"], key_id="C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654", url="http://packages.ros.org/ros2/ubuntu", suites=["$SNAPCRAFT_APT_RELEASE"], ) ]
def get_required_package_repositories(cls) -> List[PackageRepository]: codename = os_release.OsRelease().version_codename() return [ PackageRepositoryApt( formats=["deb"], components=["main"], key_id="C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654", url="http://packages.ros.org/ros2/ubuntu", suites=[codename], ) ]
def test_apt_invalid_path(): with pytest.raises(errors.PackageRepositoryValidationError) as exc_info: PackageRepositoryApt( key_id="A" * 40, path="", url="http://archive.ubuntu.com/ubuntu", ) assert exc_info.value.brief == "Invalid path ''." assert exc_info.value.details == "Paths must be non-empty strings." assert ( exc_info.value.resolution == "Verify the repository configuration and ensure that 'path' is a non-empty string such as '/'." )
def test_apt_name(): repo = PackageRepositoryApt( architectures=["amd64", "i386"], components=["main", "multiverse"], formats=["deb", "deb-src"], key_id="A" * 40, key_server="keyserver.ubuntu.com", suites=["xenial", "xenial-updates"], url="http://archive.ubuntu.com/ubuntu", ) assert repo.name == "http_archive_ubuntu_com_ubuntu"
def test_apt_invalid_url(): with pytest.raises(errors.PackageRepositoryValidationError) as exc_info: PackageRepositoryApt( key_id="A" * 40, url="", ) assert exc_info.value.brief == "Invalid URL ''." assert exc_info.value.details == "URLs must be non-empty strings." assert ( exc_info.value.resolution == "Verify the repository configuration and ensure that 'url' is correctly specified." )
def test_apt_invalid_suites_as_path(): with pytest.raises(errors.PackageRepositoryValidationError) as exc_info: PackageRepositoryApt( key_id="A" * 40, suites=["my-suite/"], url="http://archive.ubuntu.com/ubuntu", ) assert exc_info.value.brief == "Invalid suite 'my-suite/'." assert exc_info.value.details == "Suites must not end with a '/'." assert ( exc_info.value.resolution == "Verify the repository configuration and remove the trailing '/ from suites or use the 'path' property to define a path." )
def test_apt_invalid_missing_suites(): with pytest.raises(errors.PackageRepositoryValidationError) as exc_info: PackageRepositoryApt( key_id="A" * 40, components=["main"], url="http://archive.ubuntu.com/ubuntu", ) assert exc_info.value.brief == "No suites specified." assert exc_info.value.details == "Suites are required when using components." assert ( exc_info.value.resolution == "Verify the repository configuration and ensure that 'suites' is correctly specified." )
def test_apt_invalid_path_with_components(): with pytest.raises(errors.PackageRepositoryValidationError) as exc_info: PackageRepositoryApt( key_id="A" * 40, path="/", components=["main"], url="http://archive.ubuntu.com/ubuntu", ) assert (exc_info.value.brief == "Components ['main'] cannot be combined with path '/'.") assert exc_info.value.details == "Path and components are incomptiable options." assert ( exc_info.value.resolution == "Verify the repository configuration and remove 'path' or 'components'." )
def test_apt_invalid_path_with_suites(): with pytest.raises(errors.PackageRepositoryValidationError) as exc_info: PackageRepositoryApt( key_id="A" * 40, path="/", suites=["xenial", "xenial-updates"], url="http://archive.ubuntu.com/ubuntu", ) assert ( exc_info.value.brief == "Suites ['xenial', 'xenial-updates'] cannot be combined with path '/'." ) assert exc_info.value.details == "Path and suites are incomptiable options." assert ( exc_info.value.resolution == "Verify the repository configuration and remove 'path' or 'suites'.")
def test_install_package_repository_key_already_installed( mock_is_key_installed, is_installed, apt_gpg, ): mock_is_key_installed.return_value = is_installed package_repo = PackageRepositoryApt( components=["main", "multiverse"], key_id="8" * 40, key_server="xkeyserver.com", suites=["xenial"], url="http://archive.ubuntu.com/ubuntu", ) updated = apt_gpg.install_package_repository_key(package_repo=package_repo) assert updated is not is_installed
def test_apt_install_implied_path(mock_repo, tmp_path): repo = PackageRepositoryApt( key_id="A" * 40, url="http://archive.ubuntu.com/ubuntu", ) repo.install() assert mock_repo.mock_calls == [ mock.call.install_sources( architectures=None, components=None, formats=None, name="http_archive_ubuntu_com_ubuntu", suites=["/"], url="http://archive.ubuntu.com/ubuntu", ), ]
def test_install_package_repository_key_from_asset( mock_install_key, mock_is_key_installed, apt_gpg, key_assets, ): key_id = "8" * 40 expected_key_path = key_assets / ("8" * 8 + ".asc") expected_key_path.write_text("key-data") package_repo = PackageRepositoryApt( components=["main", "multiverse"], key_id=key_id, suites=["xenial"], url="http://archive.ubuntu.com/ubuntu", ) updated = apt_gpg.install_package_repository_key(package_repo=package_repo) assert updated is True assert mock_install_key.mock_calls == [call(key="key-data")]
def test_install_package_repository_key_apt_from_keyserver( mock_install_key_from_keyserver, mock_is_key_installed, apt_gpg, ): key_id = "8" * 40 package_repo = PackageRepositoryApt( components=["main", "multiverse"], key_id=key_id, key_server="key.server", suites=["xenial"], url="http://archive.ubuntu.com/ubuntu", ) updated = apt_gpg.install_package_repository_key(package_repo=package_repo) assert updated is True assert mock_install_key_from_keyserver.mock_calls == [ call(key_id=key_id, key_server="key.server") ]
def test_apt_marshal(): repo = PackageRepositoryApt( architectures=["amd64", "i386"], components=["main", "multiverse"], formats=["deb", "deb-src"], key_id="A" * 40, key_server="xkeyserver.ubuntu.com", name="test-name", suites=["xenial", "xenial-updates"], url="http://archive.ubuntu.com/ubuntu", ) assert repo.marshal() == { "architectures": ["amd64", "i386"], "components": ["main", "multiverse"], "formats": ["deb", "deb-src"], "key-id": "A" * 40, "key-server": "xkeyserver.ubuntu.com", "name": "test-name", "suites": ["xenial", "xenial-updates"], "type": "apt", "url": "http://archive.ubuntu.com/ubuntu", }
def test_apt_install(mock_repo, tmp_path): repo = PackageRepositoryApt( architectures=["amd64", "i386"], components=["main", "multiverse"], formats=["deb", "deb-src"], key_id="A" * 40, key_server="xkeyserver.ubuntu.com", name="some-name", suites=["xenial", "xenial-updates"], url="http://archive.ubuntu.com/ubuntu", ) repo.install() assert mock_repo.mock_calls == [ mock.call.install_sources( architectures=["amd64", "i386"], components=["main", "multiverse"], formats=["deb", "deb-src"], name="some-name", suites=["xenial", "xenial-updates"], url="http://archive.ubuntu.com/ubuntu", ), ]
def test_apt_valid_architectures(arch): package_repo = PackageRepositoryApt(key_id="A" * 40, url="http://test", architectures=[arch]) assert package_repo.architectures == [arch]
apt_sources_manager._sudo_write_file(dst_path="/foo/bar", content=b"some-content") assert (str(error.value).startswith( "Failed to install repository config with: ['sudo', 'install'") is True) @pytest.mark.parametrize( "package_repo,name,content", [ ( PackageRepositoryApt( architectures=["amd64", "arm64"], components=["test-component"], formats=["deb", "deb-src"], key_id="A" * 40, suites=["test-suite1", "test-suite2"], url="http://test.url/ubuntu", ), "snapcraft-http_test_url_ubuntu.sources", dedent("""\ Types: deb deb-src URIs: http://test.url/ubuntu Suites: test-suite1 test-suite2 Components: test-component Architectures: amd64 arm64 """).encode(), ), ( PackageRepositoryApt( architectures=["amd64", "arm64"],