# Path: dynamic_rest/utils.py
# def external_id_from_model_and_internal_id(model, internal_id):
#     """
#     Return a hash for the model and internal ID combination.
#     """
#     hashids = Hashids(salt=settings.HASHIDS_SALT)
# 
#     if hashids is None:
#         raise AssertionError(
#             "To use hashids features you must set "
#             "ENABLE_HASHID_FIELDS to true "
#             "and provide a HASHIDS_SALT in your dynamic_rest settings.")
#     return hashids.encode(
#         ContentType.objects.get_for_model(model).id, internal_id)
# 
# Path: tests/models.py
# class Dog(models.Model):
#     name = models.TextField()
#     fur_color = models.TextField()
#     origin = models.TextField()


from django.test import TestCase, override_settings
from rest_framework import serializers
from dynamic_rest.fields import DynamicHashIdField
from dynamic_rest.utils import (
    external_id_from_model_and_internal_id,
)
from tests.models import Dog




@override_settings(
    ENABLE_HASHID_FIELDS=True,
    HASHIDS_SALT="I guess you guys aren’t ready for that yet, "
                 "but your kids are gonna love it.",
)
class FieldsTestCase(TestCase):
    def test_dynamic_hash_id_field_with_model_parameter(self):
        class DogModelTestSerializer(serializers.ModelSerializer):
            """
            A custom model serializer simply for testing purposes.
            """

            id = DynamicHashIdField(model=Dog)

            class Meta:
                model = Dog
                fields = ["id", "name", "fur_color", "origin"]

        dog = Dog.objects.create(
            name="Kazan",
            fur_color="brown",
            origin="Abuelos")
        serializer = DogModelTestSerializer(dog)

        self.assertEqual(
            serializer.data["id"],

# Path: dynamic_rest/utils.py
# def external_id_from_model_and_internal_id(model, internal_id):
#     """
#     Return a hash for the model and internal ID combination.
#     """
#     hashids = Hashids(salt=settings.HASHIDS_SALT)
# 
#     if hashids is None:
#         raise AssertionError(
#             "To use hashids features you must set "
#             "ENABLE_HASHID_FIELDS to true "
#             "and provide a HASHIDS_SALT in your dynamic_rest settings.")
#     return hashids.encode(
#         ContentType.objects.get_for_model(model).id, internal_id)
# 
# Path: tests/models.py
# class Dog(models.Model):
#     name = models.TextField()
#     fur_color = models.TextField()
#     origin = models.TextField()


# Path: tests/test_fields.py
from django.test import TestCase, override_settings
from rest_framework import serializers
from dynamic_rest.fields import DynamicHashIdField
from dynamic_rest.utils import (
    external_id_from_model_and_internal_id,
)
from tests.models import Dog





@override_settings(
    ENABLE_HASHID_FIELDS=True,
    HASHIDS_SALT="I guess you guys aren’t ready for that yet, "
                 "but your kids are gonna love it.",
)
class FieldsTestCase(TestCase):
    def test_dynamic_hash_id_field_with_model_parameter(self):
        class DogModelTestSerializer(serializers.ModelSerializer):
            """
            A custom model serializer simply for testing purposes.
            """

            id = DynamicHashIdField(model=Dog)

            class Meta:
                model = Dog
                fields = ["id", "name", "fur_color", "origin"]

        dog = Dog.objects.create(
            name="Kazan",
            fur_color="brown",
            origin="Abuelos")
        serializer = DogModelTestSerializer(dog)

        self.assertEqual(
            serializer.data["id"],

            external_id_from_model_and_internal_id(