def test_version_matches_experimental_request(self):

        experimental_request = api_version_request.APIVersionRequest('2.0')
        experimental_request.experimental = True

        non_experimental_request = api_version_request.APIVersionRequest('2.0')

        experimental_function = versioned_method.VersionedMethod(
            'experimental_function',
            api_version_request.APIVersionRequest('2.0'),
            api_version_request.APIVersionRequest('2.1'), True, None)

        non_experimental_function = versioned_method.VersionedMethod(
            'non_experimental_function',
            api_version_request.APIVersionRequest('2.0'),
            api_version_request.APIVersionRequest('2.1'), False, None)

        self.assertTrue(
            experimental_request.matches_versioned_method(
                experimental_function))
        self.assertTrue(
            experimental_request.matches_versioned_method(
                non_experimental_function))
        self.assertTrue(
            non_experimental_request.matches_versioned_method(
                non_experimental_function))
        self.assertFalse(
            non_experimental_request.matches_versioned_method(
                experimental_function))
Beispiel #2
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
Beispiel #3
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)
Beispiel #4
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)

            return new_func
Beispiel #5
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())