Skip to content

Commit ad29c6c

Browse files
committed
Fixes rendering of tuple values
1 parent bde6fbb commit ad29c6c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

djangorestframework_camel_case/util.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ def camelize(data):
1616
new_key = re.sub(r"[a-z]_[a-z]", underscoreToCamel, key)
1717
new_dict[new_key] = camelize(value)
1818
return new_dict
19-
if isinstance(data, (list, tuple)):
19+
if isinstance(data, list):
2020
for i in range(len(data)):
2121
data[i] = camelize(data[i])
2222
return data
23+
if isinstance(data, tuple):
24+
camelized_data = []
25+
for i in range(len(data)):
26+
camelized_data.append(camelize(data[i]))
27+
return tuple(camelized_data)
2328
return data
2429

2530

tests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99
class UnderscoreToCamelTestCase(TestCase):
10+
1011
def test_under_to_camel(self):
1112
input = {
1213
"title_display": 1
@@ -16,6 +17,14 @@ def test_under_to_camel(self):
1617
}
1718
self.assertEqual(camelize(input), output)
1819

20+
def test_tuples(self):
21+
input = {
22+
"multiple_values" : (1, 2)
23+
}
24+
output = {
25+
"multipleValues": (1, 2)
26+
}
27+
self.assertEqual(camelize(input), output)
1928

2029
class CamelToUnderscoreTestCase(TestCase):
2130
def test_under_to_camel(self):

0 commit comments

Comments
 (0)