def test__get_version_match_fuzzy(self): match = "http://devstack/v2.1" root_endpoint = "http://devstack" versions = [{ "id": "v2.0", "links": [{ "href": "http://devstack/v2/", "rel": "self" }] }, { "id": "v2.1", "links": [{ "href": match, "rel": "self" }] }] sot = session.Session(None) endpoint = session.Session._Endpoint(root_endpoint, versions) # Look for a v2 match, which we internally denote as a minor # version of -1 so we can find the highest matching minor. rv = sot._get_version_match(endpoint, session.Version(2, -1), "service") self.assertEqual(rv, match)
def test__get_version_match_fragment(self): root = "http://cloud.net" match = "/v2" versions = [{"id": "v2.0", "links": [{"href": match, "rel": "self"}]}] sot = session.Session(None) endpoint = session.Session._Endpoint(root, versions) rv = sot._get_version_match(endpoint, session.Version(2, 0), "service") self.assertEqual(rv, root + match)
def test__get_version_match_project_id(self): match = "http://devstack/v2/" project_id = "asdf123" versions = [{"id": "v2.0", "links": [{"href": match, "rel": "self"}]}] sot = session.Session(None) sot.get_project_id = mock.Mock(return_value=project_id) rv = sot._get_version_match(versions, session.Version(2, 0), "service", "root", True) self.assertEqual(rv, match + project_id)
def test__get_version_match_project_id(self): match = "http://devstack/v2" root_endpoint = "http://devstack" project_id = "asdf123" versions = [{"id": "v2.0", "links": [{"href": match, "rel": "self"}]}] sot = session.Session(None) sot.get_project_id = mock.Mock(return_value=project_id) endpoint = session.Session._Endpoint(root_endpoint, versions, project_id=project_id, needs_project_id=True) rv = sot._get_version_match(endpoint, session.Version(2, 0), "service") match_endpoint = utils.urljoin(match, project_id) self.assertEqual(rv, match_endpoint)
def test__get_version_match_exact(self): match = "http://devstack/v2/" versions = [{ "id": "v2.0", "links": [{ "href": match, "rel": "self" }] }, { "id": "v2.1", "links": [{ "href": "http://devstack/v2.1/", "rel": "self" }] }] sot = session.Session(None) rv = sot._get_version_match(versions, session.Version(2, 0), "service", "root", False) self.assertEqual(rv, match)
def test__get_version_match_exact(self): match = "http://devstack/v2" root_endpoint = "http://devstack" versions = [{ "id": "v2.0", "links": [{ "href": match, "rel": "self" }] }, { "id": "v2.1", "links": [{ "href": "http://devstack/v2.1/", "rel": "self" }] }] sot = session.Session(None) endpoint = session.Session._Endpoint(root_endpoint, versions) rv = sot._get_version_match(endpoint, session.Version(2, 0), "service") self.assertEqual(rv, match)