Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix from get_files method. #58

Merged
merged 3 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions centraldogma/content_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ def get_files(
path += "/" + path_pattern

handler = {
HTTPStatus.OK: lambda resp: [
Content.from_dict(content) for content in resp.json()
],
HTTPStatus.OK: lambda resp: (
lambda data: (
[Content.from_dict(content) for content in data]
if isinstance(data, list)
else [Content.from_dict(data)]
)
)(resp.json()),
HTTPStatus.NO_CONTENT: lambda resp: [],
}
return self.client.request("get", path, params=params, handler=handler)
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/test_content_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,32 @@ def test_merge_files(self, run_around_test):
assert ret.entry_type == EntryType.JSON
assert ret.content == {"foo3": "bar3"}

def test_get_files_for_single_file(self, run_around_test):
commit = Commit("Upsert dummy1-test.json")
upsert_json = Change(
"/test/dummy1-test.json", ChangeType.UPSERT_JSON, {"foo": "bar"}
)
dogma.push(project_name, repo_name, commit, [upsert_json])

ret = dogma.get_files(project_name, repo_name, "/test/dummy1-test.json")
assert len(ret) == 1

def test_get_files_for_multiple_file(self, run_around_test):
commit = Commit("Upsert dummy1-test.json")
upsert_json = Change(
"/dummy1-test.json", ChangeType.UPSERT_JSON, {"foo": "bar"}
)
dogma.push(project_name, repo_name, commit, [upsert_json])

commit = Commit("Upsert dummy2-test.json")
upsert_json = Change(
"/dummy2-test.json", ChangeType.UPSERT_JSON, {"foo": "bar"}
)
dogma.push(project_name, repo_name, commit, [upsert_json])

ret = dogma.get_files(project_name, repo_name, "/dummy*-test.json")
assert len(ret) == 2

@staticmethod
def push_later():
time.sleep(1)
Expand Down