def test_versions_compare(self): min_version = version.parse_version_string(version.min_version_string()) max_version = version.parse_version_string(version.min_version_string()) self.assertLessEqual(min_version, max_version) huge_version = version.parse_version_string("99999.99999") self.assertGreater(huge_version, min_version)
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_matches_min_arg(self): request_version = version.parse_version_string("0.9") self.assertTrue(request_version.matches(min_version=(0, 9)))
def test_matches_no_args_good_version(self): request_version = version.parse_version_string("0.9") self.assertTrue(request_version.matches())
def test_matches_no_args_bad_version(self): request_version = version.parse_version_string("9.9") self.assertFalse(request_version.matches())
def test_matches_does_not_match_weird(self): request_version = version.parse_version_string("9.9") self.assertFalse(request_version.matches((75, 1), (10, 0)))
def test_matches_does_match(self): request_version = version.parse_version_string("9.9") # Version is a tuple under the hood self.assertTrue(request_version.matches((1, 1), (10, 0)))
def test_header_is_good(self): self.assertEqual("OpenStack-API-Version", version.Version.HEADER) request_version = version.parse_version_string("latest") self.assertEqual("OpenStack-API-Version", request_version.HEADER)
def test_version_latest(self): request_version = version.parse_version_string("latest") max_version = version.parse_version_string(version.max_version_string()) self.assertEqual(max_version, request_version)
def test_version_negative(self): request_version = version.parse_version_string("-10.5") self.assertEqual(-10, request_version.major) self.assertEqual(5, request_version.minor)
def test_version_parses(self): request_version = version.parse_version_string("10.5") self.assertEqual(10, request_version.major) self.assertEqual(5, request_version.minor)
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)
def test_matches_min_arg_bad_version(self): request_version = version.parse_version_string("0.8") self.assertFalse(request_version.matches(min_version=(0, 9)))