diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2018-02-05 14:43:02 +0100 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2018-02-05 14:43:02 +0100 |
commit | f276f13df50132554984f989b1d3d6c5fa8cdc01 (patch) | |
tree | c59072098988fb284bcfce068d1d81f81b29da44 | |
parent | b4f03173f33ed8d214ddc20b4791ec11677f6bb1 (diff) | |
download | gitlab-f276f13df50132554984f989b1d3d6c5fa8cdc01.tar.gz |
Default to API v4
-rw-r--r-- | docs/api-usage.rst | 12 | ||||
-rw-r--r-- | docs/cli.rst | 6 | ||||
-rw-r--r-- | docs/switching-to-v4.rst | 8 | ||||
-rw-r--r-- | gitlab/__init__.py | 2 | ||||
-rw-r--r-- | gitlab/config.py | 2 | ||||
-rw-r--r-- | gitlab/tests/test_gitlab.py | 6 | ||||
-rw-r--r-- | gitlab/tests/test_gitlabobject.py | 44 | ||||
-rw-r--r-- | gitlab/tests/test_manager.py | 3 |
8 files changed, 41 insertions, 42 deletions
diff --git a/docs/api-usage.rst b/docs/api-usage.rst index 5816b6d..190482f 100644 --- a/docs/api-usage.rst +++ b/docs/api-usage.rst @@ -7,7 +7,7 @@ python-gitlab supports both GitLab v3 and v4 APIs. v3 being deprecated by GitLab, its support in python-gitlab will be minimal. The development team will focus on v4. -v3 is still the default API used by python-gitlab, for compatibility reasons. +v4 is the default API used by python-gitlab since version 1.3.0. ``gitlab.Gitlab`` class @@ -63,21 +63,19 @@ for a detailed discussion. API version =========== -``python-gitlab`` uses the v3 GitLab API by default. Use the ``api_version`` -parameter to switch to v4: +``python-gitlab`` uses the v4 GitLab API by default. Use the ``api_version`` +parameter to switch to v3: .. code-block:: python import gitlab - gl = gitlab.Gitlab('http://10.0.0.1', 'JVNSESs8EwWRx5yDxM5q', api_version=4) + gl = gitlab.Gitlab('http://10.0.0.1', 'JVNSESs8EwWRx5yDxM5q', api_version=3) .. warning:: The python-gitlab API is not the same for v3 and v4. Make sure to read - :ref:`switching_to_v4` before upgrading. - - v4 will become the default in python-gitlab. + :ref:`switching_to_v4` if you are upgrading from v3. Managers ======== diff --git a/docs/cli.rst b/docs/cli.rst index 7620349..591761c 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -41,7 +41,7 @@ example: [somewhere] url = https://some.whe.re private_token = vTbFeqJYCY3sibBP7BZM - api_version = 4 + api_version = 3 [elsewhere] url = http://else.whe.re:8080 @@ -92,8 +92,8 @@ limited permissions. - An Oauth token for authentication. The Gitlab server must be configured to support this authentication method. * - ``api_version`` - - GitLab API version to use (``3`` or ``4``). Defaults to ``3`` for now, - but will switch to ``4`` eventually. + - GitLab API version to use (``3`` or ``4``). Defaults to ``4`` since + version 1.3.0. * - ``http_username`` - Username for optional HTTP authentication * - ``http_password`` diff --git a/docs/switching-to-v4.rst b/docs/switching-to-v4.rst index 217463d..ef21060 100644 --- a/docs/switching-to-v4.rst +++ b/docs/switching-to-v4.rst @@ -16,12 +16,12 @@ http://gitlab.com. Using the v4 API ================ -To use the new v4 API, explicitly define ``api_version` `in the ``Gitlab`` -constructor: +python-gitlab uses the v4 API by default since the 1.3.0 release. To use the +old v3 API, explicitly define ``api_version`` in the ``Gitlab`` constructor: .. code-block:: python - gl = gitlab.Gitlab(..., api_version=4) + gl = gitlab.Gitlab(..., api_version=3) If you use the configuration file, also explicitly define the version: @@ -30,7 +30,7 @@ If you use the configuration file, also explicitly define the version: [my_gitlab] ... - api_version = 4 + api_version = 3 Changes between v3 and v4 API diff --git a/gitlab/__init__.py b/gitlab/__init__.py index 69629f8..c909f9f 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -73,7 +73,7 @@ class Gitlab(object): def __init__(self, url, private_token=None, oauth_token=None, email=None, password=None, ssl_verify=True, http_username=None, - http_password=None, timeout=None, api_version='3', + http_password=None, timeout=None, api_version='4', session=None): self._api_version = str(api_version) diff --git a/gitlab/config.py b/gitlab/config.py index 3166ec4..0f4c424 100644 --- a/gitlab/config.py +++ b/gitlab/config.py @@ -128,7 +128,7 @@ class GitlabConfigParser(object): except Exception: pass - self.api_version = '3' + self.api_version = '4' try: self.api_version = self._config.get('global', 'api_version') except Exception: diff --git a/gitlab/tests/test_gitlab.py b/gitlab/tests/test_gitlab.py index d33df99..1a1f3d8 100644 --- a/gitlab/tests/test_gitlab.py +++ b/gitlab/tests/test_gitlab.py @@ -53,7 +53,7 @@ class TestGitlabRawMethods(unittest.TestCase): def setUp(self): self.gl = Gitlab("http://localhost", private_token="private_token", email="testuser@test.com", password="testpassword", - ssl_verify=True) + ssl_verify=True, api_version=3) @urlmatch(scheme="http", netloc="localhost", path="/api/v3/known_path", method="get") @@ -454,7 +454,7 @@ class TestGitlabMethods(unittest.TestCase): def setUp(self): self.gl = Gitlab("http://localhost", private_token="private_token", email="testuser@test.com", password="testpassword", - ssl_verify=True) + ssl_verify=True, api_version=3) def test_list(self): @urlmatch(scheme="http", netloc="localhost", @@ -938,7 +938,7 @@ class TestGitlab(unittest.TestCase): def setUp(self): self.gl = Gitlab("http://localhost", private_token="private_token", email="testuser@test.com", password="testpassword", - ssl_verify=True) + ssl_verify=True, api_version=3) def test_pickability(self): original_gl_objects = self.gl._objects diff --git a/gitlab/tests/test_gitlabobject.py b/gitlab/tests/test_gitlabobject.py index f7fd187..844ba9e 100644 --- a/gitlab/tests/test_gitlabobject.py +++ b/gitlab/tests/test_gitlabobject.py @@ -34,7 +34,7 @@ from httmock import urlmatch # noqa from gitlab import * # noqa -@urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects/1", +@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1", method="get") def resp_get_project(url, request): headers = {'content-type': 'application/json'} @@ -42,7 +42,7 @@ def resp_get_project(url, request): return response(200, content, headers, None, 5, request) -@urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects", +@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects", method="get") def resp_list_project(url, request): headers = {'content-type': 'application/json'} @@ -50,7 +50,7 @@ def resp_list_project(url, request): return response(200, content, headers, None, 5, request) -@urlmatch(scheme="http", netloc="localhost", path="/api/v3/issues/1", +@urlmatch(scheme="http", netloc="localhost", path="/api/v4/issues/1", method="get") def resp_get_issue(url, request): headers = {'content-type': 'application/json'} @@ -58,7 +58,7 @@ def resp_get_issue(url, request): return response(200, content, headers, None, 5, request) -@urlmatch(scheme="http", netloc="localhost", path="/api/v3/users/1", +@urlmatch(scheme="http", netloc="localhost", path="/api/v4/users/1", method="put") def resp_update_user(url, request): headers = {'content-type': 'application/json'} @@ -67,7 +67,7 @@ def resp_update_user(url, request): return response(200, content, headers, None, 5, request) -@urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects", +@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects", method="post") def resp_create_project(url, request): headers = {'content-type': 'application/json'} @@ -75,7 +75,7 @@ def resp_create_project(url, request): return response(201, content, headers, None, 5, request) -@urlmatch(scheme="http", netloc="localhost", path="/api/v3/groups/2/members", +@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/2/members", method="post") def resp_create_groupmember(url, request): headers = {'content-type': 'application/json'} @@ -84,14 +84,14 @@ def resp_create_groupmember(url, request): @urlmatch(scheme="http", netloc="localhost", - path="/api/v3/projects/2/snippets/3", method="get") + path="/api/v4/projects/2/snippets/3", method="get") def resp_get_projectsnippet(url, request): headers = {'content-type': 'application/json'} content = '{"title": "test", "id": 3}'.encode("utf-8") return response(200, content, headers, None, 5, request) -@urlmatch(scheme="http", netloc="localhost", path="/api/v3/groups/1", +@urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/1", method="delete") def resp_delete_group(url, request): headers = {'content-type': 'application/json'} @@ -100,7 +100,7 @@ def resp_delete_group(url, request): @urlmatch(scheme="http", netloc="localhost", - path="/api/v3/groups/2/projects/3", + path="/api/v4/groups/2/projects/3", method="post") def resp_transfer_project(url, request): headers = {'content-type': 'application/json'} @@ -109,7 +109,7 @@ def resp_transfer_project(url, request): @urlmatch(scheme="http", netloc="localhost", - path="/api/v3/groups/2/projects/3", + path="/api/v4/groups/2/projects/3", method="post") def resp_transfer_project_fail(url, request): headers = {'content-type': 'application/json'} @@ -118,7 +118,7 @@ def resp_transfer_project_fail(url, request): @urlmatch(scheme="http", netloc="localhost", - path="/api/v3/projects/2/repository/branches/branchname/protect", + path="/api/v4/projects/2/repository/branches/branchname/protect", method="put") def resp_protect_branch(url, request): headers = {'content-type': 'application/json'} @@ -127,7 +127,7 @@ def resp_protect_branch(url, request): @urlmatch(scheme="http", netloc="localhost", - path="/api/v3/projects/2/repository/branches/branchname/unprotect", + path="/api/v4/projects/2/repository/branches/branchname/unprotect", method="put") def resp_unprotect_branch(url, request): headers = {'content-type': 'application/json'} @@ -136,7 +136,7 @@ def resp_unprotect_branch(url, request): @urlmatch(scheme="http", netloc="localhost", - path="/api/v3/projects/2/repository/branches/branchname/protect", + path="/api/v4/projects/2/repository/branches/branchname/protect", method="put") def resp_protect_branch_fail(url, request): headers = {'content-type': 'application/json'} @@ -157,7 +157,7 @@ class TestGitlabObject(unittest.TestCase): data = json.loads(json_str) self.assertIn("id", data) self.assertEqual(data["username"], "testname") - self.assertEqual(data["gitlab"]["url"], "http://localhost/api/v3") + self.assertEqual(data["gitlab"]["url"], "http://localhost/api/v4") def test_pickability(self): gl_object = CurrentUser(self.gl, data={"username": "testname"}) @@ -381,7 +381,7 @@ class TestProjectCommit(unittest.TestCase): self.obj = ProjectCommit(self.gl, data={"id": 3, "project_id": 2}) @urlmatch(scheme="http", netloc="localhost", - path="/api/v3/projects/2/repository/commits/3/diff", + path="/api/v4/projects/2/repository/commits/3/diff", method="get") def resp_diff(self, url, request): headers = {'content-type': 'application/json'} @@ -389,7 +389,7 @@ class TestProjectCommit(unittest.TestCase): return response(200, content, headers, None, 5, request) @urlmatch(scheme="http", netloc="localhost", - path="/api/v3/projects/2/repository/commits/3/diff", + path="/api/v4/projects/2/repository/commits/3/diff", method="get") def resp_diff_fail(self, url, request): headers = {'content-type': 'application/json'} @@ -397,7 +397,7 @@ class TestProjectCommit(unittest.TestCase): return response(400, content, headers, None, 5, request) @urlmatch(scheme="http", netloc="localhost", - path="/api/v3/projects/2/repository/blobs/3", + path="/api/v4/projects/2/repository/blobs/3", method="get") def resp_blob(self, url, request): headers = {'content-type': 'application/json'} @@ -405,7 +405,7 @@ class TestProjectCommit(unittest.TestCase): return response(200, content, headers, None, 5, request) @urlmatch(scheme="http", netloc="localhost", - path="/api/v3/projects/2/repository/blobs/3", + path="/api/v4/projects/2/repository/blobs/3", method="get") def resp_blob_fail(self, url, request): headers = {'content-type': 'application/json'} @@ -440,7 +440,7 @@ class TestProjectSnippet(unittest.TestCase): self.obj = ProjectSnippet(self.gl, data={"id": 3, "project_id": 2}) @urlmatch(scheme="http", netloc="localhost", - path="/api/v3/projects/2/snippets/3/raw", + path="/api/v4/projects/2/snippets/3/raw", method="get") def resp_content(self, url, request): headers = {'content-type': 'application/json'} @@ -448,7 +448,7 @@ class TestProjectSnippet(unittest.TestCase): return response(200, content, headers, None, 5, request) @urlmatch(scheme="http", netloc="localhost", - path="/api/v3/projects/2/snippets/3/raw", + path="/api/v4/projects/2/snippets/3/raw", method="get") def resp_content_fail(self, url, request): headers = {'content-type': 'application/json'} @@ -474,7 +474,7 @@ class TestSnippet(unittest.TestCase): self.obj = Snippet(self.gl, data={"id": 3}) @urlmatch(scheme="http", netloc="localhost", - path="/api/v3/snippets/3/raw", + path="/api/v4/snippets/3/raw", method="get") def resp_content(self, url, request): headers = {'content-type': 'application/json'} @@ -482,7 +482,7 @@ class TestSnippet(unittest.TestCase): return response(200, content, headers, None, 5, request) @urlmatch(scheme="http", netloc="localhost", - path="/api/v3/snippets/3/raw", + path="/api/v4/snippets/3/raw", method="get") def resp_content_fail(self, url, request): headers = {'content-type': 'application/json'} diff --git a/gitlab/tests/test_manager.py b/gitlab/tests/test_manager.py index 5cd3130..c6ef299 100644 --- a/gitlab/tests/test_manager.py +++ b/gitlab/tests/test_manager.py @@ -52,7 +52,8 @@ class TestGitlabManager(unittest.TestCase): def setUp(self): self.gitlab = Gitlab("http://localhost", private_token="private_token", email="testuser@test.com", - password="testpassword", ssl_verify=True) + password="testpassword", ssl_verify=True, + api_version=3) def test_set_parent_args(self): @urlmatch(scheme="http", netloc="localhost", path="/api/v3/fake", |