Пример #1
0
    def test_init(self, mock_parse):
        a = mock.Mock()
        b = mock.Mock()
        mock_parse.return_value = (a, b)
        v = base.Version('test', 'foo', 'bar')

        mock_parse.assert_called_with('test', 'foo', 'bar')
        self.assertEqual(a, v.major)
        self.assertEqual(b, v.minor)
Пример #2
0
    def _route(self, args):
        version = controllers_base.Version(pecan.request.headers, MIN_VER_STR,
                                           MAX_VER_STR)

        # Always set the min and max headers
        pecan.response.headers[
            controllers_base.Version.min_string] = MIN_VER_STR
        pecan.response.headers[
            controllers_base.Version.max_string] = MAX_VER_STR

        # assert that requested version is supported
        self._check_version(version, pecan.response.headers)
        pecan.response.headers[controllers_base.Version.string] = str(version)
        pecan.request.version = version

        return super(Controller, self)._route(args)
Пример #3
0
    def _route(self, args):
        version = controllers_base.Version(pecan.request.headers, MIN_VER_STR,
                                           MAX_VER_STR)

        # Always set the min and max headers
        pecan.response.headers[
            controllers_base.Version.min_string] = MIN_VER_STR
        pecan.response.headers[
            controllers_base.Version.max_string] = MAX_VER_STR

        # assert that requested version is supported
        self._check_version(version, pecan.response.headers)
        pecan.response.headers[controllers_base.Version.string] = str(version)
        pecan.request.version = version
        if pecan.request.body:
            msg = ("Processing request: url: %(url)s, %(method)s, "
                   "body: %(body)s" % {
                       'url': pecan.request.url,
                       'method': pecan.request.method,
                       'body': pecan.request.body
                   })
            LOG.debug(msg)

        return super(Controller, self)._route(args)
Пример #4
0
# NOTE(yuntong): v1.0 is reserved to indicate Kilo's API, but is not presently
#             supported by the API service. All changes between Kilo and the
#             point where we added microversioning are considered backwards-
#             compatible, but are not specifically discoverable at this time.
#
#             The v1.1 version indicates this "initial" version as being
#             different from Kilo (v1.0), and includes the following changes:
#

# v1.1: API at the point in time when microversioning support was added
MIN_VER_STR = '1.1'

# v1.1: Add API changelog here
MAX_VER_STR = '1.1'

MIN_VER = controllers_base.Version(
    {controllers_base.Version.string: MIN_VER_STR}, MIN_VER_STR, MAX_VER_STR)
MAX_VER = controllers_base.Version(
    {controllers_base.Version.string: MAX_VER_STR}, MIN_VER_STR, MAX_VER_STR)


class MediaType(controllers_base.APIBase):
    """A media type representation."""

    base = wtypes.text
    type = wtypes.text

    def __init__(self, base, type):
        self.base = base
        self.type = type

Пример #5
0
 def test_repr_with_strings(self, mock_parse):
     mock_parse.return_value = ('abc', 'def')
     v = base.Version('test', mock.ANY, mock.ANY)
     result = "%s" % v
     self.assertEqual('abc.def', result)
Пример #6
0
 def test_repr(self, mock_parse):
     mock_parse.return_value = (123, 456)
     v = base.Version('test', mock.ANY, mock.ANY)
     result = "%s" % v
     self.assertEqual('123.456', result)
Пример #7
0
 def setUp(self):
     super(TestVersion, self).setUp()
     self.a = base.Version({base.Version.string: "2.0"}, "2.0", "2.1")
     self.b = base.Version({base.Version.string: "2.0"}, "2.0", "2.1")