Skip to content

Commit 76b2cad

Browse files
committed
refactor: split unit tests by GitLab API resources
1 parent 11383e7 commit 76b2cad

34 files changed

+2645
-2447
lines changed

gitlab/__init__.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@
4545
ALLOWED_KEYSET_ENDPOINTS = ["/projects"]
4646

4747

48-
def _sanitize(value):
49-
if isinstance(value, dict):
50-
return dict((k, _sanitize(v)) for k, v in value.items())
51-
if isinstance(value, str):
52-
return value.replace("/", "%2F")
53-
return value
54-
55-
5648
class Gitlab(object):
5749
"""Represents a GitLab server connection.
5850
@@ -322,7 +314,7 @@ def set_license(self, license, **kwargs):
322314
def _construct_url(self, id_, obj, parameters, action=None):
323315
if "next_url" in parameters:
324316
return parameters["next_url"]
325-
args = _sanitize(parameters)
317+
args = utils.sanitize_parameters(parameters)
326318

327319
url_attr = "_url"
328320
if action is not None:

gitlab/tests/conftest.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,44 @@ def gl():
1010
ssl_verify=True,
1111
api_version=4,
1212
)
13+
14+
15+
# Todo: parametrize, but check what tests it's really useful for
16+
@pytest.fixture
17+
def gl_trailing():
18+
return gitlab.Gitlab(
19+
"http://localhost/",
20+
private_token="private_token",
21+
api_version=4
22+
)
23+
24+
25+
@pytest.fixture
26+
def default_config(tmpdir):
27+
valid_config = """[global]
28+
default = one
29+
ssl_verify = true
30+
timeout = 2
31+
32+
[one]
33+
url = http://one.url
34+
private_token = ABCDEF
35+
"""
36+
37+
config_path = tmpdir.join("python-gitlab.cfg")
38+
config_path.write(valid_config)
39+
return str(config_path)
40+
41+
@pytest.fixture
42+
def group(gl):
43+
return gl.groups.get(1, lazy=True)
44+
45+
46+
@pytest.fixture
47+
def project(gl):
48+
return gl.projects.get(1, lazy=True)
49+
50+
51+
@pytest.fixture
52+
def user(gl):
53+
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)