# Path: dynamic_rest/utils.py
# def is_truthy(x):
#     if isinstance(x, string_types):
#         return x.lower() not in FALSEY_STRINGS
#     return bool(x)
# 
# def unpack(content):
#     if not content:
#         # empty values pass through
#         return content
# 
#     keys = [k for k in content.keys() if k != 'meta']
#     unpacked = content[keys[0]]
#     return unpacked
# 
# def internal_id_from_model_and_external_id(model, external_id):
#     """
#     Return the internal ID from the external ID and model combination.
# 
#     Because the HashId is a combination of the model's content type and the
#     internal ID, we validate here that the external ID decodes as expected,
#     and that the content type corresponds to the model we're expecting.
#     """
#     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.")
# 
#     try:
#         content_type_id, instance_id = hashids.decode(external_id)
#     except (TypeError, ValueError):
#         raise model.DoesNotExist
# 
#     content_type = ContentType.objects.get_for_id(content_type_id)
# 
#     if content_type.model_class() != model:
#         raise model.DoesNotExist
# 
#     return instance_id
# 
# def model_from_definition(model_definition):
#     """
#     Return a Django model corresponding to model_definition.
# 
#     Model definition can either be a string defining how to import the model,
#     or a model class.
# 
#     Arguments:
#         model_definition: (str|django.db.models.Model)
# 
#     Returns:
#         (django.db.models.Model)
# 
#     Implementation from
#     https://github.com/evenicoulddoit/django-rest-framework-serializer-extensions
#     """
#     if isinstance(model_definition, str):
#         model = import_string(model_definition)
#     else:
#         model = model_definition
# 
#     try:
#         assert issubclass(model, models.Model)
#     except (AssertionError, TypeError):
#         raise AssertionError(
#             '"{0}"" is not a Django model'.format(model_definition))
# 
#     return model
# 
# Path: tests/models.py
# class User(models.Model):
#     name = models.TextField()
#     last_name = models.TextField()
#     groups = models.ManyToManyField('Group', related_name='users')
#     permissions = models.ManyToManyField('Permission', related_name='users')
#     date_of_birth = models.DateField(null=True, blank=True)
#     # 'related_name' intentionally left unset in location field below:
#     location = models.ForeignKey(
#         'Location',
#         null=True,
#         blank=True,
#         on_delete=models.CASCADE
#     )
#     favorite_pet_type = models.ForeignKey(
#         ContentType,
#         null=True,
#         blank=True,
#         on_delete=models.CASCADE
#     )
#     favorite_pet_id = models.TextField(null=True, blank=True)
#     favorite_pet = GenericForeignKey(
#         'favorite_pet_type',
#         'favorite_pet_id',
#     )
#     is_dead = models.BooleanField(null=True, default=False)


from django.test import TestCase, override_settings
from dynamic_rest.utils import (
    is_truthy,
    unpack,
    internal_id_from_model_and_external_id,
    model_from_definition
)
from tests.models import User
        self.assertFalse(is_truthy("0"))
        self.assertFalse(is_truthy("False"))
        self.assertFalse(is_truthy("false"))
        self.assertFalse(is_truthy(""))

    def test_unpack_empty_value(self):
        self.assertIsNone(unpack(None))

    def test_unpack_non_empty_value(self):
        content = {"hello": "world", "meta": "worldpeace", "missed": "a 't'"}
        self.assertIsNotNone(unpack(content))

    def test_unpack_meta_first_key(self):
        content = {"meta": "worldpeace", "missed": "a 't'"}
        self.assertEqual(unpack(content), "a 't'")

    def test_unpack_meta_not_first_key(self):
        content = {"hello": "world", "meta": "worldpeace", "missed": "a 't'"}
        self.assertEqual(unpack(content), "world")

    @override_settings(
        ENABLE_HASHID_FIELDS=True,
        HASHIDS_SALT="If my calculations are correct, "
                     "when this vaby hits 88 miles per hour, "
                     "you're gonna see some serious s***.",
    )
    def test_int_id_from_model_ext_id_obj_does_not_exits(
            self):
        self.assertRaises(
            User.DoesNotExist,

# Path: dynamic_rest/utils.py
# def is_truthy(x):
#     if isinstance(x, string_types):
#         return x.lower() not in FALSEY_STRINGS
#     return bool(x)
# 
# def unpack(content):
#     if not content:
#         # empty values pass through
#         return content
# 
#     keys = [k for k in content.keys() if k != 'meta']
#     unpacked = content[keys[0]]
#     return unpacked
# 
# def internal_id_from_model_and_external_id(model, external_id):
#     """
#     Return the internal ID from the external ID and model combination.
# 
#     Because the HashId is a combination of the model's content type and the
#     internal ID, we validate here that the external ID decodes as expected,
#     and that the content type corresponds to the model we're expecting.
#     """
#     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.")
# 
#     try:
#         content_type_id, instance_id = hashids.decode(external_id)
#     except (TypeError, ValueError):
#         raise model.DoesNotExist
# 
#     content_type = ContentType.objects.get_for_id(content_type_id)
# 
#     if content_type.model_class() != model:
#         raise model.DoesNotExist
# 
#     return instance_id
# 
# def model_from_definition(model_definition):
#     """
#     Return a Django model corresponding to model_definition.
# 
#     Model definition can either be a string defining how to import the model,
#     or a model class.
# 
#     Arguments:
#         model_definition: (str|django.db.models.Model)
# 
#     Returns:
#         (django.db.models.Model)
# 
#     Implementation from
#     https://github.com/evenicoulddoit/django-rest-framework-serializer-extensions
#     """
#     if isinstance(model_definition, str):
#         model = import_string(model_definition)
#     else:
#         model = model_definition
# 
#     try:
#         assert issubclass(model, models.Model)
#     except (AssertionError, TypeError):
#         raise AssertionError(
#             '"{0}"" is not a Django model'.format(model_definition))
# 
#     return model
# 
# Path: tests/models.py
# class User(models.Model):
#     name = models.TextField()
#     last_name = models.TextField()
#     groups = models.ManyToManyField('Group', related_name='users')
#     permissions = models.ManyToManyField('Permission', related_name='users')
#     date_of_birth = models.DateField(null=True, blank=True)
#     # 'related_name' intentionally left unset in location field below:
#     location = models.ForeignKey(
#         'Location',
#         null=True,
#         blank=True,
#         on_delete=models.CASCADE
#     )
#     favorite_pet_type = models.ForeignKey(
#         ContentType,
#         null=True,
#         blank=True,
#         on_delete=models.CASCADE
#     )
#     favorite_pet_id = models.TextField(null=True, blank=True)
#     favorite_pet = GenericForeignKey(
#         'favorite_pet_type',
#         'favorite_pet_id',
#     )
#     is_dead = models.BooleanField(null=True, default=False)


# Path: tests/test_utils.py
from django.test import TestCase, override_settings
from dynamic_rest.utils import (
    is_truthy,
    unpack,
    internal_id_from_model_and_external_id,
    model_from_definition
)
from tests.models import User

        self.assertFalse(is_truthy("0"))
        self.assertFalse(is_truthy("False"))
        self.assertFalse(is_truthy("false"))
        self.assertFalse(is_truthy(""))

    def test_unpack_empty_value(self):
        self.assertIsNone(unpack(None))

    def test_unpack_non_empty_value(self):
        content = {"hello": "world", "meta": "worldpeace", "missed": "a 't'"}
        self.assertIsNotNone(unpack(content))

    def test_unpack_meta_first_key(self):
        content = {"meta": "worldpeace", "missed": "a 't'"}
        self.assertEqual(unpack(content), "a 't'")

    def test_unpack_meta_not_first_key(self):
        content = {"hello": "world", "meta": "worldpeace", "missed": "a 't'"}
        self.assertEqual(unpack(content), "world")

    @override_settings(
        ENABLE_HASHID_FIELDS=True,
        HASHIDS_SALT="If my calculations are correct, "
                     "when this vaby hits 88 miles per hour, "
                     "you're gonna see some serious s***.",
    )
    def test_int_id_from_model_ext_id_obj_does_not_exits(
            self):
        self.assertRaises(
            User.DoesNotExist,

            internal_id_from_model_and_external_id,