import unittest

from policy import Policy


class HoldoutPolicyTests(unittest.TestCase):
    def test_true_to_false_toggle_invalidates(self):
        policy = Policy({"preview": True})
        self.assertTrue(policy.allows("u1", "preview"))
        policy.set_flag("preview", False)
        self.assertFalse(policy.allows("u1", "preview"))

    def test_repeated_toggles_do_not_reuse_stale_value(self):
        policy = Policy({"preview": False})
        for value in (True, False, True):
            policy.set_flag("preview", value)
            self.assertEqual(policy.allows("u1", "preview"), value)
