def test_contract_status_entitled(self, tmpdir):
     """The contract_status returns ENTITLED when entitled is True."""
     cfg = config.UAConfig(cfg={'data_dir': tmpdir.strpath})
     cfg.write_cache('machine-token', dict(LIVEPATCH_MACHINE_TOKEN))
     cfg.write_cache('machine-access-livepatch',
                     dict(LIVEPATCH_RESOURCE_ENTITLED))
     entitlement = LivepatchEntitlement(cfg)
     assert status.ENTITLED == entitlement.contract_status()
    def test_contract_status_unentitled(self, tmpdir):
        """The contract_status returns NONE when entitled is False."""
        livepatch_unentitled = copy.deepcopy(dict(LIVEPATCH_RESOURCE_ENTITLED))

        # Make livepatch resource access report not entitled
        livepatch_unentitled['entitlement']['entitled'] = False
        cfg = config.UAConfig(cfg={'data_dir': tmpdir.strpath})
        cfg.write_cache('machine-token', dict(LIVEPATCH_MACHINE_TOKEN))
        cfg.write_cache('machine-access-livepatch', livepatch_unentitled)
        entitlement = LivepatchEntitlement(cfg)
        assert status.NONE == entitlement.contract_status()