import unittest

from policy import Policy


class PolicyTests(unittest.TestCase):
    def test_initial_decision_uses_current_flag(self):
        self.assertTrue(Policy({"preview": True}).allows("u1", "preview"))

    def test_users_have_independent_cache_entries(self):
        policy = Policy({"preview": True})
        self.assertTrue(policy.allows("u1", "preview"))
        self.assertTrue(policy.allows("u2", "preview"))

    def test_setting_flag_invalidates_prior_decisions(self):
        policy = Policy({"preview": False})
        self.assertFalse(policy.allows("u1", "preview"))
        policy.set_flag("preview", True)
        self.assertTrue(policy.allows("u1", "preview"))


if __name__ == "__main__":
    unittest.main()
