From fa47829056a71e6b9b7f2ce913f2aebc36dc69e9 Mon Sep 17 00:00:00 2001 From: Robin Berger Date: Sat, 7 May 2022 10:00:00 +0200 Subject: [PATCH] test(projects): add tests for list project methods --- tests/unit/objects/test_projects.py | 136 ++++++++++++++++++++++++---- 1 file changed, 116 insertions(+), 20 deletions(-) diff --git a/tests/unit/objects/test_projects.py b/tests/unit/objects/test_projects.py index 60693dec8..d0f588467 100644 --- a/tests/unit/objects/test_projects.py +++ b/tests/unit/objects/test_projects.py @@ -5,9 +5,30 @@ import pytest import responses -from gitlab.v4.objects import Project +from gitlab.v4.objects import ( + Project, + ProjectFork, + ProjectUser, + StarredProject, + UserProject, +) project_content = {"name": "name", "id": 1} +languages_content = { + "python": 80.00, + "ruby": 99.99, + "CoffeeScript": 0.01, +} +user_content = { + "name": "first", + "id": 1, + "state": "active", +} +forks_content = [ + { + "id": 1, + }, +] import_content = { "id": 1, "name": "project", @@ -28,6 +49,71 @@ def resp_get_project(): yield rsps +@pytest.fixture +def resp_user_projects(): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/users/1/projects", + json=[project_content], + content_type="application/json", + status=200, + ) + yield rsps + + +@pytest.fixture +def resp_starred_projects(): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/users/1/starred_projects", + json=[project_content], + content_type="application/json", + status=200, + ) + yield rsps + + +@pytest.fixture +def resp_list_users(): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/projects/1/users", + json=[user_content], + content_type="application/json", + status=200, + ) + yield rsps + + +@pytest.fixture +def resp_list_forks(): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/projects/1/forks", + json=forks_content, + content_type="application/json", + status=200, + ) + yield rsps + + +@pytest.fixture +def resp_list_languages(): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/projects/1/languages", + json=languages_content, + content_type="application/json", + status=200, + ) + yield rsps + + @pytest.fixture def resp_list_projects(): with responses.RequestsMock() as rsps: @@ -98,19 +184,26 @@ def test_import_bitbucket_server(gl, resp_import_bitbucket_server): assert res["import_status"] == "scheduled" -@pytest.mark.skip(reason="missing test") -def test_list_user_projects(gl): - pass +def test_list_user_projects(user, resp_user_projects): + user_project = user.projects.list()[0] + assert isinstance(user_project, UserProject) + assert user_project.name == "name" + assert user_project.id == 1 -@pytest.mark.skip(reason="missing test") -def test_list_user_starred_projects(gl): - pass +def test_list_user_starred_projects(user, resp_starred_projects): + starred_projects = user.starred_projects.list()[0] + assert isinstance(starred_projects, StarredProject) + assert starred_projects.name == "name" + assert starred_projects.id == 1 -@pytest.mark.skip(reason="missing test") -def test_list_project_users(gl): - pass +def test_list_project_users(project, resp_list_users): + user = project.users.list()[0] + assert isinstance(user, ProjectUser) + assert user.id == 1 + assert user.name == "first" + assert user.state == "active" @pytest.mark.skip(reason="missing test") @@ -133,9 +226,10 @@ def test_fork_project(gl): pass -@pytest.mark.skip(reason="missing test") -def test_list_project_forks(gl): - pass +def test_list_project_forks(project, resp_list_forks): + fork = project.forks.list()[0] + assert isinstance(fork, ProjectFork) + assert fork.id == 1 @pytest.mark.skip(reason="missing test") @@ -153,9 +247,13 @@ def test_list_project_starrers(gl): pass -@pytest.mark.skip(reason="missing test") -def test_get_project_languages(gl): - pass +def test_get_project_languages(project, resp_list_languages): + python = project.languages().get("python") + ruby = project.languages().get("ruby") + coffee_script = project.languages().get("CoffeeScript") + assert python == 80.00 + assert ruby == 99.99 + assert coffee_script == 00.01 @pytest.mark.skip(reason="missing test") @@ -233,13 +331,11 @@ def test_delete_project_push_rule(gl): pass -def test_transfer_project(gl, resp_transfer_project): - project = gl.projects.get(1, lazy=True) +def test_transfer_project(project, resp_transfer_project): project.transfer("test-namespace") -def test_transfer_project_deprecated_warns(gl, resp_transfer_project): - project = gl.projects.get(1, lazy=True) +def test_transfer_project_deprecated_warns(project, resp_transfer_project): with pytest.warns(DeprecationWarning): project.transfer_project("test-namespace")