Skip to content

Commit

Permalink
Drop Request.get_creator method in favor of a new "creator" attribute
Browse files Browse the repository at this point in the history
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")
  • Loading branch information
marcus-h committed Apr 12, 2017
1 parent 6965dc5 commit d68507f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,7 @@ def do_request(self, subcmd, opts, *args):
if repl.lower() == 'y' or repl == '':
(supersede, reqs) = check_existing_requests(apiurl, action.tgt_project, action.tgt_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,
project, package, cgi.escape(msg))
print(msg)
Expand Down
14 changes: 6 additions & 8 deletions osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2684,6 +2684,7 @@ def __init__(self):
def _init_attributes(self):
"""initialize attributes with default values"""
self.reqid = None
self.creator = None
self.title = ''
self.description = ''
self.priority = None
Expand All @@ -2696,9 +2697,10 @@ def _init_attributes(self):
def read(self, root):
"""read in a request"""
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))
self.reqid = root.get('id')
self.creator = root.get('creator')
if root.find('state') is None:
raise oscerr.APIError('invalid request (state expected): %s\n' % ET.tostring(root, encoding=ET_ENCODING))
self.state = RequestState(root.find('state'))
Expand Down Expand Up @@ -2736,17 +2738,13 @@ def get_actions(self, *types):
return self.actions
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):
"""serialize object to XML"""
root = ET.Element('request')
if not self.reqid is None:
root.set('id', self.reqid)
if self.creator is not None:
root.set('creator', self.creator)
for action in self.actions:
root.append(action.to_xml())
if not self.state is None:
Expand Down Expand Up @@ -4182,7 +4180,7 @@ def change_request_state_template(req, newstate):
tmpl_name = '%srequest_%s_template' % (action.type, newstate)
tmpl = conf.config.get(tmpl_name, '')
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':
data.update({'src_project': action.src_project,
'src_package': action.src_package, 'src_rev': action.src_rev,
Expand Down

0 comments on commit d68507f

Please sign in to comment.