From f64cd49e2694d80f0ed0a752325cfbd6b069b09d Mon Sep 17 00:00:00 2001 From: Michal Konečný Date: Aug 20 2020 13:20:21 +0000 Subject: Make orphan reason optional Signed-off-by: Michal Konečný --- diff --git a/pagure_distgit/forms.py b/pagure_distgit/forms.py index 4bdf1fe..d5b444f 100644 --- a/pagure_distgit/forms.py +++ b/pagure_distgit/forms.py @@ -35,7 +35,7 @@ class OrphanReasonForm(pagure.forms.PagureForm): orphan_reason = wtforms.SelectField( "Reason for orphaning package", - [wtforms.validators.DataRequired()], + [wtforms.validators.optional(strip_whitespace=True)], choices=[ ("Lack of time", "Lack of time"), ("Do not use it anymore", "Do not use it anymore"), diff --git a/pagure_distgit/plugin.py b/pagure_distgit/plugin.py index 91aeac0..469e30d 100644 --- a/pagure_distgit/plugin.py +++ b/pagure_distgit/plugin.py @@ -234,15 +234,15 @@ def orphan_endpoint(namespace, repo): Input ^^^^^ - +-----------------------+---------+--------------+---------------------------+ - | Key | Type | Optionality | Description | - +=======================+=========+==============+===========================+ - | ``orphan_reason`` | string | Mandatory | | The reason to orphan | - | | | | the package. | - +-----------------------+---------+--------------+---------------------------+ - | ``orphan_reason_info``| string | Optional | | Additional info for | - | | | | provided reason. | - +-----------------------+---------+--------------+---------------------------+ + +-----------------------+---------+--------------+------------------------+ + | Key | Type | Optionality | Description | + +=======================+=========+==============+========================+ + | ``orphan_reason`` | string | Optional | | The reason to orphan | + | | | | the package. | + +-----------------------+---------+--------------+------------------------+ + | ``orphan_reason_info``| string | Optional | | Additional info for | + | | | | provided reason. | + +-----------------------+---------+--------------+------------------------+ Sample response ^^^^^^^^^^^^^^^ diff --git a/pagure_distgit_tests/test_plugin.py b/pagure_distgit_tests/test_plugin.py index 0924957..0e5a602 100644 --- a/pagure_distgit_tests/test_plugin.py +++ b/pagure_distgit_tests/test_plugin.py @@ -53,11 +53,21 @@ class PagureFlaskApiOrphanEndpointTests(tests.Modeltests): ) assert output.status_code == 401 + def test_empty_form(self): + """Assert that empty form is accepted. + """ + headers = {"Authorization": "token aaabbbcccddd"} + datainput = {} + output = self.app.post( + "/_dg/orphan/somenamespace/test3", data=datainput, headers=headers, + ) + assert output.status_code == 200 + def test_invalid_form(self): """Assert that invalid form is not accepted. """ headers = {"Authorization": "token aaabbbcccddd"} - datainput = {} + datainput = {"orphan_reason": "bar"} output = self.app.post( "/_dg/orphan/somenamespace/test3", data=datainput, headers=headers, )