# 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
        self.assertTrue(s.is_valid())
        r512 = s.save()
        self.assertEqual(r512.id, 1024)
        self.assertEqual(r512.name, "Test Record 1024")
        self.assertEqual(r512.artist, artist)

    def test_invalid_source_field_strings(self):
        with self.assertRaises(ValueError):
            id = HashidSerializerIntegerField(source_field="tests")
        with self.assertRaises(ValueError):
            id = HashidSerializerIntegerField(source_field="tests.Artist")
        with self.assertRaises(ValueError):
            id = HashidSerializerIntegerField(source_field="Artist.id")
        with self.assertRaises(LookupError):
            id = HashidSerializerIntegerField(source_field="foo.Bar.baz")
        with self.assertRaises(LookupError):
            id = HashidSerializerIntegerField(source_field="tests.Bar.baz")
        with self.assertRaises(exceptions.FieldDoesNotExist):
            id = HashidSerializerIntegerField(source_field="tests.Artist.baz")

    def test_modelserializer_with_prefix(self):
        class TrackSerializer(serializers.ModelSerializer):
            id = HashidSerializerCharField(source_field="tests.Track.id")

            class Meta:
                model = Track
                fields = ("id",)

        salt = Track._meta.get_field("id").salt
        alphabet = Track._meta.get_field("id").alphabet

# 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

        self.assertTrue(s.is_valid())
        r512 = s.save()
        self.assertEqual(r512.id, 1024)
        self.assertEqual(r512.name, "Test Record 1024")
        self.assertEqual(r512.artist, artist)

    def test_invalid_source_field_strings(self):
        with self.assertRaises(ValueError):
            id = HashidSerializerIntegerField(source_field="tests")
        with self.assertRaises(ValueError):
            id = HashidSerializerIntegerField(source_field="tests.Artist")
        with self.assertRaises(ValueError):
            id = HashidSerializerIntegerField(source_field="Artist.id")
        with self.assertRaises(LookupError):
            id = HashidSerializerIntegerField(source_field="foo.Bar.baz")
        with self.assertRaises(LookupError):
            id = HashidSerializerIntegerField(source_field="tests.Bar.baz")
        with self.assertRaises(exceptions.FieldDoesNotExist):
            id = HashidSerializerIntegerField(source_field="tests.Artist.baz")

    def test_modelserializer_with_prefix(self):
        class TrackSerializer(serializers.ModelSerializer):
            id = HashidSerializerCharField(source_field="tests.Track.id")

            class Meta:
                model = Track
                fields = ("id",)

        salt = Track._meta.get_field("id").salt
        alphabet = Track._meta.get_field("id").alphabet

        min_length = Track._meta.get_field("id").min_length