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")
Example #2
0
    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")
Example #3
0
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)
Example #4
0
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)
Example #5
0
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)
Example #6
0
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)
Example #7
0
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)
Example #8
0
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)