# Path: django_test_tools/generators/crud_generator.py
# class SerializerTestGenerator(object):
# 
#     def __init__(self):
#         self.env = Environment(
#             loader=PackageLoader('django_test_tools', 'templates'),
#             autoescape=select_autoescape(['html', 'j2'])
#         )
#         self.env.filters['to_snake_case'] = to_snake_case
# 
#         self.template_name = 'django_test_tools/test_serializers.py.j2'
#         self.template = self.env.get_template(self.template_name)
# 
#     def print(self, serializer_info, filename):
#         rendered = self.template.render(serializer_info)
#         with open(filename, 'w', encoding='utf-8') as file:
#             file.write(rendered)


import importlib
from django.core.management import BaseCommand
from ...generators.crud_generator import SerializerTestGenerator




class Command(BaseCommand):
    """

        $ python manage.py generate_serializers_test my_application.app.api.serializers.MyObjectSerializer -f output/m.py
    """

    def add_arguments(self, parser):
        parser.add_argument('serializer_class')

        parser.add_argument("-f", "--filename",
                            dest="filename",
                            help="Output filename",
                            )

    def handle(self, *args, **options):
        parts = options.get('serializer_class').split('.')
        serializer_class_name = parts[-1]
        module_name = '.'.join(parts[0:-1])
        filename = options.get('filename')

# Path: django_test_tools/generators/crud_generator.py
# class SerializerTestGenerator(object):
# 
#     def __init__(self):
#         self.env = Environment(
#             loader=PackageLoader('django_test_tools', 'templates'),
#             autoescape=select_autoescape(['html', 'j2'])
#         )
#         self.env.filters['to_snake_case'] = to_snake_case
# 
#         self.template_name = 'django_test_tools/test_serializers.py.j2'
#         self.template = self.env.get_template(self.template_name)
# 
#     def print(self, serializer_info, filename):
#         rendered = self.template.render(serializer_info)
#         with open(filename, 'w', encoding='utf-8') as file:
#             file.write(rendered)


# Path: django_test_tools/management/commands/generate_serializers_tests.py
import importlib
from django.core.management import BaseCommand
from ...generators.crud_generator import SerializerTestGenerator





class Command(BaseCommand):
    """

        $ python manage.py generate_serializers_test my_application.app.api.serializers.MyObjectSerializer -f output/m.py
    """

    def add_arguments(self, parser):
        parser.add_argument('serializer_class')

        parser.add_argument("-f", "--filename",
                            dest="filename",
                            help="Output filename",
                            )

    def handle(self, *args, **options):
        parts = options.get('serializer_class').split('.')
        serializer_class_name = parts[-1]
        module_name = '.'.join(parts[0:-1])
        filename = options.get('filename')

        generator = SerializerTestGenerator()