2018-11-18 00:50:26 +01:00
|
|
|
from django.db import models
|
|
|
|
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
|
|
|
from django.test import SimpleTestCase
|
2018-11-17 22:18:54 +01:00
|
|
|
|
|
|
|
|
2018-11-18 00:50:26 +01:00
|
|
|
class SchemaEditorTests(SimpleTestCase):
|
2018-11-17 22:18:54 +01:00
|
|
|
def test_effective_default_callable(self):
|
|
|
|
"""SchemaEditor.effective_default() shouldn't call callable defaults."""
|
2022-02-03 20:24:19 +01:00
|
|
|
|
2018-11-17 22:18:54 +01:00
|
|
|
class MyStr(str):
|
|
|
|
def __call__(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
class MyCharField(models.CharField):
|
|
|
|
def _get_default(self):
|
|
|
|
return self.default
|
|
|
|
|
|
|
|
field = MyCharField(max_length=1, default=MyStr)
|
2018-11-18 00:50:26 +01:00
|
|
|
self.assertEqual(BaseDatabaseSchemaEditor._effective_default(field), MyStr)
|