def test_no_binary(self): field = UUIDField(required=True, binary=False) field.set_value('8005ea5e-60b7-4b2a-ab41-a773b8b72e84'.upper()) field.validate() self.assertIsInstance(field.to_python(), py2to3.string) self.assertEqual(field.to_python(), '8005ea5e-60b7-4b2a-ab41-a773b8b72e84') self.assertEqual(field.to_native(), '8005ea5e-60b7-4b2a-ab41-a773b8b72e84'.upper())
def test_set_value_string(self): field = UUIDField(required=True) field.set_value('8005ea5e-60b7-4b2a-ab41-a773b8b72e84'.upper()) field.validate() self.assertIsInstance(field.to_python(), uuid.UUID) self.assertEqual(field.to_python(), uuid.UUID('8005ea5e-60b7-4b2a-ab41-a773b8b72e84')) self.assertEqual(field.to_native(), '8005ea5e-60b7-4b2a-ab41-a773b8b72e84'.upper())
def test_default(self): field = UUIDField(required=True, default=uuid.UUID('8005ea5e-60b7-4b2a-ab41-a773b8b72e84')) field.validate() self.assertEqual(field.to_python(), uuid.UUID('8005ea5e-60b7-4b2a-ab41-a773b8b72e84')) self.assertEqual(field.to_native(), '8005ea5e-60b7-4b2a-ab41-a773b8b72e84'.upper()) field = UUIDField(required=True, default='8005ea5e-60b7-4b2a-ab41-a773b8b72e84') field.validate() self.assertEqual(field.to_python(), uuid.UUID('8005ea5e-60b7-4b2a-ab41-a773b8b72e84')) self.assertEqual(field.to_native(), '8005ea5e-60b7-4b2a-ab41-a773b8b72e84'.upper())
def test_default(self): field = UUIDField( required=True, default=uuid.UUID('8005ea5e-60b7-4b2a-ab41-a773b8b72e84')) field.validate() self.assertEqual(field.to_python(), uuid.UUID('8005ea5e-60b7-4b2a-ab41-a773b8b72e84')) self.assertEqual(field.to_native(), '8005ea5e-60b7-4b2a-ab41-a773b8b72e84'.upper()) field = UUIDField(required=True, default='8005ea5e-60b7-4b2a-ab41-a773b8b72e84') field.validate() self.assertEqual(field.to_python(), uuid.UUID('8005ea5e-60b7-4b2a-ab41-a773b8b72e84')) self.assertEqual(field.to_native(), '8005ea5e-60b7-4b2a-ab41-a773b8b72e84'.upper())
def test_required(self): field = UUIDField(required=True) self.assertRaises(SerializerFieldValueError, field.validate) field = UUIDField(required=False) field.validate() self.assertIsNone(field.to_python()) self.assertEqual(field.to_native(), '')
def test_hide_on_null(self): field = UUIDField(required=False, on_null=HIDE_FIELD) self.assertRaises(IgnoreField, field.to_native) self.assertIsNone(field.to_python())
def test_set_value(self): field = UUIDField(required=True) field.set_value(uuid.uuid4()) field.validate() self.assertIsInstance(field.to_python(), uuid.UUID)