# Path: dynamic_rest/meta.py
# def get_model_table(model):
#     try:
#         return model._meta.db_table
#     except BaseException:
#         return None
# 
# Path: dynamic_rest/routers.py
#     def replace_methodname(format_string, methodname):
# def get_directory(request):
#     def get_url(url):
#     def is_active_url(path, url):
#     def sort_key(r):
# def modify_list_route(routes):
#     def __init__(self, *args, **kwargs):
#     def get_api_root_view(self, **kwargs):
#             def get(self, request, *args, **kwargs):
#     def register(self, prefix, viewset, base_name=None):
#     def register_resource(self, viewset, namespace=None):
#     def get_canonical_path(resource_key, pk=None):
#     def get_canonical_serializer(
#         resource_key,
#         model=None,
#         instance=None,
#         resource_name=None
#     ):
#     def get_routes(self, viewset):
#     def get_relation_routes(self, viewset):
# class DynamicRouter(DefaultRouter):
#         class API(views.APIView):
# 
# Path: tests/models.py
# class Dog(models.Model):
#     name = models.TextField()
#     fur_color = models.TextField()
#     origin = models.TextField()
# 
# Path: tests/serializers.py
# class CatSerializer(DynamicModelSerializer):
#     home = DynamicRelationField('LocationSerializer', link=None)
#     backup_home = DynamicRelationField(
#         'LocationSerializer', link=backup_home_link)
#     foobar = DynamicRelationField(
#         'LocationSerializer', source='hunting_grounds', many=True)
#     parent = DynamicRelationField('CatSerializer', immutable=True)
# 
#     class Meta:
#         model = Cat
#         name = 'cat'
#         fields = ('id', 'name', 'home', 'backup_home', 'foobar', 'parent')
#         deferred_fields = ('home', 'backup_home', 'foobar', 'parent')
#         immutable_fields = ('name',)
#         untrimmed_fields = ('name',)
# 
# class DogSerializer(DynamicModelSerializer):
# 
#     class Meta:
#         model = Dog
#         fields = ('id', 'name', 'origin', 'fur', 'is_red')
# 
#     fur = CharField(source='fur_color')
#     is_red = DynamicMethodField(deferred=True, requires=['fur_color'])
# 
#     def get_is_red(self, instance):
#         return instance.fur_color == 'red'
# 
# Path: tests/urls.py



from django.urls import set_script_prefix, clear_script_prefix
from rest_framework.test import APITestCase
from rest_framework.routers import DefaultRouter
from dynamic_rest.meta import get_model_table
from dynamic_rest.routers import DynamicRouter, Route
from tests.models import Dog
from tests.serializers import CatSerializer, DogSerializer
from tests.urls import urlpatterns  # noqa  force route registration




class TestDynamicRouter(APITestCase):

    def test_get_canonical_path(self):
        rsrc_key = DogSerializer().get_resource_key()
        self.assertEqual(
            '/dogs',
            DynamicRouter.get_canonical_path(rsrc_key)
        )

    def test_get_canonical_path_with_prefix(self):
        set_script_prefix('/v2/')
        rsrc_key = DogSerializer().get_resource_key()
        self.assertEqual(
            '/v2/dogs',
            DynamicRouter.get_canonical_path(rsrc_key)
        )
        clear_script_prefix()

    def test_get_canonical_path_with_pk(self):
        rsrc_key = DogSerializer().get_resource_key()
        self.assertEqual(
            '/dogs/1/',
            DynamicRouter.get_canonical_path(rsrc_key, pk='1')
        )

    def test_get_canonical_path_with_keyspace(self):

# Path: dynamic_rest/meta.py
# def get_model_table(model):
#     try:
#         return model._meta.db_table
#     except BaseException:
#         return None
# 
# Path: dynamic_rest/routers.py
#     def replace_methodname(format_string, methodname):
# def get_directory(request):
#     def get_url(url):
#     def is_active_url(path, url):
#     def sort_key(r):
# def modify_list_route(routes):
#     def __init__(self, *args, **kwargs):
#     def get_api_root_view(self, **kwargs):
#             def get(self, request, *args, **kwargs):
#     def register(self, prefix, viewset, base_name=None):
#     def register_resource(self, viewset, namespace=None):
#     def get_canonical_path(resource_key, pk=None):
#     def get_canonical_serializer(
#         resource_key,
#         model=None,
#         instance=None,
#         resource_name=None
#     ):
#     def get_routes(self, viewset):
#     def get_relation_routes(self, viewset):
# class DynamicRouter(DefaultRouter):
#         class API(views.APIView):
# 
# Path: tests/models.py
# class Dog(models.Model):
#     name = models.TextField()
#     fur_color = models.TextField()
#     origin = models.TextField()
# 
# Path: tests/serializers.py
# class CatSerializer(DynamicModelSerializer):
#     home = DynamicRelationField('LocationSerializer', link=None)
#     backup_home = DynamicRelationField(
#         'LocationSerializer', link=backup_home_link)
#     foobar = DynamicRelationField(
#         'LocationSerializer', source='hunting_grounds', many=True)
#     parent = DynamicRelationField('CatSerializer', immutable=True)
# 
#     class Meta:
#         model = Cat
#         name = 'cat'
#         fields = ('id', 'name', 'home', 'backup_home', 'foobar', 'parent')
#         deferred_fields = ('home', 'backup_home', 'foobar', 'parent')
#         immutable_fields = ('name',)
#         untrimmed_fields = ('name',)
# 
# class DogSerializer(DynamicModelSerializer):
# 
#     class Meta:
#         model = Dog
#         fields = ('id', 'name', 'origin', 'fur', 'is_red')
# 
#     fur = CharField(source='fur_color')
#     is_red = DynamicMethodField(deferred=True, requires=['fur_color'])
# 
#     def get_is_red(self, instance):
#         return instance.fur_color == 'red'
# 
# Path: tests/urls.py



# Path: tests/test_router.py
from django.urls import set_script_prefix, clear_script_prefix
from rest_framework.test import APITestCase
from rest_framework.routers import DefaultRouter
from dynamic_rest.meta import get_model_table
from dynamic_rest.routers import DynamicRouter, Route
from tests.models import Dog
from tests.serializers import CatSerializer, DogSerializer
from tests.urls import urlpatterns  # noqa  force route registration





class TestDynamicRouter(APITestCase):

    def test_get_canonical_path(self):
        rsrc_key = DogSerializer().get_resource_key()
        self.assertEqual(
            '/dogs',
            DynamicRouter.get_canonical_path(rsrc_key)
        )

    def test_get_canonical_path_with_prefix(self):
        set_script_prefix('/v2/')
        rsrc_key = DogSerializer().get_resource_key()
        self.assertEqual(
            '/v2/dogs',
            DynamicRouter.get_canonical_path(rsrc_key)
        )
        clear_script_prefix()

    def test_get_canonical_path_with_pk(self):
        rsrc_key = DogSerializer().get_resource_key()
        self.assertEqual(
            '/dogs/1/',
            DynamicRouter.get_canonical_path(rsrc_key, pk='1')
        )

    def test_get_canonical_path_with_keyspace(self):

        rsrc_key = CatSerializer().get_resource_key()