Skip to content

Commit 6baea2f

Browse files
author
Gauvain Pocentek
committed
add unit tests for managers
1 parent 7e54a39 commit 6baea2f

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

gitlab/tests/test_manager.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929

3030

3131
class FakeChildObject(GitlabObject):
32-
_url = "/fake"
32+
_url = "/fake/%(parent_id)s/fakechild"
33+
requiredCreateAttrs = ['name']
34+
requiredUrlAttrs = ['parent_id']
3335

3436

3537
class FakeChildManager(BaseManager):
@@ -38,7 +40,8 @@ class FakeChildManager(BaseManager):
3840

3941
class FakeObject(GitlabObject):
4042
_url = "/fake"
41-
managers = [('children', FakeChildManager, [('child_id', 'id')])]
43+
requiredCreateAttrs = ['name']
44+
managers = [('children', FakeChildManager, [('parent_id', 'id')])]
4245

4346

4447
class FakeObjectManager(BaseManager):
@@ -51,6 +54,23 @@ def setUp(self):
5154
email="testuser@test.com",
5255
password="testpassword", ssl_verify=True)
5356

57+
def test_set_parent_args(self):
58+
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/fake",
59+
method="POST")
60+
def resp_create(url, request):
61+
headers = {'content-type': 'application/json'}
62+
content = '{"id": 1, "name": "name"}'.encode("utf-8")
63+
return response(201, content, headers, None, 5, request)
64+
65+
mgr = FakeChildManager(self.gitlab)
66+
args = mgr._set_parent_args(name="name")
67+
self.assertEqual(args, {"name": "name"})
68+
69+
with HTTMock(resp_create):
70+
o = FakeObjectManager(self.gitlab).create({"name": "name"})
71+
args = o.children._set_parent_args(name="name")
72+
self.assertEqual(args, {"name": "name", "parent_id": 1})
73+
5474
def test_constructor(self):
5575
self.assertRaises(AttributeError, BaseManager, self.gitlab)
5676

@@ -128,7 +148,7 @@ def resp_get(url, request):
128148
def test_create(self):
129149
mgr = FakeObjectManager(self.gitlab)
130150
FakeObject.canCreate = False
131-
self.assertRaises(NotImplementedError, mgr.create, {'foo': 'bar'})
151+
self.assertRaises(NotImplementedError, mgr.create, {'name': 'name'})
132152

133153
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/fake",
134154
method="post")

0 commit comments

Comments
 (0)