# Path: tests/compat.py
# def wrap_testdata(func):
#     return func
# 
# Path: tests/testapp/models.py
# class DynamicModel(Model):
#     attrs = DynamicField(
#         spec={
#             "datetimey": dt.datetime,
#             "datey": dt.date,
#             "floaty": float,
#             "inty": int,
#             "stry": str,
#             "timey": dt.time,
#             "nesty": {"level2": str},
#         }
#     )
# 
#     @classmethod
#     def check(cls, **kwargs):
#         # Disable the checks on MySQL so that checks tests don't fail
#         if not (connection_is_mariadb(connection)):
#             return []
#         return super().check(**kwargs)
# 
#     def __str__(self):  # pragma: no cover
#         return ",".join(f"{key}:{value}" for key, value in self.attrs.items())
# 
# class SpeclessDynamicModel(Model):
#     attrs = DynamicField()
# 
#     @classmethod
#     def check(cls, **kwargs):
#         # Disable the checks on MySQL so that checks tests don't fail
#         if not (connection_is_mariadb(connection)):
#             return []
#         return super().check(**kwargs)
# 
#     def __str__(self):  # pragma: no cover
#         return ",".join(f"{key}:{value}" for key, value in self.attrs.items())


import datetime as dt
import json
import mariadb_dyncol
import pytest
from unittest import SkipTest, mock
from django.core import serializers
from django.core.exceptions import FieldError
from django.db import connection, models
from django.db.migrations.writer import MigrationWriter
from django.db.models import CharField, Transform
from django.test import TestCase
from django.test.utils import isolate_apps
from django_mysql.models import DynamicField
from django_mysql.utils import connection_is_mariadb
from tests.compat import wrap_testdata
from tests.testapp.models import DynamicModel, SpeclessDynamicModel
        from django_mysql.models.fields import DynamicField as DField
        from django_mysql.models.fields.dynamic import DynamicField as DField

    def test_key_transform_timey_TIME(self):
        assert list(
            DynamicModel.objects.filter(attrs__timey_TIME=dt.time(14, 15, 16))
        ) == [self.objs[4]]

    def test_key_transform_nesty__level2(self):
        assert list(DynamicModel.objects.filter(attrs__nesty__level2="chirp")) == [
            self.objs[4]
        ]

    def test_key_transform_nesty__level2__startswith(self):
        assert list(
            DynamicModel.objects.filter(attrs__nesty__level2__startswith="chi")
        ) == [self.objs[4]]


class SpeclessQueryTests(DynColTestCase):
    @classmethod
    @wrap_testdata
    def setUpTestData(cls):
        super().setUpTestData()
        objs = [
            SpeclessDynamicModel(attrs={"a": "b"}),
            SpeclessDynamicModel(attrs={"a": "c"}),
        ]
        SpeclessDynamicModel.objects.bulk_create(objs)
        cls.objs = list(SpeclessDynamicModel.objects.order_by("id"))

    def test_simple(self):

# Path: tests/compat.py
# def wrap_testdata(func):
#     return func
# 
# Path: tests/testapp/models.py
# class DynamicModel(Model):
#     attrs = DynamicField(
#         spec={
#             "datetimey": dt.datetime,
#             "datey": dt.date,
#             "floaty": float,
#             "inty": int,
#             "stry": str,
#             "timey": dt.time,
#             "nesty": {"level2": str},
#         }
#     )
# 
#     @classmethod
#     def check(cls, **kwargs):
#         # Disable the checks on MySQL so that checks tests don't fail
#         if not (connection_is_mariadb(connection)):
#             return []
#         return super().check(**kwargs)
# 
#     def __str__(self):  # pragma: no cover
#         return ",".join(f"{key}:{value}" for key, value in self.attrs.items())
# 
# class SpeclessDynamicModel(Model):
#     attrs = DynamicField()
# 
#     @classmethod
#     def check(cls, **kwargs):
#         # Disable the checks on MySQL so that checks tests don't fail
#         if not (connection_is_mariadb(connection)):
#             return []
#         return super().check(**kwargs)
# 
#     def __str__(self):  # pragma: no cover
#         return ",".join(f"{key}:{value}" for key, value in self.attrs.items())


# Path: tests/testapp/test_dynamicfield.py
import datetime as dt
import json
import mariadb_dyncol
import pytest
from unittest import SkipTest, mock
from django.core import serializers
from django.core.exceptions import FieldError
from django.db import connection, models
from django.db.migrations.writer import MigrationWriter
from django.db.models import CharField, Transform
from django.test import TestCase
from django.test.utils import isolate_apps
from django_mysql.models import DynamicField
from django_mysql.utils import connection_is_mariadb
from tests.compat import wrap_testdata
from tests.testapp.models import DynamicModel, SpeclessDynamicModel
        from django_mysql.models.fields import DynamicField as DField
        from django_mysql.models.fields.dynamic import DynamicField as DField


    def test_key_transform_timey_TIME(self):
        assert list(
            DynamicModel.objects.filter(attrs__timey_TIME=dt.time(14, 15, 16))
        ) == [self.objs[4]]

    def test_key_transform_nesty__level2(self):
        assert list(DynamicModel.objects.filter(attrs__nesty__level2="chirp")) == [
            self.objs[4]
        ]

    def test_key_transform_nesty__level2__startswith(self):
        assert list(
            DynamicModel.objects.filter(attrs__nesty__level2__startswith="chi")
        ) == [self.objs[4]]


class SpeclessQueryTests(DynColTestCase):
    @classmethod
    @wrap_testdata
    def setUpTestData(cls):
        super().setUpTestData()
        objs = [
            SpeclessDynamicModel(attrs={"a": "b"}),
            SpeclessDynamicModel(attrs={"a": "c"}),
        ]
        SpeclessDynamicModel.objects.bulk_create(objs)
        cls.objs = list(SpeclessDynamicModel.objects.order_by("id"))

    def test_simple(self):

        assert list(SpeclessDynamicModel.objects.filter(attrs__a_CHAR="b")) == [