"""Test JSON.""" from decimal import Decimal from api.utils import json def test_convert_data(): """Test convert_data function.""" raw = Decimal('123.45') converted = json.convert_data(raw) assert type(converted) == float assert converted == 123.45 def test_convert_data_passthrough(): """Test convert_data passthrough.""" class SomeClass: pass raw = SomeClass() converted = json.convert_data(raw) assert type(converted) == SomeClass def test_convert_key(): """Test convert_key function.""" cases = ( ('Test.One', 'test_one'), ('This-Is-A-T.E.S.T!', 'this_is_a_t_e_s_t'), ('foo bar', 'foo_bar'), ('foo1 bar2baz', 'foo1_bar2baz'), ('nothing_to_change', 'nothing_to_change')) for test, expected in cases: result = json.convert_key(test) assert result == expected