# Path: rest_framework_extensions/routers.py
# class ExtendedSimpleRouter(ExtendedRouterMixin, SimpleRouter):
#     pass
# 
# Path: rest_framework_extensions/utils.py
# def compose_parent_pk_kwarg_name(value):
#     return '{0}{1}'.format(
#         extensions_api_settings.DEFAULT_PARENT_LOOKUP_KWARG_NAME_PREFIX,
#         value
#     )
# 
# Path: tests_app/tests/unit/routers/nested_router_mixin/views.py
# class UserViewSet(ModelViewSet):
#     model = UserModel
# 
# class GroupViewSet(ModelViewSet):
#     model = GroupModel
# 
# class PermissionViewSet(ModelViewSet):
#     model = PermissionModel
# 
# class CustomRegexUserViewSet(ModelViewSet):
#     lookup_value_regex = 'a'
#     model = UserModel
# 
# class CustomRegexGroupViewSet(ModelViewSet):
#     lookup_value_regex = 'b'
#     model = GroupModel
# 
# class CustomRegexPermissionViewSet(ModelViewSet):
#     lookup_value_regex = 'c'
#     model = PermissionModel


from rest_framework.test import APITestCase
from rest_framework_extensions.routers import ExtendedSimpleRouter
from rest_framework_extensions.utils import compose_parent_pk_kwarg_name
from .views import (
    UserViewSet,
    GroupViewSet,
    PermissionViewSet,
    CustomRegexUserViewSet,
    CustomRegexGroupViewSet,
    CustomRegexPermissionViewSet,
)


def get_regex_pattern(urlpattern):
    return urlpattern.pattern.regex.pattern


class NestedRouterMixinTest(APITestCase):
    def get_lookup_regex(self, value):
        return '(?P<{0}>[^/.]+)'.format(value)

    def get_parent_lookup_regex(self, value):
        return '(?P<{0}>[^/.]+)'.format(compose_parent_pk_kwarg_name(value))

    def get_custom_regex_lookup(self, pk_kwarg_name, lookup_value_regex):
        """ Build lookup regex with custom regular expression. """
        return '(?P<{pk_kwarg_name}>{lookup_value_regex})'.format(
            pk_kwarg_name=pk_kwarg_name,
            lookup_value_regex=lookup_value_regex
        )

    def get_custom_regex_parent_lookup(self, parent_pk_kwarg_name,
                                       parent_lookup_value_regex):
        """ Build parent lookup regex with custom regular expression. """
        return self.get_custom_regex_lookup(

# Path: rest_framework_extensions/routers.py
# class ExtendedSimpleRouter(ExtendedRouterMixin, SimpleRouter):
#     pass
# 
# Path: rest_framework_extensions/utils.py
# def compose_parent_pk_kwarg_name(value):
#     return '{0}{1}'.format(
#         extensions_api_settings.DEFAULT_PARENT_LOOKUP_KWARG_NAME_PREFIX,
#         value
#     )
# 
# Path: tests_app/tests/unit/routers/nested_router_mixin/views.py
# class UserViewSet(ModelViewSet):
#     model = UserModel
# 
# class GroupViewSet(ModelViewSet):
#     model = GroupModel
# 
# class PermissionViewSet(ModelViewSet):
#     model = PermissionModel
# 
# class CustomRegexUserViewSet(ModelViewSet):
#     lookup_value_regex = 'a'
#     model = UserModel
# 
# class CustomRegexGroupViewSet(ModelViewSet):
#     lookup_value_regex = 'b'
#     model = GroupModel
# 
# class CustomRegexPermissionViewSet(ModelViewSet):
#     lookup_value_regex = 'c'
#     model = PermissionModel


# Path: tests_app/tests/unit/routers/nested_router_mixin/tests.py
from rest_framework.test import APITestCase
from rest_framework_extensions.routers import ExtendedSimpleRouter
from rest_framework_extensions.utils import compose_parent_pk_kwarg_name
from .views import (
    UserViewSet,
    GroupViewSet,
    PermissionViewSet,
    CustomRegexUserViewSet,
    CustomRegexGroupViewSet,
    CustomRegexPermissionViewSet,
)



def get_regex_pattern(urlpattern):
    return urlpattern.pattern.regex.pattern


class NestedRouterMixinTest(APITestCase):
    def get_lookup_regex(self, value):
        return '(?P<{0}>[^/.]+)'.format(value)

    def get_parent_lookup_regex(self, value):
        return '(?P<{0}>[^/.]+)'.format(compose_parent_pk_kwarg_name(value))

    def get_custom_regex_lookup(self, pk_kwarg_name, lookup_value_regex):
        """ Build lookup regex with custom regular expression. """
        return '(?P<{pk_kwarg_name}>{lookup_value_regex})'.format(
            pk_kwarg_name=pk_kwarg_name,
            lookup_value_regex=lookup_value_regex
        )

    def get_custom_regex_parent_lookup(self, parent_pk_kwarg_name,
                                       parent_lookup_value_regex):
        """ Build parent lookup regex with custom regular expression. """
        return self.get_custom_regex_lookup(

            compose_parent_pk_kwarg_name(parent_pk_kwarg_name),