# Path: tests/testapp/models.py
# class FixedCharModel(Model):
#     zip_code = FixedCharField(max_length=10)


import pytest
from django.core.management import call_command
from django.db import connection, models
from django.db.utils import DataError
from django.test import SimpleTestCase, TestCase, TransactionTestCase, override_settings
from django.test.utils import isolate_apps
from django_mysql.models import FixedCharField
from tests.testapp.models import FixedCharModel
from __future__ import annotations




class TestSaveLoad(TestCase):
    def test_success_exact(self):
        instance = FixedCharModel.objects.create(zip_code="0" * 10)
        assert instance.zip_code == "0" * 10
        instance = FixedCharModel.objects.get(id=instance.id)
        assert instance.zip_code == "0" * 10

    def test_success_shorter(self):
        FixedCharModel.objects.create(zip_code="0" * 9)
        m = FixedCharModel.objects.get()
        assert m.zip_code == "0" * 9

    def test_invalid_too_long(self):
        with pytest.raises(DataError) as excinfo:

# Path: tests/testapp/models.py
# class FixedCharModel(Model):
#     zip_code = FixedCharField(max_length=10)


# Path: tests/testapp/test_fixedcharfield.py
import pytest
from django.core.management import call_command
from django.db import connection, models
from django.db.utils import DataError
from django.test import SimpleTestCase, TestCase, TransactionTestCase, override_settings
from django.test.utils import isolate_apps
from django_mysql.models import FixedCharField
from tests.testapp.models import FixedCharModel

from __future__ import annotations




class TestSaveLoad(TestCase):
    def test_success_exact(self):
        instance = FixedCharModel.objects.create(zip_code="0" * 10)
        assert instance.zip_code == "0" * 10
        instance = FixedCharModel.objects.get(id=instance.id)
        assert instance.zip_code == "0" * 10

    def test_success_shorter(self):
        FixedCharModel.objects.create(zip_code="0" * 9)
        m = FixedCharModel.objects.get()
        assert m.zip_code == "0" * 9

    def test_invalid_too_long(self):
        with pytest.raises(DataError) as excinfo:

            FixedCharModel.objects.create(zip_code="0" * 11)