From 8fb7662276956739de737cde24a7564a54591b98 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Wed, 20 Mar 2024 08:08:48 +0100 Subject: [PATCH 1/5] Add tests for django_ex application w/o database for now Signed-off-by: Petr "Stone" Hracek --- Makefile | 3 +++ tests/test_django.py | 60 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 Makefile create mode 100644 tests/test_django.py diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..97a95a66c --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +.PHONY: test-openshift-4 +test-openshift-4: + cd tests && PYTHONPATH=$(CURDIR) python3 -m pytest --verbose --color=yes --showlocals . \ No newline at end of file diff --git a/tests/test_django.py b/tests/test_django.py new file mode 100644 index 000000000..5370bd785 --- /dev/null +++ b/tests/test_django.py @@ -0,0 +1,60 @@ +import os + +import pytest +from pathlib import Path + +from container_ci_suite.openshift import OpenShiftAPI + +test_dir = Path(os.path.abspath(os.path.dirname(__file__))) + +VERSION=os.getenv("SINGLE_VERSION") +if not VERSION: + VERSION="3.11-ubi8" + +class TestDancerAppExTemplate: + + def setup_method(self): + self.oc_api = OpenShiftAPI(pod_name_prefix="django-example") + json_raw_file = self.oc_api.get_raw_url_for_json( + container="s2i-python-container", dir="imagestreams", filename="python-rhel.json" + ) + self.oc_api.import_is(path=json_raw_file, name="python") + + def teardown_method(self): + self.oc_api.delete_project() + + def test_template_inside_cluster(self): + if VERSION == "3.11-ubi8" or VERSION == "3.11-ubi9": + branch_to_test = "4.2.x" + else: + branch_to_test = "master" + expected_output = "Welcome to your Django application" + template_json = self.oc_api.get_raw_url_for_json( + container="django-ex", dir="openshift/templates", filename="django.json" + ) + assert self.oc_api.deploy_template( + template=template_json, name_in_template="django-example", expected_output=expected_output, + openshift_args=[f"SOURCE_REPOSITORY_REF={branch_to_test}", f"PYTHON_VERSION={VERSION}", "NAME=django-example"] + ) + assert self.oc_api.template_deployed(name_in_template="django-example") + assert self.oc_api.check_response_inside_cluster( + name_in_template="django-example", expected_output=expected_output + ) + + def test_template_by_request(self): + if VERSION == "3.11-ubi8" or VERSION == "3.11-ubi9": + branch_to_test = "4.2.x" + else: + branch_to_test = "master" + expected_output = "Welcome to your Django application" + template_json = self.oc_api.get_raw_url_for_json( + container="django-ex", dir="openshift/templates", filename="dancer.json" + ) + assert self.oc_api.deploy_template( + template=template_json, name_in_template="django-example", expected_output=expected_output, + openshift_args=[f"SOURCE_REPOSITORY_REF={branch_to_test}", f"PYTHON_VERSION={VERSION}", "NAME=django-example"] + ) + assert self.oc_api.template_deployed(name_in_template="django-example") + assert self.oc_api.check_response_outside_cluster( + name_in_template="django-example", expected_output=expected_output + ) From 9052914c2e70c5f20282e6f1604581ffed031877 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Wed, 20 Mar 2024 08:28:29 +0100 Subject: [PATCH 2/5] Fix typo in template name Signed-off-by: Petr "Stone" Hracek --- tests/test_django.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_django.py b/tests/test_django.py index 5370bd785..5ed077ddd 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -48,7 +48,7 @@ def test_template_by_request(self): branch_to_test = "master" expected_output = "Welcome to your Django application" template_json = self.oc_api.get_raw_url_for_json( - container="django-ex", dir="openshift/templates", filename="dancer.json" + container="django-ex", dir="openshift/templates", filename="django.json" ) assert self.oc_api.deploy_template( template=template_json, name_in_template="django-example", expected_output=expected_output, From fd0baa6905847414216a9c7a791be4a3d9ce19ab Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Wed, 20 Mar 2024 08:54:59 +0100 Subject: [PATCH 3/5] Fix supported matrix Signed-off-by: Petr "Stone" Hracek --- tests/test_django.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_django.py b/tests/test_django.py index 5ed077ddd..0c1093a3e 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -26,6 +26,8 @@ def teardown_method(self): def test_template_inside_cluster(self): if VERSION == "3.11-ubi8" or VERSION == "3.11-ubi9": branch_to_test = "4.2.x" + elif VERSION == "3.9-ubi9": + branch_to_test = "2.2.x" else: branch_to_test = "master" expected_output = "Welcome to your Django application" @@ -44,6 +46,8 @@ def test_template_inside_cluster(self): def test_template_by_request(self): if VERSION == "3.11-ubi8" or VERSION == "3.11-ubi9": branch_to_test = "4.2.x" + elif VERSION == "3.9-ubi9": + branch_to_test = "2.2.x" else: branch_to_test = "master" expected_output = "Welcome to your Django application" From 7919e26e3dd9ce069e96ac427ad3a02d718dd73e Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Wed, 20 Mar 2024 09:42:33 +0100 Subject: [PATCH 4/5] Fix test suite class name Signed-off-by: Petr "Stone" Hracek --- tests/test_django.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_django.py b/tests/test_django.py index 0c1093a3e..b755fa434 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -11,7 +11,7 @@ if not VERSION: VERSION="3.11-ubi8" -class TestDancerAppExTemplate: +class TestDjangoAppExTemplate: def setup_method(self): self.oc_api = OpenShiftAPI(pod_name_prefix="django-example") From fad5f1739ea45828fed274755dd76d0fb5a67b4e Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Wed, 20 Mar 2024 09:57:05 +0100 Subject: [PATCH 5/5] Use proper branch for import Signed-off-by: Petr "Stone" Hracek --- tests/test_django.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_django.py b/tests/test_django.py index b755fa434..ebb9dec26 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -32,7 +32,7 @@ def test_template_inside_cluster(self): branch_to_test = "master" expected_output = "Welcome to your Django application" template_json = self.oc_api.get_raw_url_for_json( - container="django-ex", dir="openshift/templates", filename="django.json" + container="django-ex", branch=branch_to_test, dir="openshift/templates", filename="django.json" ) assert self.oc_api.deploy_template( template=template_json, name_in_template="django-example", expected_output=expected_output, @@ -52,7 +52,7 @@ def test_template_by_request(self): branch_to_test = "master" expected_output = "Welcome to your Django application" template_json = self.oc_api.get_raw_url_for_json( - container="django-ex", dir="openshift/templates", filename="django.json" + container="django-ex", branch=branch_to_test, dir="openshift/templates", filename="django.json" ) assert self.oc_api.deploy_template( template=template_json, name_in_template="django-example", expected_output=expected_output,