summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_autodetector.py4
-rw-r--r--tests/migrations/test_operations.py12
-rw-r--r--tests/schema/tests.py21
3 files changed, 29 insertions, 8 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index c54349313e..340805b259 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -1309,7 +1309,7 @@ class AutodetectorTests(BaseAutodetectorTests):
changes, "testapp", 0, 0, name="name", preserve_default=True
)
self.assertOperationFieldAttributes(
- changes, "testapp", 0, 0, db_default=models.Value("Ada Lovelace")
+ changes, "testapp", 0, 0, db_default="Ada Lovelace"
)
@mock.patch(
@@ -1515,7 +1515,7 @@ class AutodetectorTests(BaseAutodetectorTests):
changes, "testapp", 0, 0, name="name", preserve_default=True
)
self.assertOperationFieldAttributes(
- changes, "testapp", 0, 0, db_default=models.Value("Ada Lovelace")
+ changes, "testapp", 0, 0, db_default="Ada Lovelace"
)
@mock.patch(
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index 5733ba7618..f25bb290a5 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -1581,7 +1581,7 @@ class OperationTests(OperationTestBase):
self.assertEqual(len(new_state.models[app_label, "pony"].fields), 6)
field = new_state.models[app_label, "pony"].fields["height"]
self.assertEqual(field.default, models.NOT_PROVIDED)
- self.assertEqual(field.db_default, Value(4))
+ self.assertEqual(field.db_default, 4)
project_state.apps.get_model(app_label, "pony").objects.create(weight=4)
self.assertColumnNotExists(table_name, "height")
# Add field.
@@ -1632,7 +1632,7 @@ class OperationTests(OperationTestBase):
self.assertEqual(len(new_state.models[app_label, "pony"].fields), 6)
field = new_state.models[app_label, "pony"].fields["special_char"]
self.assertEqual(field.default, models.NOT_PROVIDED)
- self.assertEqual(field.db_default, Value(db_default))
+ self.assertEqual(field.db_default, db_default)
self.assertColumnNotExists(table_name, "special_char")
with connection.schema_editor() as editor:
operation.database_forwards(
@@ -1700,7 +1700,7 @@ class OperationTests(OperationTestBase):
self.assertEqual(len(new_state.models[app_label, "pony"].fields), 6)
field = new_state.models[app_label, "pony"].fields["height"]
self.assertEqual(field.default, 3)
- self.assertEqual(field.db_default, Value(4))
+ self.assertEqual(field.db_default, 4)
pre_pony_pk = (
project_state.apps.get_model(app_label, "pony").objects.create(weight=4).pk
)
@@ -2145,7 +2145,7 @@ class OperationTests(OperationTestBase):
old_weight = project_state.models[app_label, "pony"].fields["weight"]
self.assertIs(old_weight.db_default, models.NOT_PROVIDED)
new_weight = new_state.models[app_label, "pony"].fields["weight"]
- self.assertEqual(new_weight.db_default, Value(4.5))
+ self.assertEqual(new_weight.db_default, 4.5)
with self.assertRaises(IntegrityError), transaction.atomic():
project_state.apps.get_model(app_label, "pony").objects.create()
# Alter field.
@@ -2187,7 +2187,7 @@ class OperationTests(OperationTestBase):
self.assertIs(old_pink.db_default, models.NOT_PROVIDED)
new_pink = new_state.models[app_label, "pony"].fields["pink"]
self.assertIs(new_pink.default, models.NOT_PROVIDED)
- self.assertEqual(new_pink.db_default, Value(4))
+ self.assertEqual(new_pink.db_default, 4)
pony = project_state.apps.get_model(app_label, "pony").objects.create(weight=1)
self.assertEqual(pony.pink, 3)
# Alter field.
@@ -2217,7 +2217,7 @@ class OperationTests(OperationTestBase):
old_green = project_state.models[app_label, "pony"].fields["green"]
self.assertIs(old_green.db_default, models.NOT_PROVIDED)
new_green = new_state.models[app_label, "pony"].fields["green"]
- self.assertEqual(new_green.db_default, Value(4))
+ self.assertEqual(new_green.db_default, 4)
old_pony = project_state.apps.get_model(app_label, "pony").objects.create(
weight=1
)
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 04ad299aa6..ced3367f00 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -7,6 +7,7 @@ from unittest import mock
from django.core.exceptions import FieldError
from django.core.management.color import no_style
+from django.core.serializers.json import DjangoJSONEncoder
from django.db import (
DatabaseError,
DataError,
@@ -2333,6 +2334,26 @@ class SchemaTests(TransactionTestCase):
with connection.schema_editor() as editor, self.assertNumQueries(0):
editor.alter_field(Author, Author._meta.get_field("name"), new_field)
+ @isolate_apps("schema")
+ def test_db_default_output_field_resolving(self):
+ class Author(Model):
+ data = JSONField(
+ encoder=DjangoJSONEncoder,
+ db_default={
+ "epoch": datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc)
+ },
+ )
+
+ class Meta:
+ app_label = "schema"
+
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+
+ author = Author.objects.create()
+ author.refresh_from_db()
+ self.assertEqual(author.data, {"epoch": "1970-01-01T00:00:00Z"})
+
@skipUnlessDBFeature(
"supports_column_check_constraints", "can_introspect_check_constraints"
)