# Path: django_test_tools/utils.py
# def convert_to_snake_case(camel_case):
#     """
#     Converts a CamelCase name to snake case.
#     ..code-block:: python
# 
#         camel_case = 'OperatingSystemLongName'
#         snake_case = convert_to_snake_case(camel_case)
#         self.assertEqual(snake_case, 'operating_system_long_name')
# 
#     :param camel_case: string. Camel case name
#     :return: string. Snake case name
#     """
#     s1 = first_cap_re.sub(r'\1_\2', camel_case)
#     return all_cap_re.sub(r'\1_\2', s1).lower()


from ..utils import convert_to_snake_case
        \"\"\"
        {1} = {0}Factory.create()
"""

PRINT_TEST_ATTRIBUTE_UNIQUE = """
    def test_{2}_is_unique(self):
        \"\"\"
        Tests attribute {2} of model {0} to see if the unique constraint works.
        This test should break if the unique attribute is changed.
        \"\"\"
        {1} = {0}Factory.create()
        {1}_02 = {0}Factory.create()
        {1}_02.{2} = {1}.{2}
        try:
            {1}_02.save()
            self.fail('Test should have raised and integrity error')
        except IntegrityError as e:
            self.assertEqual(str(e), '') #FIXME This test is incomplete
"""


# noinspection PyProtectedMember,PyProtectedMember
class ModelTestCaseGenerator(object):
    def __init__(self, model):
        self.model = model

    def _generate(self):
        model_test_case_content = list()
        model_test_case_content.append({'print': PRINT_TEST_CLASS,
                                        'args': [self.model.__name__,

# Path: django_test_tools/utils.py
# def convert_to_snake_case(camel_case):
#     """
#     Converts a CamelCase name to snake case.
#     ..code-block:: python
# 
#         camel_case = 'OperatingSystemLongName'
#         snake_case = convert_to_snake_case(camel_case)
#         self.assertEqual(snake_case, 'operating_system_long_name')
# 
#     :param camel_case: string. Camel case name
#     :return: string. Snake case name
#     """
#     s1 = first_cap_re.sub(r'\1_\2', camel_case)
#     return all_cap_re.sub(r'\1_\2', s1).lower()


# Path: django_test_tools/generators/model_test_gen.py
from ..utils import convert_to_snake_case

        \"\"\"
        {1} = {0}Factory.create()
"""

PRINT_TEST_ATTRIBUTE_UNIQUE = """
    def test_{2}_is_unique(self):
        \"\"\"
        Tests attribute {2} of model {0} to see if the unique constraint works.
        This test should break if the unique attribute is changed.
        \"\"\"
        {1} = {0}Factory.create()
        {1}_02 = {0}Factory.create()
        {1}_02.{2} = {1}.{2}
        try:
            {1}_02.save()
            self.fail('Test should have raised and integrity error')
        except IntegrityError as e:
            self.assertEqual(str(e), '') #FIXME This test is incomplete
"""


# noinspection PyProtectedMember,PyProtectedMember
class ModelTestCaseGenerator(object):
    def __init__(self, model):
        self.model = model

    def _generate(self):
        model_test_case_content = list()
        model_test_case_content.append({'print': PRINT_TEST_CLASS,
                                        'args': [self.model.__name__,

                                                 convert_to_snake_case(self.model.__name__)]})