# 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

    def test_char_string_direct(self):
        big_set = {str(i**2) for i in range(1000)}
        big_str = ",".join(big_set)
        s = BigCharSetModel.objects.create(field=big_str)
        s = BigCharSetModel.objects.get(id=s.id)
        assert s.field == big_set

    def test_is_a_set_immediately(self):
        s = BigCharSetModel()
        assert s.field == set()
        s.field.add("bold")
        s.field.add("brave")
        s.save()
        assert s.field == {"bold", "brave"}
        s = BigCharSetModel.objects.get(id=s.id)
        assert s.field == {"bold", "brave"}

    def test_empty(self):
        s = BigCharSetModel.objects.create()
        assert s.field == set()
        s = BigCharSetModel.objects.get(id=s.id)
        assert s.field == set()

    def test_char_cant_create_sets_with_commas(self):
        with pytest.raises(ValueError):
            BigCharSetModel.objects.create(field={"co,mma", "contained"})

    def test_char_cant_create_sets_with_empty_string(self):
        with pytest.raises(ValueError):

# 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


    def test_char_string_direct(self):
        big_set = {str(i**2) for i in range(1000)}
        big_str = ",".join(big_set)
        s = BigCharSetModel.objects.create(field=big_str)
        s = BigCharSetModel.objects.get(id=s.id)
        assert s.field == big_set

    def test_is_a_set_immediately(self):
        s = BigCharSetModel()
        assert s.field == set()
        s.field.add("bold")
        s.field.add("brave")
        s.save()
        assert s.field == {"bold", "brave"}
        s = BigCharSetModel.objects.get(id=s.id)
        assert s.field == {"bold", "brave"}

    def test_empty(self):
        s = BigCharSetModel.objects.create()
        assert s.field == set()
        s = BigCharSetModel.objects.get(id=s.id)
        assert s.field == set()

    def test_char_cant_create_sets_with_commas(self):
        with pytest.raises(ValueError):
            BigCharSetModel.objects.create(field={"co,mma", "contained"})

    def test_char_cant_create_sets_with_empty_string(self):
        with pytest.raises(ValueError):

            BigCharSetModel.objects.create(field={""})