def testValidateColor(self):
    self.mox.StubOutWithMock(model, '_ValidateKMLColor')
    mock_schema = mox.Mox().CreateMock(model.Schema)  # Skip verification.
    field = model.Field(schema=mock_schema, name='a', type='color')
    bad_color = object()

    model._ValidateKMLColor('MiXeDcAsE')
    model._ValidateKMLColor(bad_color).AndRaise(ValueError)

    self.mox.ReplayAll()
    self.assertEqual(field.Validate('MiXeDcAsE'), 'mixedcase')
    self.assertEqual(field.Validate(bad_color), None)
 def testValidateKMLColor(self):
   model._ValidateKMLColor(None)
   model._ValidateKMLColor('12345678')
   model._ValidateKMLColor('12AABB08')
   model._ValidateKMLColor('12aabb78')
   model._ValidateKMLColor('1a4eB78f')
   self.assertRaises(db.BadValueError, model._ValidateKMLColor, '')
   self.assertRaises(db.BadValueError, model._ValidateKMLColor, '5678')
   self.assertRaises(db.BadValueError, model._ValidateKMLColor, '567855')
   self.assertRaises(db.BadValueError, model._ValidateKMLColor, '1234567g')
   self.assertRaises(db.BadValueError, model._ValidateKMLColor, '1234567f ')
   self.assertRaises(db.BadValueError, model._ValidateKMLColor, '012345678')
   self.assertRaises(db.BadValueError, model._ValidateKMLColor, '0x12345678')
   self.assertRaises(TypeError, model._ValidateKMLColor, 0x12345678)