From: Aric Gardner Date: Thu, 23 Jan 2020 20:11:11 +0000 (-0500) Subject: Make output parsable X-Git-Tag: v0.30.0^0 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=a712f0aef30b673c5b32e3fe879c6e0c1635a927;p=releng%2Flftools.git Make output parsable Need valid JSON in the output for automation work -thanks DW ISSUE-ID: RELENG-2683 Signed-off-by: Aric Gardner Change-Id: Ie85adcec15577f432299846075068ed2a72783db --- diff --git a/lftools/api/endpoints/readthedocs.py b/lftools/api/endpoints/readthedocs.py index 1d9f1e2a..d39a4c1a 100644 --- a/lftools/api/endpoints/readthedocs.py +++ b/lftools/api/endpoints/readthedocs.py @@ -107,7 +107,7 @@ class ReadTheDocs(client.RestApi): """ result = self.get('projects/{}/versions/{}/' .format(project, version))[1] - return result + return json.dumps(result, indent=2) def project_version_update(self, project, version, active): """Edit version activity. @@ -188,7 +188,7 @@ class ReadTheDocs(client.RestApi): .format(project), **kwargs)[1] if result['count'] > 0: - return result + return json.dumps(result, indent=2) else: return "There are no active builds." @@ -202,7 +202,7 @@ class ReadTheDocs(client.RestApi): """ result = self.get('projects/{}/builds/{}/' .format(project, build_id))[1] - return result + return json.dumps(result, indent=2) def project_build_trigger(self, project, version): """Trigger a project build. @@ -214,7 +214,7 @@ class ReadTheDocs(client.RestApi): """ result = self.post('projects/{}/versions/{}/builds/' .format(project, version))[1] - return result + return json.dumps(result, indent=2) def subproject_list(self, project): """Return a list of subprojects. diff --git a/lftools/cli/rtd.py b/lftools/cli/rtd.py index 0da70ec9..f38177a5 100644 --- a/lftools/cli/rtd.py +++ b/lftools/cli/rtd.py @@ -86,7 +86,7 @@ def project_version_details(ctx, project_slug, version_slug): """Retrieve project version details.""" r = readthedocs.ReadTheDocs() data = r.project_version_details(project_slug, version_slug) - log.info(pformat(data)) + log.info(data) @click.command(name='project-create') @@ -128,7 +128,7 @@ def project_build_list(ctx, project_slug): """Retrieve a list of a project's builds.""" r = readthedocs.ReadTheDocs() data = r.project_build_list(project_slug) - log.info(pformat(data)) + log.info(data) @click.command(name='project-build-details') @@ -139,7 +139,7 @@ def project_build_details(ctx, project_slug, build_id): """Retrieve specific project build details.""" r = readthedocs.ReadTheDocs() data = r.project_build_details(project_slug, build_id) - log.info(pformat(data)) + log.info(data) @click.command(name='project-build-trigger') @@ -150,7 +150,7 @@ def project_build_trigger(ctx, project_slug, version_slug): """Trigger a new build.""" r = readthedocs.ReadTheDocs() data = r.project_build_trigger(project_slug, version_slug) - log.info(pformat(data)) + log.info(data) @click.command(name='subproject-list') diff --git a/tests/test_rtd.py b/tests/test_rtd.py index 8db3047d..b5cd58c0 100644 --- a/tests/test_rtd.py +++ b/tests/test_rtd.py @@ -116,7 +116,7 @@ def test_project_build_list(datafiles): responses.add(responses.GET, url='https://readthedocs.org/api/v3/projects/testproject1/builds/?running=True', # noqa json=json_data, status=200, match_querystring=True) - assert 'success' in rtd.project_build_list('testproject1')['results'][0] + assert 'success' in rtd.project_build_list('testproject1') @pytest.mark.datafiles(os.path.join(FIXTURE_DIR, 'rtd'),)