Skip to content

test: increase projects coverage #2012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 116 additions & 20 deletions tests/unit/objects/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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:
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")

Expand Down