diff --git a/tests/unit/base/test_serialize.py b/tests/unit/base/test_serialize.py index 204fe2c2a..57891a65b 100644 --- a/tests/unit/base/test_serialize.py +++ b/tests/unit/base/test_serialize.py @@ -90,6 +90,28 @@ def test_list(self): self.assertEqual({}, actual) +class BooleanTestCase(unittest.TestCase): + def test_none(self): + value = None + actual = serialize.boolean_to_string(value) + self.assertIsNone(actual) + + def test_string(self): + value = "True" + actual = serialize.boolean_to_string(value) + self.assertEqual("true", actual) + + def test_bool_true(self): + value = True + actual = serialize.boolean_to_string(value) + self.assertEqual("true", actual) + + def test_bool_false(self): + value = False + actual = serialize.boolean_to_string(value) + self.assertEqual("false", actual) + + class ObjectTestCase(unittest.TestCase): def test_object(self): actual = serialize.object({"twilio": "rocks"}) diff --git a/twilio/base/serialize.py b/twilio/base/serialize.py index 3abc0defe..eac2e12c2 100644 --- a/twilio/base/serialize.py +++ b/twilio/base/serialize.py @@ -61,6 +61,16 @@ def flatten_dict(d, result=None, prv_keys=None): return {} +def boolean_to_string(bool_or_str): + if bool_or_str is None: + return bool_or_str + + if isinstance(bool_or_str, str): + return bool_or_str.lower() + + return "true" if bool_or_str else "false" + + def object(obj): """ Return a jsonified string represenation of obj if obj is jsonifiable else