#157 Fix #148: CLI example in help is not very useful/contains meta-characters
Merged 4 years ago by dcallagh. Opened 4 years ago by fivaldi.
fivaldi/waiverdb master  into  master

file modified
+1
@@ -12,3 +12,4 @@ 

  .tox

  dist

  .ropeproject

+ .pytest_cache/

file modified
+2 -2
@@ -88,10 +88,10 @@ 

  

    Examples:

  

-       waiverdb-cli -r 123 -r 456 -p "fedora-26" -c "It's dead!"

+       waiverdb-cli -r 47 -r 48 -p "fedora-28" -c "This is fine"

  or

  

-       waiverdb-cli -t dist.rpmlint -s '{"item": "python-requests-1.2.3-1.fc26", "type": "koji_build"}' -p "fedora-26" -c "It's dead!"

+       waiverdb-cli -t dist.rpmdeplint -s '{"item": "qclib-1.3.1-3.fc28", "type": "koji_build"}' -p "fedora-28" -c "This is expected for non-x86 packages"

  

  

  Options:

file modified
+20 -14
@@ -155,7 +155,7 @@ 

      with patch('openidc_client.OpenIDCClient.send_request') as mock_oidc_req:

          mock_rv = Mock()

          mock_rv.json.return_value = {

-             "comment": "It's dead!",

+             "comment": "This is fine",

              "id": 15,

              "product_version": "Parrot",

              "subject": {"subject.test": "test", "s": "t"},
@@ -178,14 +178,14 @@ 

              """)

          runner = CliRunner()

          args = ['-C', p.strpath, '-p', 'Parrot', '-s', '{"subject.test": "test", "s": "t"}',

-                 '-t', 'test.testcase', '-c', "It's dead!"]

+                 '-t', 'test.testcase', '-c', "This is fine"]

          result = runner.invoke(waiverdb_cli, args)

          exp_json = {

              "subject": {"subject.test": "test", "s": "t"},

              "testcase": "test.testcase",

              'waived': True,

              'product_version': 'Parrot',

-             'comment': "It's dead!"

+             'comment': "This is fine"

          }

          mock_oidc_req.assert_called_once_with(

              url='http://localhost:5004/api/v1.0/waivers/',
@@ -194,7 +194,10 @@ 

              timeout=60,

              headers={'Content-Type': 'application/json'})

          assert result.exit_code == 0

-         assert result.output == 'Created waiver 15 for result with subject {"subject.test": "test", "s": "t"} and testcase test.testcase\n' # noqa

+         assert result.output.startswith('Created waiver 15 for result with subject ')

+         assert result.output.endswith(' and testcase test.testcase\n')

+         assert any(['{"subject.test": "test", "s": "t"}' in result.output,

+                     '{"s": "t", "subject.test": "test"}' in result.output])

  

  

  def test_gssapi_is_enabled(tmpdir):
@@ -204,7 +207,7 @@ 

      with patch('requests.request') as mock_request:

          mock_rv = Mock()

          mock_rv.json.return_value = {

-             "comment": "It's dead!",

+             "comment": "This is fine",

              "id": 15,

              "product_version": "Parrot",

              "subject": {"subject.test": "test", "s": "t"},
@@ -223,17 +226,20 @@ 

              """)

          runner = CliRunner()

          args = ['-C', p.strpath, '-p', 'Parrot', '-s', '{"subject.test": "test", "s": "t"}',

-                 '-t', 'test.testcase', '-c', "It's dead!"]

+                 '-t', 'test.testcase', '-c', "This is fine"]

          result = runner.invoke(waiverdb_cli, args)

          mock_request.assert_called_once()

-         assert result.output == 'Created waiver 15 for result with subject {"subject.test": "test", "s": "t"} and testcase test.testcase\n' # noqa

+         assert result.output.startswith('Created waiver 15 for result with subject ')

+         assert result.output.endswith(' and testcase test.testcase\n')

+         assert any(['{"subject.test": "test", "s": "t"}' in result.output,

+                     '{"s": "t", "subject.test": "test"}' in result.output])

  

  

  def test_submit_waiver_with_id(tmpdir):

      with patch('requests.request') as mock_request:

          mock_rv = Mock()

          mock_rv.json.return_value = {

-             "comment": "It's dead!",

+             "comment": "This is fine",

              "data": {"item": ["htop-1.0-1.fc22"], "type": ["bodhi_update"]},

              "id": 15,

              "product_version": "Parrot",
@@ -252,7 +258,7 @@ 

          """)

          runner = CliRunner()

          args = ['-C', p.strpath, '-p', 'Parrot', '-r', '123',

-                 '-c', "It's dead!"]

+                 '-c', "This is fine"]

          result = runner.invoke(waiverdb_cli, args)

          mock_request.assert_called()

          assert result.output == 'Created waiver 15 for result with id 123\n'
@@ -262,7 +268,7 @@ 

      with patch('requests.request') as mock_request:

          mock_rv = Mock()

          mock_rv.json.return_value = {

-             "comment": "It's dead!",

+             "comment": "This is fine",

              "data": {"item": ["htop-1.0-1.fc22"], "type": ["bodhi_update"]},

              "id": 15,

              "testcase": {"name": "test.testcase"},
@@ -280,7 +286,7 @@ 

          """)

          runner = CliRunner()

          args = ['-C', p.strpath, '-p', 'Parrot', '-r', '123', '-r', '456',

-                 '-c', "It's dead!"]

+                 '-c', "This is fine"]

          result = runner.invoke(waiverdb_cli, args)

          mock_request.assert_called()

  
@@ -298,7 +304,7 @@ 

  resultsdb_api_url=http://localhost:5001/api/v2.0

          """)

          args = ['-C', p.strpath, '-p', 'Parrot', '-r', '123', '-s',

-                 '{"subject.test": "test", "s": "t"}', '-c', "It's dead!"]

+                 '{"subject.test": "test", "s": "t"}', '-c', "This is fine"]

          result = runner.invoke(waiverdb_cli, args)

          assert result.output == 'Error: Please specify result_id or subject/testcase. Not both\n'

  
@@ -307,7 +313,7 @@ 

      with patch('requests.request') as mock_request:

          mock_rv = Mock()

          mock_rv.json.return_value = {

-             "comment": "It's dead!",

+             "comment": "This is fine",

              "original_spec_nvr": "test",

              "id": 15,

              "product_version": "Parrot",
@@ -326,7 +332,7 @@ 

              """)

          runner = CliRunner()

          args = ['-C', p.strpath, '-p', 'Parrot', '-r', '123',

-                 '-c', "It's dead!"]

+                 '-c', "This is fine"]

          result = runner.invoke(waiverdb_cli, args)

          mock_request.assert_called()

          assert result.output == 'Created waiver 15 for result with id 123\n'

file modified
+4 -4
@@ -173,7 +173,7 @@ 

                 "testcase": "compose.install_no_user",

                 "waived": false,

                 "product_version": "Parrot",

-                "comment": "It's dead!"

+                "comment": "This is fine"

             }

  

  
@@ -189,7 +189,7 @@ 

             Server: Werkzeug/0.12.1 Python/2.7.13

  

             {

-                "comment": "It's dead!",

+                "comment": "This is fine",

                 "id": 15,

                 "product_version": "Parrot",

                 "subject": {"productmd.compose.id": "Fedora-9000-19700101.n.18"},
@@ -325,7 +325,7 @@ 

              {

                  "data": [

                      {

-                         "comment": "It's dead!",

+                         "comment": "This is fine",

                          "id": 5,

                          "product_version": "Parrot",

                          "subject": {"productmd.compose.id": "Fedora-9000-19700101.n.18"},
@@ -336,7 +336,7 @@ 

                          "proxied_by": null

                      },

                      {

-                         "comment": "It's dead!",

+                         "comment": "This is fine",

                          "id": 4,

                          "product_version": "Parrot",

                          "subject": {"item": "gzip-1.9-1.fc28", "type": "koji_build"},

file modified
+4 -4
@@ -75,13 +75,13 @@ 

  

      Examples:

  

-         waiverdb-cli -r 123 -r 456 -p "fedora-26" -c "It's dead!"

+         waiverdb-cli -r 47 -r 48 -p "fedora-28" -c "This is fine"

  

          or

  

-         waiverdb-cli -t dist.rpmlint -s '{"item": "python-requests-1.2.3-1.fc26",

-                                           "type": "koji_build"}'

-                      -p "fedora-26" -c "It's dead!"

+         waiverdb-cli -t dist.rpmdeplint -s '{"item": "qclib-1.3.1-3.fc28",

+                                              "type": "koji_build"}'

+                      -p "fedora-28" -c "This is expected for non-x86 packages"

  

      """

      config = configparser.SafeConfigParser()

no initial comment

rebased onto fd047b2

4 years ago

@zbyszek I added some fixes for tests/test_cli.py. There was an issue with the dict order between Py2 versus Py3. Side effect was in removing of the #noqa flags.

tox for tests/test_cli.py produces:

  lint: commands succeeded
  py27: commands succeeded
  py34: commands succeeded
  py35: commands succeeded
  py36: commands succeeded
ERROR:   docs: commands failed

Don't know if the docs command is necessary to pass here... (?) But I think it's because of my environment, which is not 100% ready for waiverdb testing.

Please for last review here after the changes in asserts in tests/test_cli.py.

Thanks @fivaldi ... I wonder if we should just drop the -r example entirely since that's deprecated. Anyway, this is a good improvement. :+1:

Pull-Request has been merged by dcallagh

4 years ago