Пример #1
0
 def test_to_python_int_values(self):
     self.assertEqual(
         ULIDField().to_python(0),
         ulid.parse('00000000-0000-0000-0000-000000000000')
     )
     # Works for integers less than 128 bits.
     self.assertEqual(
         ULIDField().to_python((2 ** 128) - 1),
         ulid.parse('ffffffff-ffff-ffff-ffff-ffffffffffff')
     )
Пример #2
0
class ULIDModel(models.Model):
    field = ULIDField(default=None, null=False)
Пример #3
0
class PrimaryKeyULIDModel(models.Model):
    id = ULIDField(primary_key=True, default=ulid.new)
Пример #4
0
class NullableULIDModel(models.Model):
    field = ULIDField(blank=True, null=True)
Пример #5
0
 def test_to_python_int_too_large(self):
     # Fails for integers larger than 128 bits.
     with self.assertRaises(exceptions.ValidationError):
         ULIDField().to_python(2 ** 128)
Пример #6
0
 def test_to_python(self):
     self.assertIsNone(ULIDField().to_python(None))
Пример #7
0
 def test_deconstruct(self):
     field = ULIDField()
     name, path, args, kwargs = field.deconstruct()
     self.assertEqual(kwargs, {})
Пример #8
0
 def test_ulid_instance_ok(self):
     field = ULIDField()
     field.clean(ulid.new(), None)  # no error
Пример #9
0
 def test_invalid_ulid(self):
     field = ULIDField()
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean('550e8400', None)
     self.assertEqual(cm.exception.code, 'invalid')
     self.assertEqual(cm.exception.message % cm.exception.params, "'550e8400' is not a valid ULID.")