Skip to content

Commit 80c76e8

Browse files
Bug fix from get_files method. (#58)
1 parent 242cfe5 commit 80c76e8

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

centraldogma/content_service.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ def get_files(
5656
path += "/" + path_pattern
5757

5858
handler = {
59-
HTTPStatus.OK: lambda resp: [
60-
Content.from_dict(content) for content in resp.json()
61-
],
59+
HTTPStatus.OK: lambda resp: (
60+
lambda data: (
61+
[Content.from_dict(content) for content in data]
62+
if isinstance(data, list)
63+
else [Content.from_dict(data)]
64+
)
65+
)(resp.json()),
6266
HTTPStatus.NO_CONTENT: lambda resp: [],
6367
}
6468
return self.client.request("get", path, params=params, handler=handler)

tests/integration/test_content_service.py

+26
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,32 @@ def test_merge_files(self, run_around_test):
241241
assert ret.entry_type == EntryType.JSON
242242
assert ret.content == {"foo3": "bar3"}
243243

244+
def test_get_files_for_single_file(self, run_around_test):
245+
commit = Commit("Upsert dummy1-test.json")
246+
upsert_json = Change(
247+
"/test/dummy1-test.json", ChangeType.UPSERT_JSON, {"foo": "bar"}
248+
)
249+
dogma.push(project_name, repo_name, commit, [upsert_json])
250+
251+
ret = dogma.get_files(project_name, repo_name, "/test/dummy1-test.json")
252+
assert len(ret) == 1
253+
254+
def test_get_files_for_multiple_file(self, run_around_test):
255+
commit = Commit("Upsert dummy1-test.json")
256+
upsert_json = Change(
257+
"/dummy1-test.json", ChangeType.UPSERT_JSON, {"foo": "bar"}
258+
)
259+
dogma.push(project_name, repo_name, commit, [upsert_json])
260+
261+
commit = Commit("Upsert dummy2-test.json")
262+
upsert_json = Change(
263+
"/dummy2-test.json", ChangeType.UPSERT_JSON, {"foo": "bar"}
264+
)
265+
dogma.push(project_name, repo_name, commit, [upsert_json])
266+
267+
ret = dogma.get_files(project_name, repo_name, "/dummy*-test.json")
268+
assert len(ret) == 2
269+
244270
@staticmethod
245271
def push_later():
246272
time.sleep(1)

0 commit comments

Comments
 (0)