def test_true_or_false(self): _type = types.BooleanType(self.field) value = 'true' self.assertTrue(_type.cast(value)) value = 'false' self.assertFalse(_type.cast(value))
def test_invalid_boolean_value_fails(self): _type = types.BooleanType(self.field) value = 'not a true value' self.assertRaises(exceptions.InvalidBooleanType, _type.cast, value) value = 11231902333 self.assertRaises(exceptions.InvalidBooleanType, _type.cast, value)
def test_yes_no(self): _type = types.BooleanType(self.field) value = 'yes' self.assertTrue(_type.cast(value)) value = 'no' self.assertFalse(_type.cast(value))
def test_constraints_enum_valid_value_alternate_truths(self): '''value is equivalent to possible values in enum array''' value = 'true' field = self._make_default_field( type='boolean', constraints={'enum': ['yes', 'y', 't', '1', 1]}) _type = types.BooleanType(field) self.assertEqual(_type.cast(value), True)
def test_constraints_enum_valid_value(self): '''value is in enum array''' value = 'true' field = self._make_default_field(type='boolean', constraints={'enum': [ True, ]}) _type = types.BooleanType(field) self.assertEqual(_type.cast(value), True)
def test_one_or_zero(self): _type = types.BooleanType(self.field) value = '1' self.assertTrue(_type.cast(value)) value = '0' self.assertFalse(_type.cast(value)) value = 1 self.assertTrue(_type.cast(value)) value = 0 self.assertFalse(_type.cast(value))
def test_constraints_enum_invalid_value(self): '''value is not in enum array''' value = 'true' field = self._make_default_field(type='boolean', constraints={'enum': [ False, ]}) _type = types.BooleanType(field) with pytest.raises(exceptions.ConstraintError) as e: _type.cast(value) self.assertEqual( e.value.msg, "The value for field 'Name' " "must be in the enum array")
def test_boolean_type_with_already_cast_value(self): for value in [True, False]: for format in ['default']: self.field['format'] = format _type = types.BooleanType(self.field) self.assertEqual(_type.cast(value), value)
def test_boolean_type_simple_false(self): value = 'n' _type = types.BooleanType(self.field) self.assertFalse(_type.cast(value))
def test_boolean_type_simple_true(self): value = 'y' _type = types.BooleanType(self.field) self.assertTrue(_type.cast(value))