# Path: tests/testapp/models.py
# class BigCharSetModel(Model):
#     field = SetTextField(base_field=CharField(max_length=8), max_length=32)
# 
# class BigIntSetModel(Model):
#     field = SetTextField(base_field=IntegerField())


import json
import pytest
from django import forms
from django.core import exceptions, serializers
from django.db import models
from django.db.migrations.writer import MigrationWriter
from django.db.models import Q
from django.test import SimpleTestCase, TestCase
from django.test.utils import isolate_apps
from django_mysql.forms import SimpleSetField
from django_mysql.models import SetTextField
from tests.testapp.models import BigCharSetModel, BigIntSetModel
        from django_mysql.models.fields import SetTextField as STField
        from django_mysql.models.fields.sets import SetTextField as STField
        with pytest.raises(exceptions.ValidationError) as excinfo:
            field.clean({"a", "b", "c", "d"}, None)
        assert (
            excinfo.value.messages[0]
            == "Set contains 4 items, it should contain no more than 3."
        )


@isolate_apps("tests.testapp")
class TestCheck(SimpleTestCase):
    def test_model_set(self):
        field = BigIntSetModel._meta.get_field("field")
        assert field.model == BigIntSetModel
        # I think this is a side effect of migrations being run in tests -
        # the base_field.model is the __fake__ model
        assert field.base_field.model.__name__ == "BigIntSetModel"

    def test_base_field_checks(self):
        class Invalid(models.Model):
            field = SetTextField(models.CharField())

        errors = Invalid.check()
        assert len(errors) == 1
        assert errors[0].id == "django_mysql.E001"
        assert "Base field for set has errors" in errors[0].msg
        assert "max_length" in errors[0].msg

    def test_invalid_base_fields(self):
        class Invalid(models.Model):
            field = SetTextField(

# Path: tests/testapp/models.py
# class BigCharSetModel(Model):
#     field = SetTextField(base_field=CharField(max_length=8), max_length=32)
# 
# class BigIntSetModel(Model):
#     field = SetTextField(base_field=IntegerField())


# Path: tests/testapp/test_settextfield.py
import json
import pytest
from django import forms
from django.core import exceptions, serializers
from django.db import models
from django.db.migrations.writer import MigrationWriter
from django.db.models import Q
from django.test import SimpleTestCase, TestCase
from django.test.utils import isolate_apps
from django_mysql.forms import SimpleSetField
from django_mysql.models import SetTextField
from tests.testapp.models import BigCharSetModel, BigIntSetModel
        from django_mysql.models.fields import SetTextField as STField
        from django_mysql.models.fields.sets import SetTextField as STField

        with pytest.raises(exceptions.ValidationError) as excinfo:
            field.clean({"a", "b", "c", "d"}, None)
        assert (
            excinfo.value.messages[0]
            == "Set contains 4 items, it should contain no more than 3."
        )


@isolate_apps("tests.testapp")
class TestCheck(SimpleTestCase):
    def test_model_set(self):
        field = BigIntSetModel._meta.get_field("field")
        assert field.model == BigIntSetModel
        # I think this is a side effect of migrations being run in tests -
        # the base_field.model is the __fake__ model
        assert field.base_field.model.__name__ == "BigIntSetModel"

    def test_base_field_checks(self):
        class Invalid(models.Model):
            field = SetTextField(models.CharField())

        errors = Invalid.check()
        assert len(errors) == 1
        assert errors[0].id == "django_mysql.E001"
        assert "Base field for set has errors" in errors[0].msg
        assert "max_length" in errors[0].msg

    def test_invalid_base_fields(self):
        class Invalid(models.Model):
            field = SetTextField(

                models.ForeignKey("testapp.Author", on_delete=models.CASCADE)