|
@@ -10,6 +10,7 @@ import re
|
|
|
import sys
|
|
|
import tokenize
|
|
|
import unittest
|
|
|
+import uuid
|
|
|
|
|
|
import custom_migration_operations.more_operations
|
|
|
import custom_migration_operations.operations
|
|
@@ -321,6 +322,31 @@ class WriterTests(SimpleTestCase):
|
|
|
"default=migrations.test_writer.IntEnum(1))"
|
|
|
)
|
|
|
|
|
|
+ def test_serialize_uuid(self):
|
|
|
+ self.assertSerializedEqual(uuid.uuid1())
|
|
|
+ self.assertSerializedEqual(uuid.uuid4())
|
|
|
+
|
|
|
+ uuid_a = uuid.UUID('5c859437-d061-4847-b3f7-e6b78852f8c8')
|
|
|
+ uuid_b = uuid.UUID('c7853ec1-2ea3-4359-b02d-b54e8f1bcee2')
|
|
|
+ self.assertSerializedResultEqual(
|
|
|
+ uuid_a,
|
|
|
+ ("uuid.UUID('5c859437-d061-4847-b3f7-e6b78852f8c8')", {'import uuid'})
|
|
|
+ )
|
|
|
+ self.assertSerializedResultEqual(
|
|
|
+ uuid_b,
|
|
|
+ ("uuid.UUID('c7853ec1-2ea3-4359-b02d-b54e8f1bcee2')", {'import uuid'})
|
|
|
+ )
|
|
|
+
|
|
|
+ field = models.UUIDField(choices=((uuid_a, 'UUID A'), (uuid_b, 'UUID B')), default=uuid_a)
|
|
|
+ string = MigrationWriter.serialize(field)[0]
|
|
|
+ self.assertEqual(
|
|
|
+ string,
|
|
|
+ "models.UUIDField(choices=["
|
|
|
+ "(uuid.UUID('5c859437-d061-4847-b3f7-e6b78852f8c8'), 'UUID A'), "
|
|
|
+ "(uuid.UUID('c7853ec1-2ea3-4359-b02d-b54e8f1bcee2'), 'UUID B')], "
|
|
|
+ "default=uuid.UUID('5c859437-d061-4847-b3f7-e6b78852f8c8'))"
|
|
|
+ )
|
|
|
+
|
|
|
def test_serialize_functions(self):
|
|
|
with self.assertRaisesMessage(ValueError, 'Cannot serialize function: lambda'):
|
|
|
self.assertSerializedEqual(lambda x: 42)
|