From b891c2f87ba0a961fd23906eca4b2e8ab5393684 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Mon, 19 Aug 2024 11:02:36 +0200 Subject: [PATCH] Fix test suite Signed-off-by: Petr "Stone" Hracek --- .../ocp_stream_generator/distribution_data.py | 11 +- ocp-stream-generator/pytest.ini | 2 +- .../tests/data/data_json_builder.py | 112 ++++++++---------- .../tests/test_json_builder.py | 4 +- 4 files changed, 60 insertions(+), 69 deletions(-) diff --git a/ocp-stream-generator/ocp_stream_generator/distribution_data.py b/ocp-stream-generator/ocp_stream_generator/distribution_data.py index 69d9977..b647975 100755 --- a/ocp-stream-generator/ocp_stream_generator/distribution_data.py +++ b/ocp-stream-generator/ocp_stream_generator/distribution_data.py @@ -52,8 +52,9 @@ "CentOS Stream 10": "el10", } -latest_description = """ - -WARNING: By selecting this tag, your application will automatically update -to use the latest version available on OpenShift, including major version updates. -""" +latest_description = ( + "\n\nWARNING: By selecting this tag," + " your application will automatically" + " update to use the latest version available on OpenShift," + " including major version updates.\n" +) diff --git a/ocp-stream-generator/pytest.ini b/ocp-stream-generator/pytest.ini index 8c54221..eb48dbf 100644 --- a/ocp-stream-generator/pytest.ini +++ b/ocp-stream-generator/pytest.ini @@ -1,3 +1,3 @@ [pytest] -pythonpath = ocp-stream-generator +pythonpath = ocp_stream_generator testpaths = tests diff --git a/ocp-stream-generator/tests/data/data_json_builder.py b/ocp-stream-generator/tests/data/data_json_builder.py index 757f337..ae46ecf 100644 --- a/ocp-stream-generator/tests/data/data_json_builder.py +++ b/ocp-stream-generator/tests/data/data_json_builder.py @@ -29,10 +29,10 @@ "annotations": { "openshift.io/display-name": "Test 1 (Latest)", "openshift.io/provider-display-name": "Red Hat, Inc.", - "description": "test description\n\nWARNING: By selecting this tag, your" - "application will automatically update" - "to use the latest version" - "available on OpenShift, including major version updates.\n", + "description": "test description\n\nWARNING: By selecting this tag," + " your application will automatically update" + " to use the latest version available on OpenShift," + " including major version updates.\n", "iconClass": "icon-test", "tags": "test,test", "version": "1", @@ -79,10 +79,11 @@ create_annotation_latest_result = { "openshift.io/display-name": "Test 1 (Latest)", "openshift.io/provider-display-name": "Red Hat, Inc.", - "description": "test description\n\nWARNING: By selecting this tag," - "your application will automatically update to use" - "the latest version available on OpenShift," - "including major version updates.\n", + "description": ( + "test description\n\nWARNING: By selecting this tag," + " your application will automatically update to use " + "the latest version available on OpenShift, including major version updates.\n" + ), "iconClass": "icon-test", "tags": "test,test", "version": "1", @@ -95,58 +96,47 @@ "spec": {"tags": []}, } +description_msg = ( + "test description\n\n" + "WARNING: By selecting this tag, your application will automatically" + " update to use the latest version available on OpenShift, including major version updates.\n" +) -generate_json_result = """ -{ - "kind": "ImageStream", - "apiVersion": "image.openshift.io/v1", - "metadata": { - "name": "test", - "annotations": { - "openshift.io/display-name": "Test" - } - }, - "spec": { - "tags": [ - { - "name": "1-el8", - "annotations": { - "openshift.io/display-name": "Test 1 (RHEL 8)", - "openshift.io/provider-display-name": "Red Hat, Inc.", - "description": "test description", - "iconClass": "icon-test", - "tags": "test,test", - "version": "1" - }, - "from": { - "kind": "DockerImage", - "name": "registry.redhat.io/rhel8/test-1:latest" - }, - "referencePolicy": { - "type": "Local" - } - }, - { - "name": "latest", - "annotations": { - "openshift.io/display-name": "Test 1 (Latest)", - "openshift.io/provider-display-name": "Red Hat, Inc.", - "description": "test description\n\nWARNING: By selecting this tag, - your application will automatically update to use the latest version - available on OpenShift, including major version updates.\n", - "iconClass": "icon-test", - "tags": "test,test", - "version": "1" - }, - "from": { - "kind": "ImageStreamTag", - "name": "1-el8" - }, - "referencePolicy": { - "type": "Local" - } - } - ] - } +generate_json_result = { + "kind": "ImageStream", + "apiVersion": "image.openshift.io/v1", + "metadata": {"name": "test", "annotations": {"openshift.io/display-name": "Test"}}, + "spec": { + "tags": [ + { + "name": "1-el8", + "annotations": { + "openshift.io/display-name": "Test 1 (RHEL 8)", + "openshift.io/provider-display-name": "Red Hat, Inc.", + "description": "test description", + "iconClass": "icon-test", + "tags": "test,test", + "version": "1", + }, + "from": { + "kind": "DockerImage", + "name": "registry.redhat.io/rhel8/test-1:latest", + }, + "referencePolicy": {"type": "Local"}, + }, + { + "name": "latest", + "annotations": { + "openshift.io/display-name": "Test 1 (Latest)", + "openshift.io/provider-display-name": "Red Hat, Inc.", + "description": f"{description_msg}", + "iconClass": "icon-test", + "tags": "test,test", + "version": "1", + }, + "from": {"kind": "ImageStreamTag", "name": "1-el8"}, + "referencePolicy": {"type": "Local"}, + }, + ] + }, } -""" diff --git a/ocp-stream-generator/tests/test_json_builder.py b/ocp-stream-generator/tests/test_json_builder.py index ba2fbe8..2b1d4fb 100644 --- a/ocp-stream-generator/tests/test_json_builder.py +++ b/ocp-stream-generator/tests/test_json_builder.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 - +import json import re from stream_generator import JsonBuilder from stream_generator import Tag @@ -86,5 +86,5 @@ def test_generate_json(): } isf_data = ImagestreamFile(file, header) stripped_json = re.sub(r"[\n\t\s\\n]*", "", builder.generate_json(isf_data)) - stripped_result = re.sub(r"[\n\t\s\\n]*", "", generate_json_result) + stripped_result = re.sub(r"[\n\t\s\\n]*", "", json.dumps(generate_json_result)) assert stripped_json == stripped_result