Skip to content

Commit

Permalink
Merge pull request #1078 from python-gitlab/refactor/split-unit-tests
Browse files Browse the repository at this point in the history
Refactor: split unit tests by API resources
  • Loading branch information
max-wittig committed Aug 26, 2020
2 parents e2dc9ec + 204782a commit a7e44a0
Show file tree
Hide file tree
Showing 42 changed files with 2,778 additions and 2,617 deletions.
10 changes: 1 addition & 9 deletions gitlab/__init__.py
Expand Up @@ -45,14 +45,6 @@
ALLOWED_KEYSET_ENDPOINTS = ["/projects"]


def _sanitize(value):
if isinstance(value, dict):
return dict((k, _sanitize(v)) for k, v in value.items())
if isinstance(value, str):
return value.replace("/", "%2F")
return value


class Gitlab(object):
"""Represents a GitLab server connection.
Expand Down Expand Up @@ -322,7 +314,7 @@ def set_license(self, license, **kwargs):
def _construct_url(self, id_, obj, parameters, action=None):
if "next_url" in parameters:
return parameters["next_url"]
args = _sanitize(parameters)
args = utils.sanitize_parameters(parameters)

url_attr = "_url"
if action is not None:
Expand Down
1 change: 0 additions & 1 deletion gitlab/cli.py
Expand Up @@ -16,7 +16,6 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function

import argparse
import functools
Expand Down
40 changes: 40 additions & 0 deletions gitlab/tests/conftest.py
Expand Up @@ -10,3 +10,43 @@ def gl():
ssl_verify=True,
api_version=4,
)


# Todo: parametrize, but check what tests it's really useful for
@pytest.fixture
def gl_trailing():
return gitlab.Gitlab(
"http://localhost/", private_token="private_token", api_version=4
)


@pytest.fixture
def default_config(tmpdir):
valid_config = """[global]
default = one
ssl_verify = true
timeout = 2
[one]
url = http://one.url
private_token = ABCDEF
"""

config_path = tmpdir.join("python-gitlab.cfg")
config_path.write(valid_config)
return str(config_path)


@pytest.fixture
def group(gl):
return gl.groups.get(1, lazy=True)


@pytest.fixture
def project(gl):
return gl.projects.get(1, lazy=True)


@pytest.fixture
def user(gl):
return gl.users.get(1, lazy=True)
58 changes: 58 additions & 0 deletions gitlab/tests/mixins/test_meta_mixins.py
@@ -0,0 +1,58 @@
from gitlab.mixins import (
CreateMixin,
CRUDMixin,
DeleteMixin,
GetMixin,
ListMixin,
NoUpdateMixin,
UpdateMixin,
RetrieveMixin,
)


def test_retrieve_mixin():
class M(RetrieveMixin):
pass

obj = M()
assert hasattr(obj, "list")
assert hasattr(obj, "get")
assert not hasattr(obj, "create")
assert not hasattr(obj, "update")
assert not hasattr(obj, "delete")
assert isinstance(obj, ListMixin)
assert isinstance(obj, GetMixin)


def test_crud_mixin():
class M(CRUDMixin):
pass

obj = M()
assert hasattr(obj, "get")
assert hasattr(obj, "list")
assert hasattr(obj, "create")
assert hasattr(obj, "update")
assert hasattr(obj, "delete")
assert isinstance(obj, ListMixin)
assert isinstance(obj, GetMixin)
assert isinstance(obj, CreateMixin)
assert isinstance(obj, UpdateMixin)
assert isinstance(obj, DeleteMixin)


def test_no_update_mixin():
class M(NoUpdateMixin):
pass

obj = M()
assert hasattr(obj, "get")
assert hasattr(obj, "list")
assert hasattr(obj, "create")
assert not hasattr(obj, "update")
assert hasattr(obj, "delete")
assert isinstance(obj, ListMixin)
assert isinstance(obj, GetMixin)
assert isinstance(obj, CreateMixin)
assert not isinstance(obj, UpdateMixin)
assert isinstance(obj, DeleteMixin)

0 comments on commit a7e44a0

Please sign in to comment.