Increase unit test coverage for Version Negotiation API.
Implements bp: murano-unit-test-coverage Change-Id: I3ab653fae79c2bf2660e57199aeab44b2684f1d8
This commit is contained in:
parent
d2ea832a2f
commit
f2b0db77d4
@ -13,19 +13,81 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import mock
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
from murano.api import versions
|
|
||||||
|
|
||||||
from murano.api.middleware import version_negotiation
|
from murano.api.middleware import version_negotiation
|
||||||
|
from murano.api import versions
|
||||||
from murano.tests.unit import base
|
from murano.tests.unit import base
|
||||||
|
|
||||||
|
|
||||||
class MiddlewareVersionNegotiationTest(base.MuranoTestCase):
|
class MiddlewareVersionNegotiationTest(base.MuranoTestCase):
|
||||||
|
|
||||||
def test_middleware_version_negotiation_default(self):
|
@mock.patch.object(version_negotiation, 'LOG')
|
||||||
|
def test_middleware_version_negotiation_default(self, mock_log):
|
||||||
middleware_vn = version_negotiation.VersionNegotiationFilter(None)
|
middleware_vn = version_negotiation.VersionNegotiationFilter(None)
|
||||||
request = webob.Request.blank('/environments')
|
request = webob.Request.blank('/environments')
|
||||||
|
|
||||||
result = middleware_vn.process_request(request)
|
result = middleware_vn.process_request(request)
|
||||||
|
|
||||||
self.assertIsInstance(result, versions.Controller)
|
self.assertIsInstance(result, versions.Controller)
|
||||||
|
mock_log.warning.assert_called_once_with(
|
||||||
|
version_negotiation._LW(
|
||||||
|
"Unknown version. Returning version choices."))
|
||||||
|
|
||||||
|
@mock.patch.object(version_negotiation, 'LOG')
|
||||||
|
def test_process_request(self, mock_log):
|
||||||
|
"""Test process_request using different valid paths."""
|
||||||
|
middleware_vn = version_negotiation.VersionNegotiationFilter(None)
|
||||||
|
|
||||||
|
for path in ('v1', '/v1', '///v1'):
|
||||||
|
request = webob.Request.blank(path)
|
||||||
|
request.method = 'GET'
|
||||||
|
request.environ = {}
|
||||||
|
|
||||||
|
result = middleware_vn.process_request(request)
|
||||||
|
|
||||||
|
self.assertIsNone(result)
|
||||||
|
self.assertIn('api.version', request.environ)
|
||||||
|
self.assertEqual(1, request.environ['api.version'])
|
||||||
|
self.assertEqual('/v1', request.path_info)
|
||||||
|
mock_log.debug.assert_any_call(
|
||||||
|
"Matched version: v{version}".format(version=1))
|
||||||
|
mock_log.debug.assert_any_call(
|
||||||
|
'new path {path}'.format(path='/v1'))
|
||||||
|
|
||||||
|
request = webob.Request.blank('/v1/')
|
||||||
|
request.method = 'GET'
|
||||||
|
request.environ = {}
|
||||||
|
|
||||||
|
result = middleware_vn.process_request(request)
|
||||||
|
|
||||||
|
self.assertIsNone(result)
|
||||||
|
self.assertIn('api.version', request.environ)
|
||||||
|
self.assertEqual(1, request.environ['api.version'])
|
||||||
|
self.assertEqual('/v1/', request.path_info)
|
||||||
|
mock_log.debug.assert_any_call(
|
||||||
|
"Matched version: v{version}".format(version=1))
|
||||||
|
mock_log.debug.assert_any_call(
|
||||||
|
'new path {path}'.format(path='/v1/'))
|
||||||
|
|
||||||
|
@mock.patch.object(version_negotiation, 'LOG')
|
||||||
|
def test_process_request_without_path(self, mock_log):
|
||||||
|
middleware_vn = version_negotiation.VersionNegotiationFilter(None)
|
||||||
|
|
||||||
|
request = webob.Request.blank('')
|
||||||
|
request.method = 'GET'
|
||||||
|
request.environ = {}
|
||||||
|
|
||||||
|
result = middleware_vn.process_request(request)
|
||||||
|
|
||||||
|
self.assertIsInstance(result, versions.Controller)
|
||||||
|
mock_log.warning.assert_called_once_with(
|
||||||
|
version_negotiation._LW(
|
||||||
|
"Unknown version. Returning version choices."))
|
||||||
|
|
||||||
|
def test_factory(self):
|
||||||
|
app = version_negotiation.VersionNegotiationFilter.factory(None)
|
||||||
|
self.assertIsNotNone(app)
|
||||||
|
self.assertEqual(
|
||||||
|
version_negotiation.VersionNegotiationFilter, type(app(None)))
|
||||||
|
Loading…
Reference in New Issue
Block a user