# Path: django_sonic_screwdriver/helper.py
# def underscoreize(data):
#     """
#     Underscoring data.
#     """
#     if isinstance(data, dict):
#         new_dict = {}
#         for key, value in get_iterable(data):
#             if isinstance(key, str):
#                 new_key = camel_to_underscore(key)
#             else:
#                 new_key = key
#             new_dict[new_key] = underscoreize(value)
# 
#         if isinstance(data, QueryDict):
#             new_query = QueryDict(mutable=True)
#             for key, value in new_dict.items():
#                 new_query.setlist(key, value)
#             return new_query
#         return new_dict
#     if is_iterable(data) and not isinstance(data, (str, File)):
#         return [underscoreize(item) for item in data]
# 
#     return data


from django.http import QueryDict
from django.test import TestCase
from django_sonic_screwdriver.helper import underscoreize


class HelperTest(TestCase):
    def test_underscorize_with_simple_dict(self):
        data = {"test": "test", "ANewTest": "42", 2: "bla"}
        data = underscoreize(data)
        self.assertEqual(data, {2: "bla", "a_new_test": "42", "test": "test"})

    def test_underscorize_with_querydict(self):
        query_dict = QueryDict("AParam=1&AnotherParam=2&c=3")

# Path: django_sonic_screwdriver/helper.py
# def underscoreize(data):
#     """
#     Underscoring data.
#     """
#     if isinstance(data, dict):
#         new_dict = {}
#         for key, value in get_iterable(data):
#             if isinstance(key, str):
#                 new_key = camel_to_underscore(key)
#             else:
#                 new_key = key
#             new_dict[new_key] = underscoreize(value)
# 
#         if isinstance(data, QueryDict):
#             new_query = QueryDict(mutable=True)
#             for key, value in new_dict.items():
#                 new_query.setlist(key, value)
#             return new_query
#         return new_dict
#     if is_iterable(data) and not isinstance(data, (str, File)):
#         return [underscoreize(item) for item in data]
# 
#     return data


# Path: tests/test_helper.py
from django.http import QueryDict
from django.test import TestCase
from django_sonic_screwdriver.helper import underscoreize



class HelperTest(TestCase):
    def test_underscorize_with_simple_dict(self):
        data = {"test": "test", "ANewTest": "42", 2: "bla"}
        data = underscoreize(data)
        self.assertEqual(data, {2: "bla", "a_new_test": "42", "test": "test"})

    def test_underscorize_with_querydict(self):
        query_dict = QueryDict("AParam=1&AnotherParam=2&c=3")

        data = underscoreize(query_dict)