def test_unavailable_on_unentitled(self, m_platform_info, entitlement): """When unentitled, return UNAVAILABLE.""" no_entitlements = copy.deepcopy(machine_token("blah")) # delete all enttlements no_entitlements["machineTokenInfo"]["contractInfo"][ "resourceEntitlements"].pop() entitlement.cfg.write_cache("machine-token", no_entitlements) m_platform_info.return_value = dict(PLATFORM_INFO_SUPPORTED) applicability, _details = entitlement.applicability_status() assert ApplicabilityStatus.APPLICABLE == applicability uf_status, uf_details = entitlement.user_facing_status() assert UserFacingStatus.UNAVAILABLE == uf_status assert "Repo Test Class is not entitled" == uf_details.msg
def test_user_facing_status_unavailable_on_unentitled(self, entitlement): """Status UNAVAILABLE on absent entitlement contract status.""" no_entitlements = machine_token(LivepatchEntitlement.name) # Delete livepatch entitlement info no_entitlements["machineTokenInfo"]["contractInfo"][ "resourceEntitlements"].pop() entitlement.cfg.write_cache("machine-token", no_entitlements) with mock.patch("uaclient.util.get_platform_info") as m_platform_info: m_platform_info.return_value = PLATFORM_INFO_SUPPORTED uf_status, details = entitlement.user_facing_status() assert uf_status == status.UserFacingStatus.UNAVAILABLE assert "Livepatch is not entitled" == details
def test_inapplicable_on_unentitled(self, m_platform_info, entitlement): """When unentitled raises a failure, return INAPPLICABLE.""" no_entitlements = copy.deepcopy(machine_token(RepoTestEntitlement)) # delete all enttlements no_entitlements["machineTokenInfo"]["contractInfo"][ "resourceEntitlements"].pop() entitlement.cfg.write_cache("machine-token", no_entitlements) entitlement.cfg.delete_cache_key("machine-access-repotest") m_platform_info.return_value = dict(PLATFORM_INFO_SUPPORTED) applicability, _details = entitlement.applicability_status() assert status.ApplicabilityStatus.APPLICABLE == applicability uf_status, uf_details = entitlement.user_facing_status() assert status.UserFacingStatus.INAPPLICABLE == uf_status assert "Repo Test Class is not entitled" == uf_details
from uaclient import apt from uaclient import config from uaclient import status from uaclient.entitlements.cc import CC_README, CommonCriteriaEntitlement from uaclient.entitlements.tests.conftest import machine_token M_REPOPATH = "uaclient.entitlements.repo." CC_MACHINE_TOKEN = machine_token( entitlement_type="cc-eal", obligations={"enableByDefault": False}, entitled=True, directives={ "aptURL": "http://CC", "aptKey": "APTKEY", "suites": ["xenial"], "additionalPackages": ["ubuntu-commoncriteria"], }, affordances={ "architectures": ["x86_64", "ppc64le", "s390x"], "series": ["xenial"], }, ) PLATFORM_INFO_SUPPORTED = MappingProxyType({ "arch": "s390x", "series": "xenial", "kernel": "4.15.0-00-generic",