Example #1
0
        def decorator(f):
            obj_min_ver = api_version.APIVersionRequest(min_ver)
            if max_ver:
                obj_max_ver = api_version.APIVersionRequest(max_ver)
            else:
                obj_max_ver = api_version.APIVersionRequest()

            # Add to list of versioned methods registered
            func_name = f.__name__
            new_func = versioned_method.VersionedMethod(
                func_name, obj_min_ver, obj_max_ver, experimental, f)

            func_dict = getattr(cls, VER_METHOD_ATTR, {})
            if not func_dict:
                setattr(cls, VER_METHOD_ATTR, func_dict)

            func_list = func_dict.get(func_name, [])
            if not func_list:
                func_dict[func_name] = func_list
            func_list.append(new_func)
            # Ensure the list is sorted by minimum version (reversed)
            # so later when we work through the list in order we find
            # the method which has the latest version which supports
            # the version requested.
            # TODO(cyeoh): Add check to ensure that there are no overlapping
            # ranges of valid versions as that is ambiguous
            func_list.sort(reverse=True)

            return f
Example #2
0
    def test_str(self):
        args = ('fake_name', 'fake_min', 'fake_max')
        method = versioned_method.VersionedMethod(*(args + (False, None)))
        method_string = six.text_type(method)

        self.assertEqual('Version Method %s: min: %s, max: %s' % args,
                         method_string)
Example #3
0
 def test_cmpkey(self):
     method = versioned_method.VersionedMethod(
         'fake_name', 'fake_start_version', 'fake_end_version', False,
         'fake_func')
     self.assertEqual('fake_start_version', method._cmpkey())