Show siblings and component_builds in the standard modules API

This commit is contained in:
mprahl
2018-05-10 11:48:00 -04:00
parent 64064c544b
commit 00e46c205b
2 changed files with 27 additions and 16 deletions

View File

@@ -552,19 +552,22 @@ class ModuleBuild(MBSBase):
'context': self.context,
}
def json(self):
def json(self, show_tasks=True):
json = self.short_json()
json.update({
'state_reason': self.state_reason,
'component_builds': [build.id for build in self.component_builds],
'koji_tag': self.koji_tag,
'owner': self.owner,
'rebuild_strategy': self.rebuild_strategy,
'scmurl': self.scmurl,
'time_submitted': _utc_datetime_to_iso(self.time_submitted),
'time_modified': _utc_datetime_to_iso(self.time_modified),
'siblings': self.siblings,
'state_reason': self.state_reason,
'time_completed': _utc_datetime_to_iso(self.time_completed),
'koji_tag': self.koji_tag,
'tasks': self.tasks(),
'time_modified': _utc_datetime_to_iso(self.time_modified),
'time_submitted': _utc_datetime_to_iso(self.time_submitted)
})
if show_tasks:
json['tasks'] = self.tasks()
return json
def extended_json(self, show_state_url=False, api_version=1):
@@ -575,24 +578,24 @@ class ModuleBuild(MBSBase):
SQLAlchemy sessions.
:kwarg api_version: the API version to use when building the state URL
"""
json = self.json()
json = self.json(show_tasks=True)
state_url = None
if show_state_url:
state_url = get_url_for('module_build', api_version=api_version, id=self.id)
json.update({
'component_builds': [build.id for build in self.component_builds],
'ref_build_context': self.ref_build_context,
'build_context': self.build_context,
'modulemd': self.modulemd,
'ref_build_context': self.ref_build_context,
'runtime_context': self.runtime_context,
'state_trace': [{'time': _utc_datetime_to_iso(record.state_time),
'state': record.state,
'state_name': INVERSE_BUILD_STATES[record.state],
'reason': record.state_reason}
for record
in self.state_trace(self.id)],
'state_trace': [
{
'time': _utc_datetime_to_iso(record.state_time),
'state': record.state,
'state_name': INVERSE_BUILD_STATES[record.state],
'reason': record.state_reason
} for record in self.state_trace(self.id)
],
'state_url': state_url,
'siblings': self.siblings
})
return json

View File

@@ -122,6 +122,7 @@ class TestViews:
assert data['name'] == 'nginx'
assert data['owner'] == 'Moe Szyslak'
assert data['stream'] == '1'
assert data['siblings'] == []
assert data['state'] == 5
assert data['state_reason'] is None
assert data['tasks'] == {
@@ -180,6 +181,7 @@ class TestViews:
assert data['owner'] == 'Moe Szyslak'
assert data['scmurl'] == ('git://pkgs.domain.local/modules/nginx'
'?#ba95886c7a443b36a9ce31abda1f9bef22f2f8c9')
assert data['siblings'] == []
assert data['state'] == 5
assert data['state_name'] == 'ready'
assert data['state_reason'] is None
@@ -239,6 +241,7 @@ class TestViews:
items = json.loads(rv.data)['items']
expected = [
{
"component_builds": [11, 12],
"context": "00000000",
"id": 7,
"koji_tag": None,
@@ -247,6 +250,7 @@ class TestViews:
"rebuild_strategy": "changed-and-after",
"scmurl": ("git://pkgs.domain.local/modules/testmodule"
"?#ca95886c7a443b36a9ce31abda1f9bef22f2f8c9"),
"siblings": [],
"state": 1,
"state_name": "wait",
"state_reason": None,
@@ -273,6 +277,7 @@ class TestViews:
"version": "7"
},
{
"component_builds": [9, 10],
"context": "00000000",
"id": 6,
"koji_tag": "module-postgressql-1.2",
@@ -281,6 +286,7 @@ class TestViews:
"rebuild_strategy": "changed-and-after",
"scmurl": ("git://pkgs.domain.local/modules/postgressql"
"?#aa95886c7a443b36a9ce31abda1f9bef22f2f8c9"),
"siblings": [],
"state": 3,
"state_name": "done",
"state_reason": None,
@@ -317,6 +323,7 @@ class TestViews:
items = json.loads(rv.data)['items']
expected = [
{
"component_builds": [3, 4],
"context": "3a4057d2",
"id": 3,
"koji_tag": "module-nginx-1.2",
@@ -325,6 +332,7 @@ class TestViews:
"rebuild_strategy": "changed-and-after",
"scmurl": ("git://pkgs.domain.local/modules/nginx"
"?#ba95886c7a443b36a9ce31abda1f9bef22f2f8c9"),
"siblings": [2],
"state": 5,
"state_name": "ready",
"state_reason": None,