Skip to content

Commit fc8affd

Browse files
author
Gauvain Pocentek
committed
Fix Project.tree()
Add API tests for tree(), blob() and archive().
1 parent 141f21a commit fc8affd

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

gitlab/objects.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -1207,14 +1207,20 @@ def Tag(self, id=None, **kwargs):
12071207
**kwargs)
12081208

12091209
def tree(self, path='', ref_name='', **kwargs):
1210-
url = "%s/%s/repository/tree" % (self._url, self.id)
1211-
url += '?path=%s&ref_name=%s' % (path, ref_name)
1210+
url = "/projects/%s/repository/tree" % (self.id)
1211+
params = []
1212+
if path:
1213+
params.append("path=%s" % path)
1214+
if ref_name:
1215+
params.append("ref_name=%s" % ref_name)
1216+
if params:
1217+
url += '?' + "&".join(params)
12121218
r = self.gitlab._raw_get(url, **kwargs)
12131219
raise_error_from_response(r, GitlabGetError)
12141220
return r.json()
12151221

12161222
def blob(self, sha, filepath, **kwargs):
1217-
url = "%s/%s/repository/blobs/%s" % (self._url, self.id, sha)
1223+
url = "/projects/%s/repository/blobs/%s" % (self.id, sha)
12181224
url += '?filepath=%s' % (filepath)
12191225
r = self.gitlab._raw_get(url, **kwargs)
12201226
raise_error_from_response(r, GitlabGetError)

tools/python_test.py

+9
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@
121121
readme = admin_project.files.get(file_path='README.rst', ref='master')
122122
assert(readme.decode() == 'Initial content')
123123

124+
tree = admin_project.tree()
125+
assert(len(tree) == 1)
126+
assert(tree[0]['name'] == 'README.rst')
127+
blob = admin_project.blob('master', 'README.rst')
128+
assert(blob == 'Initial content')
129+
archive1 = admin_project.archive()
130+
archive2 = admin_project.archive('master')
131+
assert(archive1 == archive2)
132+
124133
# labels
125134
label1 = admin_project.labels.create({'name': 'label1', 'color': '#778899'})
126135
label1 = admin_project.labels.get('label1')

0 commit comments

Comments
 (0)