def test_ppa_unmarshal_invalid_apt_ppa_extra_keys(): test_dict = {"type": "apt", "ppa": "test/ppa", "test": "foo"} with pytest.raises(errors.PackageRepositoryValidationError) as raised: PackageRepositoryAptPPA.unmarshal(test_dict) err = raised.value assert str(err) == ( "Invalid package repository for 'test/ppa': unsupported properties 'test'." ) assert err.details is None assert err.resolution == ( "Verify repository configuration and ensure that it is correct.")
def test_ppa_unmarshal_invalid_data(): test_dict = "not-a-dict" with pytest.raises(errors.PackageRepositoryValidationError) as raised: PackageRepositoryAptPPA.unmarshal(test_dict) # type: ignore err = raised.value assert str( err) == "Invalid package repository for 'not-a-dict': invalid object." assert err.details == "Package repository must be a valid dictionary object." assert err.resolution == ( "Verify repository configuration and ensure that the correct syntax is used." )
def test_ppa_unmarshal_invalid_apt_ppa_type(): test_dict = {"type": "aptx", "ppa": "test/ppa"} with pytest.raises(errors.PackageRepositoryValidationError) as raised: PackageRepositoryAptPPA.unmarshal(test_dict) err = raised.value assert str(err) == ( "Invalid package repository for 'test/ppa': unsupported type 'aptx'.") assert err.details == "The only currently supported type is 'apt'." assert err.resolution == ( "Verify repository configuration and ensure that 'type' is correctly specified." )
def test_install_ppa_invalid(apt_sources_mgr): repo = PackageRepositoryAptPPA(ppa="ppa-missing-slash") with pytest.raises(errors.AptPPAInstallError) as raised: apt_sources_mgr.install_package_repository_sources(package_repo=repo) assert str(raised.value) == ( "Failed to install PPA 'ppa-missing-slash': invalid PPA format" )
def test_ppa_invalid_ppa(): with pytest.raises(errors.PackageRepositoryValidationError) as raised: PackageRepositoryAptPPA(ppa="") err = raised.value assert str(err) == "Invalid package repository for '': invalid PPA." assert err.details == "PPAs must be non-empty strings." assert err.resolution == ( "Verify repository configuration and ensure that 'ppa' is correctly specified." )
def test_install_package_repository_key_ppa_from_keyserver(apt_gpg, mocker): mock_install_key_from_keyserver = mocker.patch( "snapcraft.repo.apt_key_manager.AptKeyManager.install_key_from_keyserver" ) mocker.patch( "snapcraft.repo.apt_key_manager.AptKeyManager.is_key_installed", return_value=False, ) package_repo = PackageRepositoryAptPPA(ppa="test/ppa") 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="FAKE-PPA-SIGNING-KEY", key_server="keyserver.ubuntu.com") ]
def test_ppa_marshal(): repo = PackageRepositoryAptPPA(ppa="test/ppa") assert repo.marshal() == {"type": "apt", "ppa": "test/ppa"}
key_id="A" * 40, name="IMPLIED-PATH", url="http://test.url/ubuntu", ), "snapcraft-IMPLIED-PATH.sources", dedent( """\ Types: deb URIs: http://test.url/ubuntu Suites: / Architectures: FAKE-HOST-ARCH """ ).encode(), ), ( PackageRepositoryAptPPA(ppa="test/ppa"), "snapcraft-ppa-test_ppa.sources", dedent( """\ Types: deb URIs: http://ppa.launchpad.net/test/ppa/ubuntu Suites: FAKE-CODENAME Components: main Architectures: FAKE-HOST-ARCH """ ).encode(), ), ], ) def test_install(package_repo, name, content, apt_sources_mgr, mocker): run_mock = mocker.patch("subprocess.run")