Commit eb64d069 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Utilities to run tests with python-gitlab

The API handle (`gitlab.Gitlab` instance) can be retrieved on
a `User` instance with `user.python_gitlab_client`).

Since there are several GitLab API client libraries for Python,
this raises the question whether we should make this
conditional, and how to make variants if they cannot be installed
in the same virtualenv (that's probably the case)
parent 091e38ed63dd
......@@ -3,6 +3,8 @@ import logging
import requests
import time
from gitlab import Gitlab # python-gitlab
logger = logging.getLogger(__name__)
......@@ -16,6 +18,7 @@ class User(object):
id = attr.ib()
heptapod = attr.ib(repr=False)
password = attr.ib(default=None, repr=False)
_python_gitlab_client = attr.ib(default=None, repr=False)
@classmethod
def create(cls, heptapod, name, password=None, fullname=None, **kw):
......@@ -241,6 +244,18 @@ class User(object):
logger.info("%r: access token generated in %.2f seconds",
self, time.time() - start)
@property
def python_gitlab_client(self):
"""Return the API client from the python-gitlab library
See https://python-gitlab.readthedocs.io
"""
cl = self._python_gitlab_client
if cl is None:
cl = self._python_gitlab_client = Gitlab(self.heptapod.url,
private_token=self.token)
return cl
def __enter__(self):
return self
......
......@@ -9,6 +9,7 @@ deps =
selenium
pytest-parallel
pytest-shard
python-gitlab
commands =
py.test {posargs}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment