def set_version(): """A before_request function to set microversion.""" try: flask.g.request_version = version.extract_version( flask.request.headers) except ValueError as exc: flask.g.request_version = version.parse_version_string( version.min_version_string()) raise httpexceptor.HTTP406('unable to use provided version: %s' % exc)
def test_cows_in_header_no_service(self): headers = {"openstack-api-version": " 1 . cow "} request_version = version.extract_version(headers) self.assertEqual(request_version.min_version, request_version)
def test_weird_whitespacey_header(self): headers = {"openstack-api-version": "enamel 1 . 0 "} request_version = version.extract_version(headers) self.assertEqual(version.Version(1, 0), request_version)
def test_weird_untyped_header(self): headers = {"openstack-api-version": "1.0 bottles of sangria"} request_version = version.extract_version(headers) self.assertEqual(request_version.min_version, request_version)
def test_latest_header(self): headers = {"openstack-api-version": "enamel latest"} request_version = version.extract_version(headers) self.assertEqual(request_version.max_version, request_version)
def test_missing_header(self): headers = {} request_version = version.extract_version(headers) self.assertEqual(request_version.min_version, request_version)
def test_correct_headers(self): headers = {"openstack-api-version": "enamel 0.9"} request_version = version.extract_version(headers) self.assertEqual(version.parse_version_string("0.9"), request_version)