def test_wrong_type_exception(self): self.mox.StubOutWithMock(datetime, 'datetime') datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05') self.mox.ReplayAll() exception = WrongTypeException('field_name', 'value', '1234', 'uuid') self.assertEqual(exception.reason, "Failed at 2014-01-02 03:04:05 UTC for uuid: " "{field_name: value} was of incorrect type for" " exist id 1234")
def test_wrong_type_exception(self): utils.mock_datetime_utcnow(self.mox, '2014-01-02 03:04:05') exception = WrongTypeException('field_name', 'value', 'exist_id', 'uuid') self.assertEqual(exception.field_name, 'field_name') self.assertEqual(exception.value, 'value') self.assertEqual(exception.exist_id, 'exist_id') self.assertEqual(exception.uuid, 'uuid') self.assertEqual( exception.reason, "Failed at 2014-01-02 03:04:05 UTC for uuid: {field_name: value} " "was of incorrect type for exist id exist_id")
def _is_int_in_char(attr_name, attr_value, exist_id, instance_uuid): try: int(attr_value) except ValueError: raise WrongTypeException(attr_name, attr_value, exist_id, instance_uuid)
def _is_long(attr_name, attr_value, exist_id, instance_uuid): if not isinstance(attr_value, long): raise WrongTypeException(attr_name, attr_value, exist_id, instance_uuid)
def _is_like_date(attr_name, attr_value, exist_id, instance_uuid): if not isinstance(attr_value, decimal.Decimal): raise WrongTypeException(attr_name, attr_value, exist_id, instance_uuid)
def _is_like_uuid(attr_name, attr_value, exist_id): if not re.match( "[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$", attr_value): raise WrongTypeException(attr_name, attr_value, exist_id, None)
def _is_alphanumeric(attr_name, attr_value, exist_id, instance_uuid): if not re.match("[a-zA-Z0-9.]+$", attr_value): raise WrongTypeException(attr_name, attr_value, exist_id, instance_uuid)
def _is_hex_owner_id(attr_name, attr_value, exist_id, instance_uuid): if not re.match("^[0-9a-fA-F]+$", attr_value): raise WrongTypeException(attr_name, attr_value, exist_id, instance_uuid)