# Path: tests/models.py
# class Artist(models.Model):
#     id = HashidAutoField(primary_key=True, alphabet="1234567890abcdef")
#     name = models.CharField(max_length=40)
# 
#     def __str__(self):
#         return "{} ({})".format(self.name, self.id)
# 
# class Record(models.Model):
#     id = BigHashidAutoField(primary_key=True)
#     name = models.CharField(max_length=40)
#     artist = models.ForeignKey(Artist, on_delete=models.CASCADE, null=True, blank=True, related_name="records")
#     reference_id = HashidField()
#     prefixed_id = HashidField(null=True, blank=True, prefix="prefix_")
#     string_id = HashidField(null=True, blank=True, enable_hashid_object=False)
#     plain_hashid = HashidField(null=True, blank=True, enable_descriptor=False)
#     plain_id = HashidField(null=True, blank=True, enable_descriptor=False, enable_hashid_object=False)
#     alternate_id = HashidField(salt="a different salt", null=True, blank=True)
#     key = BigHashidField(min_length=10, alphabet="abcdlmnotuvwxyz123789", null=True, blank=True)
# 
#     def __str__(self):
#         return "{} ({})".format(self.name, self.reference_id)
# 
# class Track(models.Model):
#     id = BigHashidAutoField(primary_key=True, allow_int_lookup=True, min_length=10, prefix='albumtrack:', salt="abcd", alphabet="abcdefghijklmnop")


from unittest import skipUnless
from django.core import exceptions
from django.test import TestCase
from rest_framework.exceptions import ErrorDetail
from tests.models import Artist, Record, Track
    from rest_framework import serializers
    from rest_framework.renderers import JSONRenderer
    from hashid_field.rest import UnconfiguredHashidSerialField, HashidSerializerCharField, HashidSerializerIntegerField
import hashids
@skipUnless(have_drf, "Requires Django REST Framework to be installed")
class TestRestFramework(TestCase):
    def assertSerializerError(self, serializer, field, code):
        serializer_name = serializer.__class__.__name__
        self.assertFalse(serializer.is_valid(),
                         msg="The serializer {} does not contain any errors".format(serializer_name))

        def assertCodeInErrors(errors):
            found_error = False
            for error_detail in errors:
                if error_detail.code == code:
                    found_error = True
            self.assertTrue(found_error,
                            msg="The field '{} in serializer '{}' does not contain the error code {}".format(
                                field, serializer_name, code))

        if field:
            if field in serializer.errors:
                assertCodeInErrors(serializer.errors[field])
            else:
                self.fail("The field '{}' in serializer '{}' contains no errors".format(field, serializer_name))
        else:
            if 'non_field_errors' in serializer.errors:
                assertCodeInErrors(serializer.errors['non_field_errors'])
            else:
                self.fail("The serializer '{}' does not contain the non-field error {}".format(serializer_name, code))

    def test_default_modelserializer_field(self):
        class ArtistSerializer(serializers.ModelSerializer):
            class Meta:

# Path: tests/models.py
# class Artist(models.Model):
#     id = HashidAutoField(primary_key=True, alphabet="1234567890abcdef")
#     name = models.CharField(max_length=40)
# 
#     def __str__(self):
#         return "{} ({})".format(self.name, self.id)
# 
# class Record(models.Model):
#     id = BigHashidAutoField(primary_key=True)
#     name = models.CharField(max_length=40)
#     artist = models.ForeignKey(Artist, on_delete=models.CASCADE, null=True, blank=True, related_name="records")
#     reference_id = HashidField()
#     prefixed_id = HashidField(null=True, blank=True, prefix="prefix_")
#     string_id = HashidField(null=True, blank=True, enable_hashid_object=False)
#     plain_hashid = HashidField(null=True, blank=True, enable_descriptor=False)
#     plain_id = HashidField(null=True, blank=True, enable_descriptor=False, enable_hashid_object=False)
#     alternate_id = HashidField(salt="a different salt", null=True, blank=True)
#     key = BigHashidField(min_length=10, alphabet="abcdlmnotuvwxyz123789", null=True, blank=True)
# 
#     def __str__(self):
#         return "{} ({})".format(self.name, self.reference_id)
# 
# class Track(models.Model):
#     id = BigHashidAutoField(primary_key=True, allow_int_lookup=True, min_length=10, prefix='albumtrack:', salt="abcd", alphabet="abcdefghijklmnop")


# Path: tests/test_rest_framework.py
from unittest import skipUnless
from django.core import exceptions
from django.test import TestCase
from rest_framework.exceptions import ErrorDetail
from tests.models import Artist, Record, Track
    from rest_framework import serializers
    from rest_framework.renderers import JSONRenderer
    from hashid_field.rest import UnconfiguredHashidSerialField, HashidSerializerCharField, HashidSerializerIntegerField
import hashids

@skipUnless(have_drf, "Requires Django REST Framework to be installed")
class TestRestFramework(TestCase):
    def assertSerializerError(self, serializer, field, code):
        serializer_name = serializer.__class__.__name__
        self.assertFalse(serializer.is_valid(),
                         msg="The serializer {} does not contain any errors".format(serializer_name))

        def assertCodeInErrors(errors):
            found_error = False
            for error_detail in errors:
                if error_detail.code == code:
                    found_error = True
            self.assertTrue(found_error,
                            msg="The field '{} in serializer '{}' does not contain the error code {}".format(
                                field, serializer_name, code))

        if field:
            if field in serializer.errors:
                assertCodeInErrors(serializer.errors[field])
            else:
                self.fail("The field '{}' in serializer '{}' contains no errors".format(field, serializer_name))
        else:
            if 'non_field_errors' in serializer.errors:
                assertCodeInErrors(serializer.errors['non_field_errors'])
            else:
                self.fail("The serializer '{}' does not contain the non-field error {}".format(serializer_name, code))

    def test_default_modelserializer_field(self):
        class ArtistSerializer(serializers.ModelSerializer):
            class Meta:

                model = Artist