2016-04-09 17:17:34 +00:00
|
|
|
import uuid
|
|
|
|
|
|
|
|
from django.forms import UUIDField, ValidationError
|
|
|
|
from django.test import SimpleTestCase
|
|
|
|
|
|
|
|
|
|
|
|
class UUIDFieldTest(SimpleTestCase):
|
|
|
|
|
|
|
|
def test_uuidfield_1(self):
|
|
|
|
field = UUIDField()
|
|
|
|
value = field.clean('550e8400e29b41d4a716446655440000')
|
|
|
|
self.assertEqual(value, uuid.UUID('550e8400e29b41d4a716446655440000'))
|
|
|
|
|
|
|
|
def test_uuidfield_2(self):
|
|
|
|
field = UUIDField(required=False)
|
|
|
|
value = field.clean('')
|
2016-06-16 18:19:18 +00:00
|
|
|
self.assertIsNone(value)
|
2016-04-09 17:17:34 +00:00
|
|
|
|
|
|
|
def test_uuidfield_3(self):
|
|
|
|
field = UUIDField()
|
2017-05-28 19:37:21 +00:00
|
|
|
with self.assertRaisesMessage(ValidationError, 'Enter a valid UUID.'):
|
2016-04-09 17:17:34 +00:00
|
|
|
field.clean('550e8400')
|
|
|
|
|
|
|
|
def test_uuidfield_4(self):
|
|
|
|
field = UUIDField()
|
|
|
|
value = field.prepare_value(uuid.UUID('550e8400e29b41d4a716446655440000'))
|
|
|
|
self.assertEqual(value, '550e8400e29b41d4a716446655440000')
|