# Path: tests/project/models.py
# class Child(TimeStampedModel):
#     name = models.CharField(max_length=255)
#     parent = models.ForeignKey(Parent, null=True, on_delete=models.CASCADE)
#     objects = Manager.from_queryset(ExtendedQuerySet)()
# 
# class Node(TimeStampedModel):
#     name = models.CharField(max_length=255)
#     parent = models.ForeignKey("self", null=True, on_delete=models.CASCADE)
#     objects = Manager.from_queryset(ExtendedQuerySet)()
# 
# class Parent(TimeStampedModel):
#     name = models.CharField(max_length=255)
#     objects = Manager.from_queryset(ExtendedQuerySet)()
# 
#     @property
#     def attribute_error(self) -> NoReturn:
#         raise AttributeError()
# 
#     @property
#     def version(self) -> str:
#         return str(self.pk) + ":" + str(self.date_modified)
# 
# class SecretModel(models.Model):
#     secret = SecretField()
# 
# class Simple(Model):
#     name = models.CharField(max_length=255)
#     objects = SimpleManager()
# 
# class TestUUIDModel(UUIDModel):
#     text = models.CharField(max_length=255)
#     parent = models.ForeignKey("TestUUIDModel", null=True, on_delete=models.CASCADE)
# 
# class URLSecretModel(models.Model):
#     # num_bytes=25 forces the base64 algorithm to pad
#     secret = URLSecretField(num_bytes=25, min_bytes=25)


from os import environ
from django.conf import global_settings
from django.core.exceptions import ValidationError
from django.test import TestCase
from bananas import environment
from bananas.environment import env
from bananas.models import ModelDict
from tests.project.models import (
    Child,
    Node,
    Parent,
    SecretModel,
    Simple,
    TestUUIDModel,
    URLSecretModel,
)
        from tests.project import settings_example as settings
        self.child = Child.objects.create(name="B", parent=self.parent)
        self.other_child = Child.objects.create(name="C", parent=self.parent)

    def test_modeldict(self):
        d = ModelDict(foo="bar", baz__ham="spam")
        self.assertIn("foo", d, 'should have key "foo"')
        self.assertNotIn("baz", d, 'should not have key "baz"')
        self.assertRaises(AttributeError, d.__getattr__, "x")
        self.assertTrue(hasattr(d, "foo"), 'should not have real attr "foo"')
        self.assertEqual(d.foo, "bar")
        self.assertEqual(d.baz__ham, "spam")
        self.assertIsInstance(d.baz, ModelDict, "should lazy resolve sub dict")

    def test_modeldict_from_model(self):
        d = ModelDict.from_model(self.child, "id", "parent__id", "parent__name")
        self.assertDictEqual(
            d, {"id": self.child.id, "parent__id": self.parent.id, "parent__name": "A"}
        )
        self.assertTrue(d.parent)

        _child = Child.objects.create(name="B")
        d = ModelDict.from_model(_child, "id", "parent__id", "parent__name")
        self.assertDictEqual(
            d,
            {
                "id": _child.id,
                "parent": None,
            },
        )


# Path: tests/project/models.py
# class Child(TimeStampedModel):
#     name = models.CharField(max_length=255)
#     parent = models.ForeignKey(Parent, null=True, on_delete=models.CASCADE)
#     objects = Manager.from_queryset(ExtendedQuerySet)()
# 
# class Node(TimeStampedModel):
#     name = models.CharField(max_length=255)
#     parent = models.ForeignKey("self", null=True, on_delete=models.CASCADE)
#     objects = Manager.from_queryset(ExtendedQuerySet)()
# 
# class Parent(TimeStampedModel):
#     name = models.CharField(max_length=255)
#     objects = Manager.from_queryset(ExtendedQuerySet)()
# 
#     @property
#     def attribute_error(self) -> NoReturn:
#         raise AttributeError()
# 
#     @property
#     def version(self) -> str:
#         return str(self.pk) + ":" + str(self.date_modified)
# 
# class SecretModel(models.Model):
#     secret = SecretField()
# 
# class Simple(Model):
#     name = models.CharField(max_length=255)
#     objects = SimpleManager()
# 
# class TestUUIDModel(UUIDModel):
#     text = models.CharField(max_length=255)
#     parent = models.ForeignKey("TestUUIDModel", null=True, on_delete=models.CASCADE)
# 
# class URLSecretModel(models.Model):
#     # num_bytes=25 forces the base64 algorithm to pad
#     secret = URLSecretField(num_bytes=25, min_bytes=25)


# Path: tests/tests/tests.py
from os import environ
from django.conf import global_settings
from django.core.exceptions import ValidationError
from django.test import TestCase
from bananas import environment
from bananas.environment import env
from bananas.models import ModelDict
from tests.project.models import (
    Child,
    Node,
    Parent,
    SecretModel,
    Simple,
    TestUUIDModel,
    URLSecretModel,
)
        from tests.project import settings_example as settings

        self.child = Child.objects.create(name="B", parent=self.parent)
        self.other_child = Child.objects.create(name="C", parent=self.parent)

    def test_modeldict(self):
        d = ModelDict(foo="bar", baz__ham="spam")
        self.assertIn("foo", d, 'should have key "foo"')
        self.assertNotIn("baz", d, 'should not have key "baz"')
        self.assertRaises(AttributeError, d.__getattr__, "x")
        self.assertTrue(hasattr(d, "foo"), 'should not have real attr "foo"')
        self.assertEqual(d.foo, "bar")
        self.assertEqual(d.baz__ham, "spam")
        self.assertIsInstance(d.baz, ModelDict, "should lazy resolve sub dict")

    def test_modeldict_from_model(self):
        d = ModelDict.from_model(self.child, "id", "parent__id", "parent__name")
        self.assertDictEqual(
            d, {"id": self.child.id, "parent__id": self.parent.id, "parent__name": "A"}
        )
        self.assertTrue(d.parent)

        _child = Child.objects.create(name="B")
        d = ModelDict.from_model(_child, "id", "parent__id", "parent__name")
        self.assertDictEqual(
            d,
            {
                "id": _child.id,
                "parent": None,
            },
        )


        _parent = Node.objects.create(name="A", parent=None)