Skip to content

Commit f1ebb88

Browse files
committed
refactor: split unit tests by GitLab API resources
1 parent 3d6a723 commit f1ebb88

34 files changed

+2654
-2447
lines changed

gitlab/__init__.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@
4242
)
4343

4444

45-
def _sanitize(value):
46-
if isinstance(value, dict):
47-
return dict((k, _sanitize(v)) for k, v in value.items())
48-
if isinstance(value, str):
49-
return value.replace("/", "%2F")
50-
return value
51-
52-
5345
class Gitlab(object):
5446
"""Represents a GitLab server connection.
5547
@@ -319,7 +311,7 @@ def set_license(self, license, **kwargs):
319311
def _construct_url(self, id_, obj, parameters, action=None):
320312
if "next_url" in parameters:
321313
return parameters["next_url"]
322-
args = _sanitize(parameters)
314+
args = utils.sanitize_parameters(parameters)
323315

324316
url_attr = "_url"
325317
if action is not None:

gitlab/tests/conftest.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import pytest
2+
3+
import gitlab
4+
5+
6+
@pytest.fixture
7+
def default_config(tmpdir):
8+
valid_config = """[global]
9+
default = one
10+
ssl_verify = true
11+
timeout = 2
12+
13+
[one]
14+
url = http://one.url
15+
private_token = ABCDEF
16+
"""
17+
18+
config_path = tmpdir.join("python-gitlab.cfg")
19+
config_path.write(valid_config)
20+
return str(config_path)
21+
22+
23+
@pytest.fixture
24+
def gl():
25+
return gitlab.Gitlab(
26+
"http://localhost", private_token="private_token", api_version=4
27+
)
28+
29+
30+
# Todo: parametrize, but check what tests it's really useful for
31+
@pytest.fixture
32+
def gl_trailing():
33+
return gitlab.Gitlab(
34+
"http://localhost/", private_token="private_token", api_version=4
35+
)
36+
37+
38+
@pytest.fixture
39+
def group(gl):
40+
return gl.groups.get(1, lazy=True)
41+
42+
43+
@pytest.fixture
44+
def project(gl):
45+
return gl.projects.get(1, lazy=True)
46+
47+
48+
@pytest.fixture
49+
def user(gl):
50+
return gl.users.get(1, lazy=True)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from gitlab.mixins import (
2+
CreateMixin,
3+
CRUDMixin,
4+
DeleteMixin,
5+
GetMixin,
6+
ListMixin,
7+
NoUpdateMixin,
8+
UpdateMixin,
9+
RetrieveMixin,
10+
)
11+
12+
13+
def test_retrieve_mixin():
14+
class M(RetrieveMixin):
15+
pass
16+
17+
obj = M()
18+
assert hasattr(obj, "list")
19+
assert hasattr(obj, "get")
20+
assert not hasattr(obj, "create")
21+
assert not hasattr(obj, "update")
22+
assert not hasattr(obj, "delete")
23+
assert isinstance(obj, ListMixin)
24+
assert isinstance(obj, GetMixin)
25+
26+
27+
def test_crud_mixin():
28+
class M(CRUDMixin):
29+
pass
30+
31+
obj = M()
32+
assert hasattr(obj, "get")
33+
assert hasattr(obj, "list")
34+
assert hasattr(obj, "create")
35+
assert hasattr(obj, "update")
36+
assert hasattr(obj, "delete")
37+
assert isinstance(obj, ListMixin)
38+
assert isinstance(obj, GetMixin)
39+
assert isinstance(obj, CreateMixin)
40+
assert isinstance(obj, UpdateMixin)
41+
assert isinstance(obj, DeleteMixin)
42+
43+
44+
def test_no_update_mixin():
45+
class M(NoUpdateMixin):
46+
pass
47+
48+
obj = M()
49+
assert hasattr(obj, "get")
50+
assert hasattr(obj, "list")
51+
assert hasattr(obj, "create")
52+
assert not hasattr(obj, "update")
53+
assert hasattr(obj, "delete")
54+
assert isinstance(obj, ListMixin)
55+
assert isinstance(obj, GetMixin)
56+
assert isinstance(obj, CreateMixin)
57+
assert not isinstance(obj, UpdateMixin)
58+
assert isinstance(obj, DeleteMixin)

0 commit comments

Comments
 (0)