def test_blankable(self):
        v = BooleanField(blank=True, blank_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 1
            mocked_random.choice = random.choice
            self.assertIn(v.generate(), [True, False])

        v = BooleanField(blank=True, blank_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 0
            mocked_random.choice = random.choice
            self.assertFalse(v.generate())
    def test_not_required(self):
        v = BooleanField(required=False, not_present_prob=0)
        self.assertIn(v.generate(), [True, False])

        v = BooleanField(required=False, not_present_prob=1)
        with self.assertRaises(NotGeneratedException):
            v.generate()

        v = BooleanField(required=False, not_present_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 0
            with self.assertRaises(NotGeneratedException):
                v.generate()

        v = BooleanField(required=False, not_present_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 1
            mocked_random.choice = random.choice
            self.assertIn(v.generate(), [True, False])
 def test_default(self):
     v = BooleanField()
     self.assertIn(v.generate(), [True, False])