summaryrefslogtreecommitdiff
path: root/gitlab/tests
diff options
context:
space:
mode:
Diffstat (limited to 'gitlab/tests')
-rw-r--r--gitlab/tests/test_base.py80
-rw-r--r--gitlab/tests/test_cli.py65
-rw-r--r--gitlab/tests/test_config.py46
-rw-r--r--gitlab/tests/test_gitlab.py444
-rw-r--r--gitlab/tests/test_mixins.py239
-rw-r--r--gitlab/tests/test_types.py30
6 files changed, 486 insertions, 418 deletions
diff --git a/gitlab/tests/test_base.py b/gitlab/tests/test_base.py
index d38c507..2526bee 100644
--- a/gitlab/tests/test_base.py
+++ b/gitlab/tests/test_base.py
@@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pickle
+
try:
import unittest
except ImportError:
@@ -34,23 +35,23 @@ class FakeObject(base.RESTObject):
class FakeManager(base.RESTManager):
_obj_cls = FakeObject
- _path = '/tests'
+ _path = "/tests"
class TestRESTManager(unittest.TestCase):
def test_computed_path_simple(self):
class MGR(base.RESTManager):
- _path = '/tests'
+ _path = "/tests"
_obj_cls = object
mgr = MGR(FakeGitlab())
- self.assertEqual(mgr._computed_path, '/tests')
+ self.assertEqual(mgr._computed_path, "/tests")
def test_computed_path_with_parent(self):
class MGR(base.RESTManager):
- _path = '/tests/%(test_id)s/cases'
+ _path = "/tests/%(test_id)s/cases"
_obj_cls = object
- _from_parent_attrs = {'test_id': 'id'}
+ _from_parent_attrs = {"test_id": "id"}
class Parent(object):
id = 42
@@ -59,15 +60,15 @@ class TestRESTManager(unittest.TestCase):
no_id = 0
mgr = MGR(FakeGitlab(), parent=Parent())
- self.assertEqual(mgr._computed_path, '/tests/42/cases')
+ self.assertEqual(mgr._computed_path, "/tests/42/cases")
def test_path_property(self):
class MGR(base.RESTManager):
- _path = '/tests'
+ _path = "/tests"
_obj_cls = object
mgr = MGR(FakeGitlab())
- self.assertEqual(mgr.path, '/tests')
+ self.assertEqual(mgr.path, "/tests")
class TestRESTObject(unittest.TestCase):
@@ -76,36 +77,36 @@ class TestRESTObject(unittest.TestCase):
self.manager = FakeManager(self.gitlab)
def test_instanciate(self):
- obj = FakeObject(self.manager, {'foo': 'bar'})
+ obj = FakeObject(self.manager, {"foo": "bar"})
- self.assertDictEqual({'foo': 'bar'}, obj._attrs)
+ self.assertDictEqual({"foo": "bar"}, obj._attrs)
self.assertDictEqual({}, obj._updated_attrs)
self.assertEqual(None, obj._create_managers())
self.assertEqual(self.manager, obj.manager)
self.assertEqual(self.gitlab, obj.manager.gitlab)
def test_pickability(self):
- obj = FakeObject(self.manager, {'foo': 'bar'})
+ obj = FakeObject(self.manager, {"foo": "bar"})
original_obj_module = obj._module
pickled = pickle.dumps(obj)
unpickled = pickle.loads(pickled)
self.assertIsInstance(unpickled, FakeObject)
- self.assertTrue(hasattr(unpickled, '_module'))
+ self.assertTrue(hasattr(unpickled, "_module"))
self.assertEqual(unpickled._module, original_obj_module)
def test_attrs(self):
- obj = FakeObject(self.manager, {'foo': 'bar'})
+ obj = FakeObject(self.manager, {"foo": "bar"})
- self.assertEqual('bar', obj.foo)
- self.assertRaises(AttributeError, getattr, obj, 'bar')
+ self.assertEqual("bar", obj.foo)
+ self.assertRaises(AttributeError, getattr, obj, "bar")
- obj.bar = 'baz'
- self.assertEqual('baz', obj.bar)
- self.assertDictEqual({'foo': 'bar'}, obj._attrs)
- self.assertDictEqual({'bar': 'baz'}, obj._updated_attrs)
+ obj.bar = "baz"
+ self.assertEqual("baz", obj.bar)
+ self.assertDictEqual({"foo": "bar"}, obj._attrs)
+ self.assertDictEqual({"bar": "baz"}, obj._updated_attrs)
def test_get_id(self):
- obj = FakeObject(self.manager, {'foo': 'bar'})
+ obj = FakeObject(self.manager, {"foo": "bar"})
obj.id = 42
self.assertEqual(42, obj.get_id())
@@ -114,50 +115,47 @@ class TestRESTObject(unittest.TestCase):
def test_custom_id_attr(self):
class OtherFakeObject(FakeObject):
- _id_attr = 'foo'
+ _id_attr = "foo"
- obj = OtherFakeObject(self.manager, {'foo': 'bar'})
- self.assertEqual('bar', obj.get_id())
+ obj = OtherFakeObject(self.manager, {"foo": "bar"})
+ self.assertEqual("bar", obj.get_id())
def test_update_attrs(self):
- obj = FakeObject(self.manager, {'foo': 'bar'})
- obj.bar = 'baz'
- obj._update_attrs({'foo': 'foo', 'bar': 'bar'})
- self.assertDictEqual({'foo': 'foo', 'bar': 'bar'}, obj._attrs)
+ obj = FakeObject(self.manager, {"foo": "bar"})
+ obj.bar = "baz"
+ obj._update_attrs({"foo": "foo", "bar": "bar"})
+ self.assertDictEqual({"foo": "foo", "bar": "bar"}, obj._attrs)
self.assertDictEqual({}, obj._updated_attrs)
def test_create_managers(self):
class ObjectWithManager(FakeObject):
- _managers = (('fakes', 'FakeManager'), )
+ _managers = (("fakes", "FakeManager"),)
- obj = ObjectWithManager(self.manager, {'foo': 'bar'})
+ obj = ObjectWithManager(self.manager, {"foo": "bar"})
obj.id = 42
self.assertIsInstance(obj.fakes, FakeManager)
self.assertEqual(obj.fakes.gitlab, self.gitlab)
self.assertEqual(obj.fakes._parent, obj)
def test_equality(self):
- obj1 = FakeObject(self.manager, {'id': 'foo'})
- obj2 = FakeObject(self.manager, {'id': 'foo', 'other_attr': 'bar'})
+ obj1 = FakeObject(self.manager, {"id": "foo"})
+ obj2 = FakeObject(self.manager, {"id": "foo", "other_attr": "bar"})
self.assertEqual(obj1, obj2)
def test_equality_custom_id(self):
class OtherFakeObject(FakeObject):
- _id_attr = 'foo'
+ _id_attr = "foo"
- obj1 = OtherFakeObject(self.manager, {'foo': 'bar'})
- obj2 = OtherFakeObject(
- self.manager,
- {'foo': 'bar', 'other_attr': 'baz'}
- )
+ obj1 = OtherFakeObject(self.manager, {"foo": "bar"})
+ obj2 = OtherFakeObject(self.manager, {"foo": "bar", "other_attr": "baz"})
self.assertEqual(obj1, obj2)
def test_inequality(self):
- obj1 = FakeObject(self.manager, {'id': 'foo'})
- obj2 = FakeObject(self.manager, {'id': 'bar'})
+ obj1 = FakeObject(self.manager, {"id": "foo"})
+ obj2 = FakeObject(self.manager, {"id": "bar"})
self.assertNotEqual(obj1, obj2)
def test_inequality_no_id(self):
- obj1 = FakeObject(self.manager, {'attr1': 'foo'})
- obj2 = FakeObject(self.manager, {'attr1': 'bar'})
+ obj1 = FakeObject(self.manager, {"attr1": "foo"})
+ obj2 = FakeObject(self.manager, {"attr1": "bar"})
self.assertNotEqual(obj1, obj2)
diff --git a/gitlab/tests/test_cli.py b/gitlab/tests/test_cli.py
index 3fe4a4e..bc49d8b 100644
--- a/gitlab/tests/test_cli.py
+++ b/gitlab/tests/test_cli.py
@@ -22,6 +22,7 @@ from __future__ import absolute_import
import argparse
import os
import tempfile
+
try:
from contextlib import redirect_stderr # noqa: H302
except ImportError:
@@ -34,6 +35,7 @@ except ImportError:
yield
sys.stderr = old_target
+
try:
import unittest
except ImportError:
@@ -69,8 +71,8 @@ class TestCLI(unittest.TestCase):
self.assertEqual(test.exception.code, 1)
def test_parse_value(self):
- ret = cli._parse_value('foobar')
- self.assertEqual(ret, 'foobar')
+ ret = cli._parse_value("foobar")
+ self.assertEqual(ret, "foobar")
ret = cli._parse_value(True)
self.assertEqual(ret, True)
@@ -82,36 +84,39 @@ class TestCLI(unittest.TestCase):
self.assertEqual(ret, None)
fd, temp_path = tempfile.mkstemp()
- os.write(fd, b'content')
+ os.write(fd, b"content")
os.close(fd)
- ret = cli._parse_value('@%s' % temp_path)
- self.assertEqual(ret, 'content')
+ ret = cli._parse_value("@%s" % temp_path)
+ self.assertEqual(ret, "content")
os.unlink(temp_path)
fl = six.StringIO()
with redirect_stderr(fl):
with self.assertRaises(SystemExit) as exc:
- cli._parse_value('@/thisfileprobablydoesntexist')
- self.assertEqual(fl.getvalue(),
- "[Errno 2] No such file or directory:"
- " '/thisfileprobablydoesntexist'\n")
+ cli._parse_value("@/thisfileprobablydoesntexist")
+ self.assertEqual(
+ fl.getvalue(),
+ "[Errno 2] No such file or directory:"
+ " '/thisfileprobablydoesntexist'\n",
+ )
self.assertEqual(exc.exception.code, 1)
def test_base_parser(self):
parser = cli._get_base_parser()
- args = parser.parse_args(['-v', '-g', 'gl_id',
- '-c', 'foo.cfg', '-c', 'bar.cfg'])
+ args = parser.parse_args(
+ ["-v", "-g", "gl_id", "-c", "foo.cfg", "-c", "bar.cfg"]
+ )
self.assertTrue(args.verbose)
- self.assertEqual(args.gitlab, 'gl_id')
- self.assertEqual(args.config_file, ['foo.cfg', 'bar.cfg'])
+ self.assertEqual(args.gitlab, "gl_id")
+ self.assertEqual(args.config_file, ["foo.cfg", "bar.cfg"])
class TestV4CLI(unittest.TestCase):
def test_parse_args(self):
parser = cli._get_parser(gitlab.v4.cli)
- args = parser.parse_args(['project', 'list'])
- self.assertEqual(args.what, 'project')
- self.assertEqual(args.action, 'list')
+ args = parser.parse_args(["project", "list"])
+ self.assertEqual(args.what, "project")
+ self.assertEqual(args.action, "list")
def test_parser(self):
parser = cli._get_parser(gitlab.v4.cli)
@@ -121,29 +126,29 @@ class TestV4CLI(unittest.TestCase):
subparsers = action
break
self.assertIsNotNone(subparsers)
- self.assertIn('project', subparsers.choices)
+ self.assertIn("project", subparsers.choices)
user_subparsers = None
- for action in subparsers.choices['project']._actions:
+ for action in subparsers.choices["project"]._actions:
if type(action) == argparse._SubParsersAction:
user_subparsers = action
break
self.assertIsNotNone(user_subparsers)
- self.assertIn('list', user_subparsers.choices)
- self.assertIn('get', user_subparsers.choices)
- self.assertIn('delete', user_subparsers.choices)
- self.assertIn('update', user_subparsers.choices)
- self.assertIn('create', user_subparsers.choices)
- self.assertIn('archive', user_subparsers.choices)
- self.assertIn('unarchive', user_subparsers.choices)
+ self.assertIn("list", user_subparsers.choices)
+ self.assertIn("get", user_subparsers.choices)
+ self.assertIn("delete", user_subparsers.choices)
+ self.assertIn("update", user_subparsers.choices)
+ self.assertIn("create", user_subparsers.choices)
+ self.assertIn("archive", user_subparsers.choices)
+ self.assertIn("unarchive", user_subparsers.choices)
- actions = user_subparsers.choices['create']._option_string_actions
- self.assertFalse(actions['--description'].required)
+ actions = user_subparsers.choices["create"]._option_string_actions
+ self.assertFalse(actions["--description"].required)
user_subparsers = None
- for action in subparsers.choices['group']._actions:
+ for action in subparsers.choices["group"]._actions:
if type(action) == argparse._SubParsersAction:
user_subparsers = action
break
- actions = user_subparsers.choices['create']._option_string_actions
- self.assertTrue(actions['--name'].required)
+ actions = user_subparsers.choices["create"]._option_string_actions
+ self.assertTrue(actions["--name"].required)
diff --git a/gitlab/tests/test_config.py b/gitlab/tests/test_config.py
index d1e668e..9e19ce8 100644
--- a/gitlab/tests/test_config.py
+++ b/gitlab/tests/test_config.py
@@ -76,51 +76,51 @@ per_page = 200
class TestConfigParser(unittest.TestCase):
- @mock.patch('os.path.exists')
+ @mock.patch("os.path.exists")
def test_missing_config(self, path_exists):
path_exists.return_value = False
with self.assertRaises(config.GitlabConfigMissingError):
- config.GitlabConfigParser('test')
+ config.GitlabConfigParser("test")
- @mock.patch('os.path.exists')
- @mock.patch('six.moves.builtins.open')
+ @mock.patch("os.path.exists")
+ @mock.patch("six.moves.builtins.open")
def test_invalid_id(self, m_open, path_exists):
fd = six.StringIO(no_default_config)
fd.close = mock.Mock(return_value=None)
m_open.return_value = fd
path_exists.return_value = True
- config.GitlabConfigParser('there')
+ config.GitlabConfigParser("there")
self.assertRaises(config.GitlabIDError, config.GitlabConfigParser)
fd = six.StringIO(valid_config)
fd.close = mock.Mock(return_value=None)
m_open.return_value = fd
- self.assertRaises(config.GitlabDataError,
- config.GitlabConfigParser,
- gitlab_id='not_there')
+ self.assertRaises(
+ config.GitlabDataError, config.GitlabConfigParser, gitlab_id="not_there"
+ )
- @mock.patch('os.path.exists')
- @mock.patch('six.moves.builtins.open')
+ @mock.patch("os.path.exists")
+ @mock.patch("six.moves.builtins.open")
def test_invalid_data(self, m_open, path_exists):
fd = six.StringIO(missing_attr_config)
- fd.close = mock.Mock(return_value=None,
- side_effect=lambda: fd.seek(0))
+ fd.close = mock.Mock(return_value=None, side_effect=lambda: fd.seek(0))
m_open.return_value = fd
path_exists.return_value = True
- config.GitlabConfigParser('one')
- config.GitlabConfigParser('one')
- self.assertRaises(config.GitlabDataError, config.GitlabConfigParser,
- gitlab_id='two')
- self.assertRaises(config.GitlabDataError, config.GitlabConfigParser,
- gitlab_id='three')
+ config.GitlabConfigParser("one")
+ config.GitlabConfigParser("one")
+ self.assertRaises(
+ config.GitlabDataError, config.GitlabConfigParser, gitlab_id="two"
+ )
+ self.assertRaises(
+ config.GitlabDataError, config.GitlabConfigParser, gitlab_id="three"
+ )
with self.assertRaises(config.GitlabDataError) as emgr:
- config.GitlabConfigParser('four')
- self.assertEqual('Unsupported per_page number: 200',
- emgr.exception.args[0])
+ config.GitlabConfigParser("four")
+ self.assertEqual("Unsupported per_page number: 200", emgr.exception.args[0])
- @mock.patch('os.path.exists')
- @mock.patch('six.moves.builtins.open')
+ @mock.patch("os.path.exists")
+ @mock.patch("six.moves.builtins.open")
def test_valid_data(self, m_open, path_exists):
fd = six.StringIO(valid_config)
fd.close = mock.Mock(return_value=None)
diff --git a/gitlab/tests/test_gitlab.py b/gitlab/tests/test_gitlab.py
index fddd5ed..c2b372a 100644
--- a/gitlab/tests/test_gitlab.py
+++ b/gitlab/tests/test_gitlab.py
@@ -21,6 +21,7 @@ from __future__ import print_function
import os
import pickle
import tempfile
+
try:
import unittest
except ImportError:
@@ -64,42 +65,52 @@ class TestSanitize(unittest.TestCase):
class TestGitlabList(unittest.TestCase):
def setUp(self):
- self.gl = Gitlab("http://localhost", private_token="private_token",
- api_version=4)
+ self.gl = Gitlab(
+ "http://localhost", private_token="private_token", api_version=4
+ )
def test_build_list(self):
- @urlmatch(scheme='http', netloc="localhost", path="/api/v4/tests",
- method="get")
+ @urlmatch(scheme="http", netloc="localhost", path="/api/v4/tests", method="get")
def resp_1(url, request):
- headers = {'content-type': 'application/json',
- 'X-Page': 1,
- 'X-Next-Page': 2,
- 'X-Per-Page': 1,
- 'X-Total-Pages': 2,
- 'X-Total': 2,
- 'Link': (
- '<http://localhost/api/v4/tests?per_page=1&page=2>;'
- ' rel="next"')}
+ headers = {
+ "content-type": "application/json",
+ "X-Page": 1,
+ "X-Next-Page": 2,
+ "X-Per-Page": 1,
+ "X-Total-Pages": 2,
+ "X-Total": 2,
+ "Link": (
+ "<http://localhost/api/v4/tests?per_page=1&page=2>;" ' rel="next"'
+ ),
+ }
content = '[{"a": "b"}]'
return response(200, content, headers, None, 5, request)
- @urlmatch(scheme='http', netloc="localhost", path="/api/v4/tests",
- method='get', query=r'.*page=2')
+ @urlmatch(
+ scheme="http",
+ netloc="localhost",
+ path="/api/v4/tests",
+ method="get",
+ query=r".*page=2",
+ )
def resp_2(url, request):
- headers = {'content-type': 'application/json',
- 'X-Page': 2,
- 'X-Next-Page': 2,
- 'X-Per-Page': 1,
- 'X-Total-Pages': 2,
- 'X-Total': 2}
+ headers = {
+ "content-type": "application/json",
+ "X-Page": 2,
+ "X-Next-Page": 2,
+ "X-Per-Page": 1,
+ "X-Total-Pages": 2,
+ "X-Total": 2,
+ }
content = '[{"c": "d"}]'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_1):
- obj = self.gl.http_list('/tests', as_list=False)
+ obj = self.gl.http_list("/tests", as_list=False)
self.assertEqual(len(obj), 2)
- self.assertEqual(obj._next_url,
- 'http://localhost/api/v4/tests?per_page=1&page=2')
+ self.assertEqual(
+ obj._next_url, "http://localhost/api/v4/tests?per_page=1&page=2"
+ )
self.assertEqual(obj.current_page, 1)
self.assertEqual(obj.prev_page, None)
self.assertEqual(obj.next_page, 2)
@@ -110,306 +121,343 @@ class TestGitlabList(unittest.TestCase):
with HTTMock(resp_2):
l = list(obj)
self.assertEqual(len(l), 2)
- self.assertEqual(l[0]['a'], 'b')
- self.assertEqual(l[1]['c'], 'd')
+ self.assertEqual(l[0]["a"], "b")
+ self.assertEqual(l[1]["c"], "d")
class TestGitlabHttpMethods(unittest.TestCase):
def setUp(self):
- self.gl = Gitlab("http://localhost", private_token="private_token",
- api_version=4)
+ self.gl = Gitlab(
+ "http://localhost", private_token="private_token", api_version=4
+ )
def test_build_url(self):
- r = self.gl._build_url('http://localhost/api/v4')
- self.assertEqual(r, 'http://localhost/api/v4')
- r = self.gl._build_url('https://localhost/api/v4')
- self.assertEqual(r, 'https://localhost/api/v4')
- r = self.gl._build_url('/projects')
- self.assertEqual(r, 'http://localhost/api/v4/projects')
+ r = self.gl._build_url("http://localhost/api/v4")
+ self.assertEqual(r, "http://localhost/api/v4")
+ r = self.gl._build_url("https://localhost/api/v4")
+ self.assertEqual(r, "https://localhost/api/v4")
+ r = self.gl._build_url("/projects")
+ self.assertEqual(r, "http://localhost/api/v4/projects")
def test_http_request(self):
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects",
- method="get")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/projects", method="get"
+ )
def resp_cont(url, request):
- headers = {'content-type': 'application/json'}
+ headers = {"content-type": "application/json"}
content = '[{"name": "project1"}]'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
- http_r = self.gl.http_request('get', '/projects')
+ http_r = self.gl.http_request("get", "/projects")
http_r.json()
self.assertEqual(http_r.status_code, 200)
def test_http_request_404(self):
- @urlmatch(scheme="http", netloc="localhost",
- path="/api/v4/not_there", method="get")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/not_there", method="get"
+ )
def resp_cont(url, request):
- content = {'Here is wh it failed'}
+ content = {"Here is wh it failed"}
return response(404, content, {}, None, 5, request)
with HTTMock(resp_cont):
- self.assertRaises(GitlabHttpError,
- self.gl.http_request,
- 'get', '/not_there')
+ self.assertRaises(
+ GitlabHttpError, self.gl.http_request, "get", "/not_there"
+ )
def test_get_request(self):
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects",
- method="get")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/projects", method="get"
+ )
def resp_cont(url, request):
- headers = {'content-type': 'application/json'}
+ headers = {"content-type": "application/json"}
content = '{"name": "project1"}'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
- result = self.gl.http_get('/projects')
+ result = self.gl.http_get("/projects")
self.assertIsInstance(result, dict)
- self.assertEqual(result['name'], 'project1')
+ self.assertEqual(result["name"], "project1")
def test_get_request_raw(self):
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects",
- method="get")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/projects", method="get"
+ )
def resp_cont(url, request):
- headers = {'content-type': 'application/octet-stream'}
- content = 'content'
+ headers = {"content-type": "application/octet-stream"}
+ content = "content"
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
- result = self.gl.http_get('/projects')
- self.assertEqual(result.content.decode('utf-8'), 'content')
+ result = self.gl.http_get("/projects")
+ self.assertEqual(result.content.decode("utf-8"), "content")
def test_get_request_404(self):
- @urlmatch(scheme="http", netloc="localhost",
- path="/api/v4/not_there", method="get")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/not_there", method="get"
+ )
def resp_cont(url, request):
- content = {'Here is wh it failed'}
+ content = {"Here is wh it failed"}
return response(404, content, {}, None, 5, request)
with HTTMock(resp_cont):
- self.assertRaises(GitlabHttpError, self.gl.http_get, '/not_there')
+ self.assertRaises(GitlabHttpError, self.gl.http_get, "/not_there")
def test_get_request_invalid_data(self):
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects",
- method="get")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/projects", method="get"
+ )
def resp_cont(url, request):
- headers = {'content-type': 'application/json'}
+ headers = {"content-type": "application/json"}
content = '["name": "project1"]'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
- self.assertRaises(GitlabParsingError, self.gl.http_get,
- '/projects')
+ self.assertRaises(GitlabParsingError, self.gl.http_get, "/projects")
def test_list_request(self):
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects",
- method="get")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/projects", method="get"
+ )
def resp_cont(url, request):
- headers = {'content-type': 'application/json', 'X-Total': 1}
+ headers = {"content-type": "application/json", "X-Total": 1}
content = '[{"name": "project1"}]'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
- result = self.gl.http_list('/projects', as_list=True)
+ result = self.gl.http_list("/projects", as_list=True)
self.assertIsInstance(result, list)
self.assertEqual(len(result), 1)
with HTTMock(resp_cont):
- result = self.gl.http_list('/projects', as_list=False)
+ result = self.gl.http_list("/projects", as_list=False)
self.assertIsInstance(result, GitlabList)
self.assertEqual(len(result), 1)
with HTTMock(resp_cont):
- result = self.gl.http_list('/projects', all=True)
+ result = self.gl.http_list("/projects", all=True)
self.assertIsInstance(result, list)
self.assertEqual(len(result), 1)
def test_list_request_404(self):
- @urlmatch(scheme="http", netloc="localhost",
- path="/api/v4/not_there", method="get")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/not_there", method="get"
+ )
def resp_cont(url, request):
- content = {'Here is why it failed'}
+ content = {"Here is why it failed"}
return response(404, content, {}, None, 5, request)
with HTTMock(resp_cont):
- self.assertRaises(GitlabHttpError, self.gl.http_list, '/not_there')
+ self.assertRaises(GitlabHttpError, self.gl.http_list, "/not_there")
def test_list_request_invalid_data(self):
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects",
- method="get")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/projects", method="get"
+ )
def resp_cont(url, request):
- headers = {'content-type': 'application/json'}
+ headers = {"content-type": "application/json"}
content = '["name": "project1"]'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
- self.assertRaises(GitlabParsingError, self.gl.http_list,
- '/projects')
+ self.assertRaises(GitlabParsingError, self.gl.http_list, "/projects")
def test_post_request(self):
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects",
- method="post")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/projects", method="post"
+ )
def resp_cont(url, request):
- headers = {'content-type': 'application/json'}
+ headers = {"content-type": "application/json"}
content = '{"name": "project1"}'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
- result = self.gl.http_post('/projects')
+ result = self.gl.http_post("/projects")
self.assertIsInstance(result, dict)
- self.assertEqual(result['name'], 'project1')
+ self.assertEqual(result["name"], "project1")
def test_post_request_404(self):
- @urlmatch(scheme="http", netloc="localhost",
- path="/api/v4/not_there", method="post")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/not_there", method="post"
+ )
def resp_cont(url, request):
- content = {'Here is wh it failed'}
+ content = {"Here is wh it failed"}
return response(404, content, {}, None, 5, request)
with HTTMock(resp_cont):
- self.assertRaises(GitlabHttpError, self.gl.http_post, '/not_there')
+ self.assertRaises(GitlabHttpError, self.gl.http_post, "/not_there")
def test_post_request_invalid_data(self):
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects",
- method="post")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/projects", method="post"
+ )
def resp_cont(url, request):
- headers = {'content-type': 'application/json'}
+ headers = {"content-type": "application/json"}
content = '["name": "project1"]'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
- self.assertRaises(GitlabParsingError, self.gl.http_post,
- '/projects')
+ self.assertRaises(GitlabParsingError, self.gl.http_post, "/projects")
def test_put_request(self):
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects",
- method="put")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/projects", method="put"
+ )
def resp_cont(url, request):
- headers = {'content-type': 'application/json'}
+ headers = {"content-type": "application/json"}
content = '{"name": "project1"}'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
- result = self.gl.http_put('/projects')
+ result = self.gl.http_put("/projects")
self.assertIsInstance(result, dict)
- self.assertEqual(result['name'], 'project1')
+ self.assertEqual(result["name"], "project1")
def test_put_request_404(self):
- @urlmatch(scheme="http", netloc="localhost",
- path="/api/v4/not_there", method="put")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/not_there", method="put"
+ )
def resp_cont(url, request):
- content = {'Here is wh it failed'}
+ content = {"Here is wh it failed"}
return response(404, content, {}, None, 5, request)
with HTTMock(resp_cont):
- self.assertRaises(GitlabHttpError, self.gl.http_put, '/not_there')
+ self.assertRaises(GitlabHttpError, self.gl.http_put, "/not_there")
def test_put_request_invalid_data(self):
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects",
- method="put")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/projects", method="put"
+ )
def resp_cont(url, request):
- headers = {'content-type': 'application/json'}
+ headers = {"content-type": "application/json"}
content = '["name": "project1"]'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
- self.assertRaises(GitlabParsingError, self.gl.http_put,
- '/projects')
+ self.assertRaises(GitlabParsingError, self.gl.http_put, "/projects")
def test_delete_request(self):
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects",
- method="delete")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/projects", method="delete"
+ )
def resp_cont(url, request):
- headers = {'content-type': 'application/json'}
- content = 'true'
+ headers = {"content-type": "application/json"}
+ content = "true"
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
- result = self.gl.http_delete('/projects')
+ result = self.gl.http_delete("/projects")
self.assertIsInstance(result, requests.Response)
self.assertEqual(result.json(), True)
def test_delete_request_404(self):
- @urlmatch(scheme="http", netloc="localhost",
- path="/api/v4/not_there", method="delete")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/not_there", method="delete"
+ )
def resp_cont(url, request):
- content = {'Here is wh it failed'}
+ content = {"Here is wh it failed"}
return response(404, content, {}, None, 5, request)
with HTTMock(resp_cont):
- self.assertRaises(GitlabHttpError, self.gl.http_delete,
- '/not_there')
+ self.assertRaises(GitlabHttpError, self.gl.http_delete, "/not_there")
class TestGitlabAuth(unittest.TestCase):
def test_invalid_auth_args(self):
- self.assertRaises(ValueError,
- Gitlab,
- "http://localhost", api_version='4',
- private_token='private_token', oauth_token='bearer')
- self.assertRaises(ValueError,
- Gitlab,
- "http://localhost", api_version='4',
- oauth_token='bearer', http_username='foo',
- http_password='bar')
- self.assertRaises(ValueError,
- Gitlab,
- "http://localhost", api_version='4',
- private_token='private_token', http_password='bar')
- self.assertRaises(ValueError,
- Gitlab,
- "http://localhost", api_version='4',
- private_token='private_token', http_username='foo')
+ self.assertRaises(
+ ValueError,
+ Gitlab,
+ "http://localhost",
+ api_version="4",
+ private_token="private_token",
+ oauth_token="bearer",
+ )
+ self.assertRaises(
+ ValueError,
+ Gitlab,
+ "http://localhost",
+ api_version="4",
+ oauth_token="bearer",
+ http_username="foo",
+ http_password="bar",
+ )
+ self.assertRaises(
+ ValueError,
+ Gitlab,
+ "http://localhost",
+ api_version="4",
+ private_token="private_token",
+ http_password="bar",
+ )
+ self.assertRaises(
+ ValueError,
+ Gitlab,
+ "http://localhost",
+ api_version="4",
+ private_token="private_token",
+ http_username="foo",
+ )
def test_private_token_auth(self):
- gl = Gitlab('http://localhost', private_token='private_token',
- api_version='4')
- self.assertEqual(gl.private_token, 'private_token')
+ gl = Gitlab("http://localhost", private_token="private_token", api_version="4")
+ self.assertEqual(gl.private_token, "private_token")
self.assertEqual(gl.oauth_token, None)
self.assertEqual(gl._http_auth, None)
- self.assertEqual(gl.headers['PRIVATE-TOKEN'], 'private_token')
- self.assertNotIn('Authorization', gl.headers)
+ self.assertEqual(gl.headers["PRIVATE-TOKEN"], "private_token")
+ self.assertNotIn("Authorization", gl.headers)
def test_oauth_token_auth(self):
- gl = Gitlab('http://localhost', oauth_token='oauth_token',
- api_version='4')
+ gl = Gitlab("http://localhost", oauth_token="oauth_token", api_version="4")
self.assertEqual(gl.private_token, None)
- self.assertEqual(gl.oauth_token, 'oauth_token')
+ self.assertEqual(gl.oauth_token, "oauth_token")
self.assertEqual(gl._http_auth, None)
- self.assertEqual(gl.headers['Authorization'], 'Bearer oauth_token')
- self.assertNotIn('PRIVATE-TOKEN', gl.headers)
+ self.assertEqual(gl.headers["Authorization"], "Bearer oauth_token")
+ self.assertNotIn("PRIVATE-TOKEN", gl.headers)
def test_http_auth(self):
- gl = Gitlab('http://localhost', private_token='private_token',
- http_username='foo', http_password='bar', api_version='4')
- self.assertEqual(gl.private_token, 'private_token')
+ gl = Gitlab(
+ "http://localhost",
+ private_token="private_token",
+ http_username="foo",
+ http_password="bar",
+ api_version="4",
+ )
+ self.assertEqual(gl.private_token, "private_token")
self.assertEqual(gl.oauth_token, None)
self.assertIsInstance(gl._http_auth, requests.auth.HTTPBasicAuth)
- self.assertEqual(gl.headers['PRIVATE-TOKEN'], 'private_token')
- self.assertNotIn('Authorization', gl.headers)
+ self.assertEqual(gl.headers["PRIVATE-TOKEN"], "private_token")
+ self.assertNotIn("Authorization", gl.headers)
class TestGitlab(unittest.TestCase):
-
def setUp(self):
- self.gl = Gitlab("http://localhost", private_token="private_token",
- email="testuser@test.com", password="testpassword",
- ssl_verify=True, api_version=4)
+ self.gl = Gitlab(
+ "http://localhost",
+ private_token="private_token",
+ email="testuser@test.com",
+ password="testpassword",
+ ssl_verify=True,
+ api_version=4,
+ )
def test_pickability(self):
original_gl_objects = self.gl._objects
pickled = pickle.dumps(self.gl)
unpickled = pickle.loads(pickled)
self.assertIsInstance(unpickled, Gitlab)
- self.assertTrue(hasattr(unpickled, '_objects'))
+ self.assertTrue(hasattr(unpickled, "_objects"))
self.assertEqual(unpickled._objects, original_gl_objects)
def test_credentials_auth_nopassword(self):
self.gl.email = None
self.gl.password = None
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/session",
- method="post")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/session", method="post"
+ )
def resp_cont(url, request):
- headers = {'content-type': 'application/json'}
+ headers = {"content-type": "application/json"}
content = '{"message": "message"}'.encode("utf-8")
return response(404, content, headers, None, 5, request)
@@ -417,10 +465,11 @@ class TestGitlab(unittest.TestCase):
self.assertRaises(GitlabHttpError, self.gl._credentials_auth)
def test_credentials_auth_notok(self):
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/session",
- method="post")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/session", method="post"
+ )
def resp_cont(url, request):
- headers = {'content-type': 'application/json'}
+ headers = {"content-type": "application/json"}
content = '{"message": "message"}'.encode("utf-8")
return response(404, content, headers, None, 5, request)
@@ -441,12 +490,14 @@ class TestGitlab(unittest.TestCase):
id_ = 1
expected = {"PRIVATE-TOKEN": token}
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/session",
- method="post")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/session", method="post"
+ )
def resp_cont(url, request):
- headers = {'content-type': 'application/json'}
+ headers = {"content-type": "application/json"}
content = '{{"id": {0:d}, "private_token": "{1:s}"}}'.format(
- id_, token).encode("utf-8")
+ id_, token
+ ).encode("utf-8")
return response(201, content, headers, None, 5, request)
with HTTMock(resp_cont):
@@ -461,12 +512,12 @@ class TestGitlab(unittest.TestCase):
name = "username"
id_ = 1
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/user",
- method="get")
+ @urlmatch(scheme="http", netloc="localhost", path="/api/v4/user", method="get")
def resp_cont(url, request):
- headers = {'content-type': 'application/json'}
- content = '{{"id": {0:d}, "username": "{1:s}"}}'.format(
- id_, name).encode("utf-8")
+ headers = {"content-type": "application/json"}
+ content = '{{"id": {0:d}, "username": "{1:s}"}}'.format(id_, name).encode(
+ "utf-8"
+ )
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
@@ -476,10 +527,11 @@ class TestGitlab(unittest.TestCase):
self.assertEqual(type(self.gl.user), CurrentUser)
def test_hooks(self):
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/hooks/1",
- method="get")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/hooks/1", method="get"
+ )
def resp_get_hook(url, request):
- headers = {'content-type': 'application/json'}
+ headers = {"content-type": "application/json"}
content = '{"url": "testurl", "id": 1}'.encode("utf-8")
return response(200, content, headers, None, 5, request)
@@ -490,10 +542,11 @@ class TestGitlab(unittest.TestCase):
self.assertEqual(data.id, 1)
def test_projects(self):
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1",
- method="get")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/projects/1", method="get"
+ )
def resp_get_project(url, request):
- headers = {'content-type': 'application/json'}
+ headers = {"content-type": "application/json"}
content = '{"name": "name", "id": 1}'.encode("utf-8")
return response(200, content, headers, None, 5, request)
@@ -504,12 +557,13 @@ class TestGitlab(unittest.TestCase):
self.assertEqual(data.id, 1)
def test_groups(self):
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/groups/1",
- method="get")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/groups/1", method="get"
+ )
def resp_get_group(url, request):
- headers = {'content-type': 'application/json'}
+ headers = {"content-type": "application/json"}
content = '{"name": "name", "id": 1, "path": "path"}'
- content = content.encode('utf-8')
+ content = content.encode("utf-8")
return response(200, content, headers, None, 5, request)
with HTTMock(resp_get_group):
@@ -520,27 +574,30 @@ class TestGitlab(unittest.TestCase):
self.assertEqual(data.id, 1)
def test_issues(self):
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/issues",
- method="get")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/issues", method="get"
+ )
def resp_get_issue(url, request):
- headers = {'content-type': 'application/json'}
- content = ('[{"name": "name", "id": 1}, '
- '{"name": "other_name", "id": 2}]')
+ headers = {"content-type": "application/json"}
+ content = '[{"name": "name", "id": 1}, ' '{"name": "other_name", "id": 2}]'
content = content.encode("utf-8")
return response(200, content, headers, None, 5, request)
with HTTMock(resp_get_issue):
data = self.gl.issues.list()
self.assertEqual(data[1].id, 2)
- self.assertEqual(data[1].name, 'other_name')
+ self.assertEqual(data[1].name, "other_name")
def test_users(self):
- @urlmatch(scheme="http", netloc="localhost", path="/api/v4/users/1",
- method="get")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/users/1", method="get"
+ )
def resp_get_user(url, request):
- headers = {'content-type': 'application/json'}
- content = ('{"name": "name", "id": 1, "password": "password", '
- '"username": "username", "email": "email"}')
+ headers = {"content-type": "application/json"}
+ content = (
+ '{"name": "name", "id": 1, "password": "password", '
+ '"username": "username", "email": "email"}'
+ )
content = content.encode("utf-8")
return response(200, content, headers, None, 5, request)
@@ -558,13 +615,14 @@ class TestGitlab(unittest.TestCase):
def test_from_config(self):
config_path = self._default_config()
- gitlab.Gitlab.from_config('one', [config_path])
+ gitlab.Gitlab.from_config("one", [config_path])
os.unlink(config_path)
def test_subclass_from_config(self):
class MyGitlab(gitlab.Gitlab):
pass
+
config_path = self._default_config()
- gl = MyGitlab.from_config('one', [config_path])
- self.assertEqual(type(gl).__name__, 'MyGitlab')
+ gl = MyGitlab.from_config("one", [config_path])
+ self.assertEqual(type(gl).__name__, "MyGitlab")
os.unlink(config_path)
diff --git a/gitlab/tests/test_mixins.py b/gitlab/tests/test_mixins.py
index b3c2e81..56be8f3 100644
--- a/gitlab/tests/test_mixins.py
+++ b/gitlab/tests/test_mixins.py
@@ -38,47 +38,47 @@ class TestObjectMixinsAttributes(unittest.TestCase):
pass
obj = O()
- self.assertTrue(hasattr(obj, 'approve'))
+ self.assertTrue(hasattr(obj, "approve"))
def test_subscribable_mixin(self):
class O(SubscribableMixin):
pass
obj = O()
- self.assertTrue(hasattr(obj, 'subscribe'))
- self.assertTrue(hasattr(obj, 'unsubscribe'))
+ self.assertTrue(hasattr(obj, "subscribe"))
+ self.assertTrue(hasattr(obj, "unsubscribe"))
def test_todo_mixin(self):
class O(TodoMixin):
pass
obj = O()
- self.assertTrue(hasattr(obj, 'todo'))
+ self.assertTrue(hasattr(obj, "todo"))
def test_time_tracking_mixin(self):
class O(TimeTrackingMixin):
pass
obj = O()
- self.assertTrue(hasattr(obj, 'time_stats'))
- self.assertTrue(hasattr(obj, 'time_estimate'))
- self.assertTrue(hasattr(obj, 'reset_time_estimate'))
- self.assertTrue(hasattr(obj, 'add_spent_time'))
- self.assertTrue(hasattr(obj, 'reset_spent_time'))
+ self.assertTrue(hasattr(obj, "time_stats"))
+ self.assertTrue(hasattr(obj, "time_estimate"))
+ self.assertTrue(hasattr(obj, "reset_time_estimate"))
+ self.assertTrue(hasattr(obj, "add_spent_time"))
+ self.assertTrue(hasattr(obj, "reset_spent_time"))
def test_set_mixin(self):
class O(SetMixin):
pass
obj = O()
- self.assertTrue(hasattr(obj, 'set'))
+ self.assertTrue(hasattr(obj, "set"))
def test_user_agent_detail_mixin(self):
class O(UserAgentDetailMixin):
pass
obj = O()
- self.assertTrue(hasattr(obj, 'user_agent_detail'))
+ self.assertTrue(hasattr(obj, "user_agent_detail"))
class TestMetaMixins(unittest.TestCase):
@@ -87,11 +87,11 @@ class TestMetaMixins(unittest.TestCase):
pass
obj = M()
- self.assertTrue(hasattr(obj, 'list'))
- self.assertTrue(hasattr(obj, 'get'))
- self.assertFalse(hasattr(obj, 'create'))
- self.assertFalse(hasattr(obj, 'update'))
- self.assertFalse(hasattr(obj, 'delete'))
+ self.assertTrue(hasattr(obj, "list"))
+ self.assertTrue(hasattr(obj, "get"))
+ self.assertFalse(hasattr(obj, "create"))
+ self.assertFalse(hasattr(obj, "update"))
+ self.assertFalse(hasattr(obj, "delete"))
self.assertIsInstance(obj, ListMixin)
self.assertIsInstance(obj, GetMixin)
@@ -100,11 +100,11 @@ class TestMetaMixins(unittest.TestCase):
pass
obj = M()
- self.assertTrue(hasattr(obj, 'get'))
- self.assertTrue(hasattr(obj, 'list'))
- self.assertTrue(hasattr(obj, 'create'))
- self.assertTrue(hasattr(obj, 'update'))
- self.assertTrue(hasattr(obj, 'delete'))
+ self.assertTrue(hasattr(obj, "get"))
+ self.assertTrue(hasattr(obj, "list"))
+ self.assertTrue(hasattr(obj, "create"))
+ self.assertTrue(hasattr(obj, "update"))
+ self.assertTrue(hasattr(obj, "delete"))
self.assertIsInstance(obj, ListMixin)
self.assertIsInstance(obj, GetMixin)
self.assertIsInstance(obj, CreateMixin)
@@ -116,11 +116,11 @@ class TestMetaMixins(unittest.TestCase):
pass
obj = M()
- self.assertTrue(hasattr(obj, 'get'))
- self.assertTrue(hasattr(obj, 'list'))
- self.assertTrue(hasattr(obj, 'create'))
- self.assertFalse(hasattr(obj, 'update'))
- self.assertTrue(hasattr(obj, 'delete'))
+ self.assertTrue(hasattr(obj, "get"))
+ self.assertTrue(hasattr(obj, "list"))
+ self.assertTrue(hasattr(obj, "create"))
+ self.assertFalse(hasattr(obj, "update"))
+ self.assertTrue(hasattr(obj, "delete"))
self.assertIsInstance(obj, ListMixin)
self.assertIsInstance(obj, GetMixin)
self.assertIsInstance(obj, CreateMixin)
@@ -133,23 +133,25 @@ class FakeObject(base.RESTObject):
class FakeManager(base.RESTManager):
- _path = '/tests'
+ _path = "/tests"
_obj_cls = FakeObject
class TestMixinMethods(unittest.TestCase):
def setUp(self):
- self.gl = Gitlab("http://localhost", private_token="private_token",
- api_version=4)
+ self.gl = Gitlab(
+ "http://localhost", private_token="private_token", api_version=4
+ )
def test_get_mixin(self):
class M(GetMixin, FakeManager):
pass
- @urlmatch(scheme="http", netloc="localhost", path='/api/v4/tests/42',
- method="get")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/tests/42", method="get"
+ )
def resp_cont(url, request):
- headers = {'Content-Type': 'application/json'}
+ headers = {"Content-Type": "application/json"}
content = '{"id": 42, "foo": "bar"}'
return response(200, content, headers, None, 5, request)
@@ -157,36 +159,36 @@ class TestMixinMethods(unittest.TestCase):
mgr = M(self.gl)
obj = mgr.get(42)
self.assertIsInstance(obj, FakeObject)
- self.assertEqual(obj.foo, 'bar')
+ self.assertEqual(obj.foo, "bar")
self.assertEqual(obj.id, 42)
def test_refresh_mixin(self):
class O(RefreshMixin, FakeObject):
pass
- @urlmatch(scheme="http", netloc="localhost", path='/api/v4/tests/42',
- method="get")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/tests/42", method="get"
+ )
def resp_cont(url, request):
- headers = {'Content-Type': 'application/json'}
+ headers = {"Content-Type": "application/json"}
content = '{"id": 42, "foo": "bar"}'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
mgr = FakeManager(self.gl)
- obj = O(mgr, {'id': 42})
+ obj = O(mgr, {"id": 42})
res = obj.refresh()
self.assertIsNone(res)
- self.assertEqual(obj.foo, 'bar')
+ self.assertEqual(obj.foo, "bar")
self.assertEqual(obj.id, 42)
def test_get_without_id_mixin(self):
class M(GetWithoutIdMixin, FakeManager):
pass
- @urlmatch(scheme="http", netloc="localhost", path='/api/v4/tests',
- method="get")
+ @urlmatch(scheme="http", netloc="localhost", path="/api/v4/tests", method="get")
def resp_cont(url, request):
- headers = {'Content-Type': 'application/json'}
+ headers = {"Content-Type": "application/json"}
content = '{"foo": "bar"}'
return response(200, content, headers, None, 5, request)
@@ -194,17 +196,16 @@ class TestMixinMethods(unittest.TestCase):
mgr = M(self.gl)
obj = mgr.get()
self.assertIsInstance(obj, FakeObject)
- self.assertEqual(obj.foo, 'bar')
- self.assertFalse(hasattr(obj, 'id'))
+ self.assertEqual(obj.foo, "bar")
+ self.assertFalse(hasattr(obj, "id"))
def test_list_mixin(self):
class M(ListMixin, FakeManager):
pass
- @urlmatch(scheme="http", netloc="localhost", path='/api/v4/tests',
- method="get")
+ @urlmatch(scheme="http", netloc="localhost", path="/api/v4/tests", method="get")
def resp_cont(url, request):
- headers = {'Content-Type': 'application/json'}
+ headers = {"Content-Type": "application/json"}
content = '[{"id": 42, "foo": "bar"},{"id": 43, "foo": "baz"}]'
return response(200, content, headers, None, 5, request)
@@ -229,20 +230,21 @@ class TestMixinMethods(unittest.TestCase):
class M(ListMixin, FakeManager):
pass
- @urlmatch(scheme="http", netloc="localhost", path='/api/v4/others',
- method="get")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/others", method="get"
+ )
def resp_cont(url, request):
- headers = {'Content-Type': 'application/json'}
+ headers = {"Content-Type": "application/json"}
content = '[{"id": 42, "foo": "bar"}]'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
mgr = M(self.gl)
- obj_list = mgr.list(path='/others', as_list=False)
+ obj_list = mgr.list(path="/others", as_list=False)
self.assertIsInstance(obj_list, base.RESTObjectList)
obj = obj_list.next()
self.assertEqual(obj.id, 42)
- self.assertEqual(obj.foo, 'bar')
+ self.assertEqual(obj.foo, "bar")
self.assertRaises(StopIteration, obj_list.next)
def test_create_mixin_get_attrs(self):
@@ -250,8 +252,8 @@ class TestMixinMethods(unittest.TestCase):
pass
class M2(CreateMixin, FakeManager):
- _create_attrs = (('foo',), ('bar', 'baz'))
- _update_attrs = (('foo',), ('bam', ))
+ _create_attrs = (("foo",), ("bar", "baz"))
+ _update_attrs = (("foo",), ("bam",))
mgr = M1(self.gl)
required, optional = mgr.get_create_attrs()
@@ -260,69 +262,71 @@ class TestMixinMethods(unittest.TestCase):
mgr = M2(self.gl)
required, optional = mgr.get_create_attrs()
- self.assertIn('foo', required)
- self.assertIn('bar', optional)
- self.assertIn('baz', optional)
- self.assertNotIn('bam', optional)
+ self.assertIn("foo", required)
+ self.assertIn("bar", optional)
+ self.assertIn("baz", optional)
+ self.assertNotIn("bam", optional)
def test_create_mixin_missing_attrs(self):
class M(CreateMixin, FakeManager):
- _create_attrs = (('foo',), ('bar', 'baz'))
+ _create_attrs = (("foo",), ("bar", "baz"))
mgr = M(self.gl)
- data = {'foo': 'bar', 'baz': 'blah'}
+ data = {"foo": "bar", "baz": "blah"}
mgr._check_missing_create_attrs(data)
- data = {'baz': 'blah'}
+ data = {"baz": "blah"}
with self.assertRaises(AttributeError) as error:
mgr._check_missing_create_attrs(data)
- self.assertIn('foo', str(error.exception))
+ self.assertIn("foo", str(error.exception))
def test_create_mixin(self):
class M(CreateMixin, FakeManager):
- _create_attrs = (('foo',), ('bar', 'baz'))
- _update_attrs = (('foo',), ('bam', ))
+ _create_attrs = (("foo",), ("bar", "baz"))
+ _update_attrs = (("foo",), ("bam",))
- @urlmatch(scheme="http", netloc="localhost", path='/api/v4/tests',
- method="post")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/tests", method="post"
+ )
def resp_cont(url, request):
- headers = {'Content-Type': 'application/json'}
+ headers = {"Content-Type": "application/json"}
content = '{"id": 42, "foo": "bar"}'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
mgr = M(self.gl)
- obj = mgr.create({'foo': 'bar'})
+ obj = mgr.create({"foo": "bar"})
self.assertIsInstance(obj, FakeObject)
self.assertEqual(obj.id, 42)
- self.assertEqual(obj.foo, 'bar')
+ self.assertEqual(obj.foo, "bar")
def test_create_mixin_custom_path(self):
class M(CreateMixin, FakeManager):
- _create_attrs = (('foo',), ('bar', 'baz'))
- _update_attrs = (('foo',), ('bam', ))
+ _create_attrs = (("foo",), ("bar", "baz"))
+ _update_attrs = (("foo",), ("bam",))
- @urlmatch(scheme="http", netloc="localhost", path='/api/v4/others',
- method="post")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/others", method="post"
+ )
def resp_cont(url, request):
- headers = {'Content-Type': 'application/json'}
+ headers = {"Content-Type": "application/json"}
content = '{"id": 42, "foo": "bar"}'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
mgr = M(self.gl)
- obj = mgr.create({'foo': 'bar'}, path='/others')
+ obj = mgr.create({"foo": "bar"}, path="/others")
self.assertIsInstance(obj, FakeObject)
self.assertEqual(obj.id, 42)
- self.assertEqual(obj.foo, 'bar')
+ self.assertEqual(obj.foo, "bar")
def test_update_mixin_get_attrs(self):
class M1(UpdateMixin, FakeManager):
pass
class M2(UpdateMixin, FakeManager):
- _create_attrs = (('foo',), ('bar', 'baz'))
- _update_attrs = (('foo',), ('bam', ))
+ _create_attrs = (("foo",), ("bar", "baz"))
+ _update_attrs = (("foo",), ("bam",))
mgr = M1(self.gl)
required, optional = mgr.get_update_attrs()
@@ -331,70 +335,71 @@ class TestMixinMethods(unittest.TestCase):
mgr = M2(self.gl)
required, optional = mgr.get_update_attrs()
- self.assertIn('foo', required)
- self.assertIn('bam', optional)
- self.assertNotIn('bar', optional)
- self.assertNotIn('baz', optional)
+ self.assertIn("foo", required)
+ self.assertIn("bam", optional)
+ self.assertNotIn("bar", optional)
+ self.assertNotIn("baz", optional)
def test_update_mixin_missing_attrs(self):
class M(UpdateMixin, FakeManager):
- _update_attrs = (('foo',), ('bar', 'baz'))
+ _update_attrs = (("foo",), ("bar", "baz"))
mgr = M(self.gl)
- data = {'foo': 'bar', 'baz': 'blah'}
+ data = {"foo": "bar", "baz": "blah"}
mgr._check_missing_update_attrs(data)
- data = {'baz': 'blah'}
+ data = {"baz": "blah"}
with self.assertRaises(AttributeError) as error:
mgr._check_missing_update_attrs(data)
- self.assertIn('foo', str(error.exception))
+ self.assertIn("foo", str(error.exception))
def test_update_mixin(self):
class M(UpdateMixin, FakeManager):
- _create_attrs = (('foo',), ('bar', 'baz'))
- _update_attrs = (('foo',), ('bam', ))
+ _create_attrs = (("foo",), ("bar", "baz"))
+ _update_attrs = (("foo",), ("bam",))
- @urlmatch(scheme="http", netloc="localhost", path='/api/v4/tests/42',
- method="put")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/tests/42", method="put"
+ )
def resp_cont(url, request):
- headers = {'Content-Type': 'application/json'}
+ headers = {"Content-Type": "application/json"}
content = '{"id": 42, "foo": "baz"}'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
mgr = M(self.gl)
- server_data = mgr.update(42, {'foo': 'baz'})
+ server_data = mgr.update(42, {"foo": "baz"})
self.assertIsInstance(server_data, dict)
- self.assertEqual(server_data['id'], 42)
- self.assertEqual(server_data['foo'], 'baz')
+ self.assertEqual(server_data["id"], 42)
+ self.assertEqual(server_data["foo"], "baz")
def test_update_mixin_no_id(self):
class M(UpdateMixin, FakeManager):
- _create_attrs = (('foo',), ('bar', 'baz'))
- _update_attrs = (('foo',), ('bam', ))
+ _create_attrs = (("foo",), ("bar", "baz"))
+ _update_attrs = (("foo",), ("bam",))
- @urlmatch(scheme="http", netloc="localhost", path='/api/v4/tests',
- method="put")
+ @urlmatch(scheme="http", netloc="localhost", path="/api/v4/tests", method="put")
def resp_cont(url, request):
- headers = {'Content-Type': 'application/json'}
+ headers = {"Content-Type": "application/json"}
content = '{"foo": "baz"}'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
mgr = M(self.gl)
- server_data = mgr.update(new_data={'foo': 'baz'})
+ server_data = mgr.update(new_data={"foo": "baz"})
self.assertIsInstance(server_data, dict)
- self.assertEqual(server_data['foo'], 'baz')
+ self.assertEqual(server_data["foo"], "baz")
def test_delete_mixin(self):
class M(DeleteMixin, FakeManager):
pass
- @urlmatch(scheme="http", netloc="localhost", path='/api/v4/tests/42',
- method="delete")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/tests/42", method="delete"
+ )
def resp_cont(url, request):
- headers = {'Content-Type': 'application/json'}
- content = ''
+ headers = {"Content-Type": "application/json"}
+ content = ""
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
@@ -408,35 +413,37 @@ class TestMixinMethods(unittest.TestCase):
class O(SaveMixin, RESTObject):
pass
- @urlmatch(scheme="http", netloc="localhost", path='/api/v4/tests/42',
- method="put")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/tests/42", method="put"
+ )
def resp_cont(url, request):
- headers = {'Content-Type': 'application/json'}
+ headers = {"Content-Type": "application/json"}
content = '{"id": 42, "foo": "baz"}'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
mgr = M(self.gl)
- obj = O(mgr, {'id': 42, 'foo': 'bar'})
- obj.foo = 'baz'
+ obj = O(mgr, {"id": 42, "foo": "bar"})
+ obj.foo = "baz"
obj.save()
- self.assertEqual(obj._attrs['foo'], 'baz')
+ self.assertEqual(obj._attrs["foo"], "baz")
self.assertDictEqual(obj._updated_attrs, {})
def test_set_mixin(self):
class M(SetMixin, FakeManager):
pass
- @urlmatch(scheme="http", netloc="localhost", path='/api/v4/tests/foo',
- method="put")
+ @urlmatch(
+ scheme="http", netloc="localhost", path="/api/v4/tests/foo", method="put"
+ )
def resp_cont(url, request):
- headers = {'Content-Type': 'application/json'}
+ headers = {"Content-Type": "application/json"}
content = '{"key": "foo", "value": "bar"}'
return response(200, content, headers, None, 5, request)
with HTTMock(resp_cont):
mgr = M(self.gl)
- obj = mgr.set('foo', 'bar')
+ obj = mgr.set("foo", "bar")
self.assertIsInstance(obj, FakeObject)
- self.assertEqual(obj.key, 'foo')
- self.assertEqual(obj.value, 'bar')
+ self.assertEqual(obj.key, "foo")
+ self.assertEqual(obj.value, "bar")
diff --git a/gitlab/tests/test_types.py b/gitlab/tests/test_types.py
index c04f68f..4ce065e 100644
--- a/gitlab/tests/test_types.py
+++ b/gitlab/tests/test_types.py
@@ -25,13 +25,13 @@ from gitlab import types
class TestGitlabAttribute(unittest.TestCase):
def test_all(self):
- o = types.GitlabAttribute('whatever')
- self.assertEqual('whatever', o.get())
+ o = types.GitlabAttribute("whatever")
+ self.assertEqual("whatever", o.get())
- o.set_from_cli('whatever2')
- self.assertEqual('whatever2', o.get())
+ o.set_from_cli("whatever2")
+ self.assertEqual("whatever2", o.get())
- self.assertEqual('whatever2', o.get_for_api())
+ self.assertEqual("whatever2", o.get_for_api())
o = types.GitlabAttribute()
self.assertEqual(None, o._value)
@@ -40,27 +40,27 @@ class TestGitlabAttribute(unittest.TestCase):
class TestListAttribute(unittest.TestCase):
def test_list_input(self):
o = types.ListAttribute()
- o.set_from_cli('foo,bar,baz')
- self.assertEqual(['foo', 'bar', 'baz'], o.get())
+ o.set_from_cli("foo,bar,baz")
+ self.assertEqual(["foo", "bar", "baz"], o.get())
- o.set_from_cli('foo')
- self.assertEqual(['foo'], o.get())
+ o.set_from_cli("foo")
+ self.assertEqual(["foo"], o.get())
def test_empty_input(self):
o = types.ListAttribute()
- o.set_from_cli('')
+ o.set_from_cli("")
self.assertEqual([], o.get())
- o.set_from_cli(' ')
+ o.set_from_cli(" ")
self.assertEqual([], o.get())
def test_get_for_api(self):
o = types.ListAttribute()
- o.set_from_cli('foo,bar,baz')
- self.assertEqual('foo,bar,baz', o.get_for_api())
+ o.set_from_cli("foo,bar,baz")
+ self.assertEqual("foo,bar,baz", o.get_for_api())
class TestLowercaseStringAttribute(unittest.TestCase):
def test_get_for_api(self):
- o = types.LowercaseStringAttribute('FOO')
- self.assertEqual('foo', o.get_for_api())
+ o = types.LowercaseStringAttribute("FOO")
+ self.assertEqual("foo", o.get_for_api())