From d7a3066e03164af7f441397eac9e8cfef17c8e0c Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Wed, 19 Feb 2020 00:34:27 +0100 Subject: test: add unit tests for revert commit API --- gitlab/tests/test_gitlab.py | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'gitlab/tests/test_gitlab.py') diff --git a/gitlab/tests/test_gitlab.py b/gitlab/tests/test_gitlab.py index 3eccf6e..aed675e 100644 --- a/gitlab/tests/test_gitlab.py +++ b/gitlab/tests/test_gitlab.py @@ -794,6 +794,58 @@ class TestGitlab(unittest.TestCase): self.gl.users.get(1, lazy=True).activate() self.gl.users.get(1, lazy=True).deactivate() + def test_commit_revert(self): + @urlmatch( + scheme="http", netloc="localhost", path="/api/v4/projects/1$", method="get" + ) + def resp_get_project(url, request): + headers = {"content-type": "application/json"} + content = '{"name": "name", "id": 1}'.encode("utf-8") + return response(200, content, headers, None, 5, request) + + @urlmatch( + scheme="http", + netloc="localhost", + path="/api/v4/projects/1/repository/commits/6b2257ea", + method="get", + ) + def resp_get_commit(url, request): + headers = {"content-type": "application/json"} + content = """{ + "id": "6b2257eabcec3db1f59dafbd84935e3caea04235", + "short_id": "6b2257ea", + "title": "Initial commit" + }""" + content = content.encode("utf-8") + return response(200, content, headers, None, 5, request) + + @urlmatch( + scheme="http", + netloc="localhost", + path="/api/v4/projects/1/repository/commits/6b2257ea", + method="post", + ) + def resp_revert_commit(url, request): + headers = {"content-type": "application/json"} + content = """{ + "id": "8b090c1b79a14f2bd9e8a738f717824ff53aebad", + "short_id": "8b090c1b", + "title":"Revert \\"Initial commit\\"" + }""" + content = content.encode("utf-8") + return response(200, content, headers, None, 5, request) + + with HTTMock(resp_get_project, resp_get_commit): + project = self.gl.projects.get(1) + commit = project.commits.get("6b2257ea") + self.assertEqual(commit.short_id, "6b2257ea") + self.assertEqual(commit.title, "Initial commit") + + with HTTMock(resp_revert_commit): + revert_commit = commit.revert(branch="master") + self.assertEqual(revert_commit["short_id"], "8b090c1b") + self.assertEqual(revert_commit["title"], 'Revert "Initial commit"') + def test_update_submodule(self): @urlmatch( scheme="http", netloc="localhost", path="/api/v4/projects/1$", method="get" -- cgit v1.2.1 From 31c65621ff592dda0ad3bf854db906beb8a48e9a Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Wed, 19 Feb 2020 20:35:43 +0100 Subject: test: use lazy object in unit tests --- gitlab/tests/test_gitlab.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gitlab/tests/test_gitlab.py') diff --git a/gitlab/tests/test_gitlab.py b/gitlab/tests/test_gitlab.py index aed675e..5e0f3c2 100644 --- a/gitlab/tests/test_gitlab.py +++ b/gitlab/tests/test_gitlab.py @@ -836,7 +836,7 @@ class TestGitlab(unittest.TestCase): return response(200, content, headers, None, 5, request) with HTTMock(resp_get_project, resp_get_commit): - project = self.gl.projects.get(1) + project = self.gl.projects.get(1, lazy=True) commit = project.commits.get("6b2257ea") self.assertEqual(commit.short_id, "6b2257ea") self.assertEqual(commit.title, "Initial commit") -- cgit v1.2.1 From cb436951b1fde9c010e966819c75d0d7adacf17d Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Wed, 19 Feb 2020 21:09:39 +0100 Subject: test: remove duplicate resp_get_project --- gitlab/tests/test_gitlab.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'gitlab/tests/test_gitlab.py') diff --git a/gitlab/tests/test_gitlab.py b/gitlab/tests/test_gitlab.py index 5e0f3c2..b56889a 100644 --- a/gitlab/tests/test_gitlab.py +++ b/gitlab/tests/test_gitlab.py @@ -795,14 +795,6 @@ class TestGitlab(unittest.TestCase): self.gl.users.get(1, lazy=True).deactivate() def test_commit_revert(self): - @urlmatch( - scheme="http", netloc="localhost", path="/api/v4/projects/1$", method="get" - ) - def resp_get_project(url, request): - headers = {"content-type": "application/json"} - content = '{"name": "name", "id": 1}'.encode("utf-8") - return response(200, content, headers, None, 5, request) - @urlmatch( scheme="http", netloc="localhost", @@ -835,7 +827,7 @@ class TestGitlab(unittest.TestCase): content = content.encode("utf-8") return response(200, content, headers, None, 5, request) - with HTTMock(resp_get_project, resp_get_commit): + with HTTMock(resp_get_commit): project = self.gl.projects.get(1, lazy=True) commit = project.commits.get("6b2257ea") self.assertEqual(commit.short_id, "6b2257ea") -- cgit v1.2.1