def test_apt_unmarshal_invalid_extra_keys(): test_dict = { "architectures": ["amd64", "i386"], "components": ["main", "multiverse"], "formats": ["deb", "deb-src"], "key-id": "A" * 40, "key-server": "keyserver.ubuntu.com", "name": "test-name", "suites": ["xenial", "xenial-updates"], "type": "apt", "url": "http://archive.ubuntu.com/ubuntu", "foo": "bar", "foo2": "bar", } with pytest.raises(errors.PackageRepositoryValidationError) as exc_info: PackageRepositoryApt.unmarshal(test_dict) assert ( exc_info.value.brief == "Found unsupported package repository properties 'foo', 'foo2'." ) assert exc_info.value.details is None assert ( exc_info.value.resolution == "Verify repository configuration and ensure it is correct." )
def test_apt_unmarshal_invalid_data(): test_dict = "not-a-dict" with pytest.raises(errors.PackageRepositoryValidationError) as exc_info: PackageRepositoryApt.unmarshal(test_dict) assert exc_info.value.brief == "Invalid package repository object 'not-a-dict'." assert ( exc_info.value.details == "Package repository must be a valid dictionary object." ) assert ( exc_info.value.resolution == "Verify repository configuration and ensure that the correct syntax is used." )
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_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_unmarshal_invalid_type(): test_dict = { "architectures": ["amd64", "i386"], "components": ["main", "multiverse"], "formats": ["deb", "deb-src"], "key-id": "A" * 40, "key-server": "keyserver.ubuntu.com", "name": "test-name", "suites": ["xenial", "xenial-updates"], "type": "aptx", "url": "http://archive.ubuntu.com/ubuntu", } with pytest.raises(errors.PackageRepositoryValidationError) as exc_info: PackageRepositoryApt.unmarshal(test_dict) assert exc_info.value.brief == "Unsupported type 'aptx'." assert exc_info.value.details == "The only currently supported type is 'apt'." assert ( exc_info.value.resolution == "Verify repository configuration and ensure that 'type' is correctly specified." )
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_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 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_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_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_from_asset( mock_install_key, mock_is_key_installed, apt_gpg, key_assets, ): key_id = "123456789012345678901234567890123456AABB" expected_key_path = key_assets / "3456AABB.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") ]
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"],
def test_apt_valid_architectures(arch): package_repo = PackageRepositoryApt( key_id="A" * 40, url="http://test", architectures=[arch] ) assert package_repo.architectures == [arch]