1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-30 19:56:14 +01:00

Drop Request.get_creator method in favor of a new "creator" attribute

This implements the Request api change that was proposed in commit
6965dc5 ("Adjust request testcases to the upcoming Request api
change").

Fixes: #286 ("get_creator() does not return request creator")
This commit is contained in:
Marcus Huewe 2017-04-12 12:58:23 +02:00
parent 6965dc5cd4
commit d68507fa95
2 changed files with 7 additions and 9 deletions

View File

@ -2503,7 +2503,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if repl.lower() == 'y' or repl == '': if repl.lower() == 'y' or repl == '':
(supersede, reqs) = check_existing_requests(apiurl, action.tgt_project, action.tgt_package, (supersede, reqs) = check_existing_requests(apiurl, action.tgt_project, action.tgt_package,
project, package) project, package)
msg = "%s (forwarded request %s from %s)" % (rq.description, reqid, rq.get_creator()) msg = "%s (forwarded request %s from %s)" % (rq.description, reqid, rq.creator)
rid = create_submit_request(apiurl, action.tgt_project, action.tgt_package, rid = create_submit_request(apiurl, action.tgt_project, action.tgt_package,
project, package, cgi.escape(msg)) project, package, cgi.escape(msg))
print(msg) print(msg)

View File

@ -2684,6 +2684,7 @@ class Request:
def _init_attributes(self): def _init_attributes(self):
"""initialize attributes with default values""" """initialize attributes with default values"""
self.reqid = None self.reqid = None
self.creator = None
self.title = '' self.title = ''
self.description = '' self.description = ''
self.priority = None self.priority = None
@ -2696,9 +2697,10 @@ class Request:
def read(self, root): def read(self, root):
"""read in a request""" """read in a request"""
self._init_attributes() self._init_attributes()
if not root.get('id'): if not root.get('id') or not root.get('creator'):
raise oscerr.APIError('invalid request: %s\n' % ET.tostring(root, encoding=ET_ENCODING)) raise oscerr.APIError('invalid request: %s\n' % ET.tostring(root, encoding=ET_ENCODING))
self.reqid = root.get('id') self.reqid = root.get('id')
self.creator = root.get('creator')
if root.find('state') is None: if root.find('state') is None:
raise oscerr.APIError('invalid request (state expected): %s\n' % ET.tostring(root, encoding=ET_ENCODING)) raise oscerr.APIError('invalid request (state expected): %s\n' % ET.tostring(root, encoding=ET_ENCODING))
self.state = RequestState(root.find('state')) self.state = RequestState(root.find('state'))
@ -2736,17 +2738,13 @@ class Request:
return self.actions return self.actions
return [i for i in self.actions if i.type in types] return [i for i in self.actions if i.type in types]
def get_creator(self):
"""return the creator of the request"""
if len(self.statehistory):
return self.statehistory[0].who
return self.state.who
def to_xml(self): def to_xml(self):
"""serialize object to XML""" """serialize object to XML"""
root = ET.Element('request') root = ET.Element('request')
if not self.reqid is None: if not self.reqid is None:
root.set('id', self.reqid) root.set('id', self.reqid)
if self.creator is not None:
root.set('creator', self.creator)
for action in self.actions: for action in self.actions:
root.append(action.to_xml()) root.append(action.to_xml())
if not self.state is None: if not self.state is None:
@ -4182,7 +4180,7 @@ def change_request_state_template(req, newstate):
tmpl_name = '%srequest_%s_template' % (action.type, newstate) tmpl_name = '%srequest_%s_template' % (action.type, newstate)
tmpl = conf.config.get(tmpl_name, '') tmpl = conf.config.get(tmpl_name, '')
tmpl = tmpl.replace('\\t', '\t').replace('\\n', '\n') tmpl = tmpl.replace('\\t', '\t').replace('\\n', '\n')
data = {'reqid': req.reqid, 'type': action.type, 'who': req.get_creator()} data = {'reqid': req.reqid, 'type': action.type, 'who': req.creator}
if req.actions[0].type == 'submit': if req.actions[0].type == 'submit':
data.update({'src_project': action.src_project, data.update({'src_project': action.src_project,
'src_package': action.src_package, 'src_rev': action.src_rev, 'src_package': action.src_package, 'src_rev': action.src_rev,