Return empty result if short=true is specified on empty list of builds

Fixes #1376

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
This commit is contained in:
Chenxiong Qi
2019-08-06 22:05:12 +08:00
parent ac09fb55ba
commit 6f1d0b3ad9
2 changed files with 7 additions and 1 deletions

View File

@@ -125,7 +125,7 @@ class AbstractQueryableBuildAPI(MethodView):
json_func_kwargs["show_state_url"] = True
json_func_kwargs["api_version"] = api_version
elif short_flag == "true" or short_flag == "1":
if hasattr(p_query.items[0], "short_json"):
if p_query.items and hasattr(p_query.items[0], "short_json"):
json_func_name = "short_json"
if json_func_name == "json" or json_func_name == "extended_json":
# Only ModuleBuild.json and ModuleBuild.extended_json has argument db_session

View File

@@ -524,6 +524,12 @@ class TestViews:
assert rv.status_code == 400
assert results == expected_error
def test_query_builds_get_short_json_from_empty_list_of_builds(self):
rv = self.client.get("/module-build-service/1/module-builds/?name=pkgname&short=true")
data = json.loads(rv.data)
assert [] == data["items"]
assert 0 == data["meta"]["total"]
def test_query_component_build(self):
rv = self.client.get("/module-build-service/1/component-builds/1")
data = json.loads(rv.data)