29
29
30
30
31
31
class FakeChildObject (GitlabObject ):
32
- _url = "/fake"
32
+ _url = "/fake/%(parent_id)s/fakechild"
33
+ requiredCreateAttrs = ['name' ]
34
+ requiredUrlAttrs = ['parent_id' ]
33
35
34
36
35
37
class FakeChildManager (BaseManager ):
@@ -38,7 +40,8 @@ class FakeChildManager(BaseManager):
38
40
39
41
class FakeObject (GitlabObject ):
40
42
_url = "/fake"
41
- managers = [('children' , FakeChildManager , [('child_id' , 'id' )])]
43
+ requiredCreateAttrs = ['name' ]
44
+ managers = [('children' , FakeChildManager , [('parent_id' , 'id' )])]
42
45
43
46
44
47
class FakeObjectManager (BaseManager ):
@@ -51,6 +54,23 @@ def setUp(self):
51
54
email = "testuser@test.com" ,
52
55
password = "testpassword" , ssl_verify = True )
53
56
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
+
54
74
def test_constructor (self ):
55
75
self .assertRaises (AttributeError , BaseManager , self .gitlab )
56
76
@@ -128,7 +148,7 @@ def resp_get(url, request):
128
148
def test_create (self ):
129
149
mgr = FakeObjectManager (self .gitlab )
130
150
FakeObject .canCreate = False
131
- self .assertRaises (NotImplementedError , mgr .create , {'foo ' : 'bar ' })
151
+ self .assertRaises (NotImplementedError , mgr .create , {'name ' : 'name ' })
132
152
133
153
@urlmatch (scheme = "http" , netloc = "localhost" , path = "/api/v3/fake" ,
134
154
method = "post" )
0 commit comments