Skip to content

Commit

Permalink
Merge pull request #20 from mimi1vx/force_reject
Browse files Browse the repository at this point in the history
Force reject
  • Loading branch information
mergify[bot] committed Mar 30, 2023
2 parents a399da9 + bcd9cd4 commit e0eaa1c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 41 deletions.
2 changes: 1 addition & 1 deletion oscqam/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.62.0"
__version__ = "0.70.0"
14 changes: 10 additions & 4 deletions oscqam/actions/rejectaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ class RejectAction(OscAction):

DECLINE_MSG = "Declining request {request} for {user}. See Testreport: {url}"

def __init__(self, remote, user, request_id, reason, message=None, out=sys.stdout):
def __init__(
self, remote, user, request_id, reason, force, message=None, out=sys.stdout
):
super(RejectAction, self).__init__(remote, user, out=out)
self.request = remote.requests.by_id(request_id)
self._template = None
self._template = None if not force else "There is no template"
self.reason = reason
self.message = message
self.force: bool = force

@property
def template(self):
Expand All @@ -40,8 +43,11 @@ def validate(self):
raise NoCommentError()

def action(self):
self.validate()
url = self.template.fancy_url
if not self.force:
self.validate()
url = self.template.fancy_url
else:
url = self.template
msg = RejectAction.DECLINE_MSG.format(
user=self.user, request=self.request, url=url
)
Expand Down
48 changes: 15 additions & 33 deletions oscqam/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def do_approve(self, subcmd, opts, *args):
"--skip-template",
action="store_true",
default=False,
help="Will not check if a template exists.",
help="Do not check whether a template exists.",
)
def do_assign(self, subcmd, opts, *args):
"""${cmd_name}: Assign the request to the user.
Expand Down Expand Up @@ -441,6 +441,12 @@ def query_enum(self, enum, tid, desc):
action="append",
help="Reason the request was rejected: " + all_reasons_string,
)
@cmdln.option(
"--skip-template",
action="store_true",
default=False,
help="Do not check whether a template exists.",
)
def do_reject(self, subcmd, opts, *args):
"""${cmd_name}: Reject the request for the user.
Expand All @@ -464,8 +470,14 @@ def do_reject(self, subcmd, opts, *args):
)
if reasons == self.SUBQUERY_QUIT:
return
template_skip: bool = False if opts.skip_template else True
action = RejectAction(
self.api, self.affected_user, self.request_id, reasons, message
self.api,
self.affected_user,
self.request_id,
reasons,
template_skip,
message,
)
action()

Expand Down Expand Up @@ -573,36 +585,6 @@ def setup_logging():
logging.basicConfig(filename=path, filemode="w", level=level)


@cmdln.option(
"-A", "--assigned", action="store_true", help="Parameter for list command."
)
@cmdln.option(
"-F",
"--fields",
action="append",
help="Define the fields to output for the list command in "
"cumulative fashion (pass flag multiple times).",
)
@cmdln.option(
"-G",
"--group",
action="append",
help="Define the groups to use for the command."
"Pass multiple groups passing flag multiple times.",
)
@cmdln.option("-M", "--message", help="Message to use for the command.")
@cmdln.option(
"-R", "--reason", action="append", help="Reason a request has to be rejected."
)
@cmdln.option(
"-T",
"--tabular",
action="store_true",
help="Create tabular output for list command.",
)
@cmdln.option("-U", "--user", help="User to use for the command.")
@cmdln.option("-v", "--verbose", action="store_true", help="Generate verbose output.")
@cmdln.option("--skip-template", help="Will not check if a template exists.")
def do_qam(self, subcmd, opts, *args):
"""Start the QA-Maintenance specific submode of osc for request handling."""
osc_stdout = [None]
Expand All @@ -627,7 +609,7 @@ def restore_osc_stdout():

osc.conf.get_config()
running = True
ret = None
ret = 0
while running:
try:
restore_orig_stdout()
Expand Down
23 changes: 20 additions & 3 deletions tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_reject_not_failed(remote):
request = remote.requests.by_id(cloud_open)
template = models.Template(request, tr_getter=FakeTrGetter(template_txt))
action = actions.RejectAction(
remote, user_id, cloud_open, reject_reasons.RejectReason.administrative
remote, user_id, cloud_open, [reject_reasons.RejectReason.administrative], False
)
action._template = template
with pytest.raises(errors.TestResultMismatchError) as context:
Expand All @@ -193,13 +193,29 @@ def test_reject_no_comment(remote):
),
)
action = actions.RejectAction(
remote, user_id, cloud_open, reject_reasons.RejectReason.administrative
remote, user_id, cloud_open, [reject_reasons.RejectReason.administrative], False
)
action._template = template
with pytest.raises(errors.NoCommentError):
action()


def test_reject_no_comment_force(remote):
"""Reject can be forced without template"""
request = remote.requests.by_id(cloud_open)
endpoint = "source/{prj}/_attribute/MAINT:RejectReason".format(
prj=request.src_project
)
remote.register_url(endpoint, lambda: load_fixture("reject_reason_attribute.xml"))
action = actions.RejectAction(
remote, user_id, cloud_open, [reject_reasons.RejectReason.administrative], True
)
action()
assert len(remote.post_calls), 2
assert request.src_project in remote.post_calls[0]
assert "Testreport: There is no template" in remote.post_calls[1]


def test_reject_posts_reason(remote):
"""Rejecting a request will post a reason attribute."""
request = remote.requests.by_id(cloud_open)
Expand All @@ -216,7 +232,7 @@ def test_reject_posts_reason(remote):
)
remote.register_url(endpoint, lambda: load_fixture("reject_reason_attribute.xml"))
action = actions.RejectAction(
remote, user_id, cloud_open, [reject_reasons.RejectReason.administrative]
remote, user_id, cloud_open, [reject_reasons.RejectReason.administrative], False
)
action._template = template
action()
Expand Down Expand Up @@ -508,6 +524,7 @@ def test_decline_output(remote):
user_id,
cloud_open,
[reject_reasons.RejectReason.administrative],
False,
out=out,
)
action._template = template
Expand Down

0 comments on commit e0eaa1c

Please sign in to comment.