示例#1
0
 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())
示例#2
0
 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())
示例#3
0
 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())
示例#4
0
 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())
示例#5
0
    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())
示例#6
0
    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())
示例#7
0
    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(), '')
示例#8
0
    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(), '')
示例#9
0
 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())
示例#10
0
 def test_set_value(self):
     field = UUIDField(required=True)
     field.set_value(uuid.uuid4())
     field.validate()
     self.assertIsInstance(field.to_python(), uuid.UUID)
示例#11
0
 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())
示例#12
0
 def test_set_value(self):
     field = UUIDField(required=True)
     field.set_value(uuid.uuid4())
     field.validate()
     self.assertIsInstance(field.to_python(), uuid.UUID)