Skip to content

Commit df1b3e2

Browse files
committed
Add Unstable app to PyTest suite.
Fix proper branch in `test_dockerfiles` function. Add test suite to Class and build application once. Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
1 parent 8249fc6 commit df1b3e2

File tree

3 files changed

+107
-68
lines changed

3 files changed

+107
-68
lines changed

test/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"TEST_DIR",
3030
"WEB_APPS",
3131
"SHOULD_FAIL_WEB_APPS",
32+
"UNSTABLE_WEB_APP",
3233
"BRANCH_TO_TEST",
3334
"DEPLOYED_PSQL_IMAGE",
3435
"IMAGE_TAG",
@@ -61,7 +62,6 @@
6162
"numpy",
6263
"app-home",
6364
"locale",
64-
"pipenv",
6565
"app-module",
6666
"pyuwsgi-pipenv",
6767
"micropipenv",
@@ -83,7 +83,9 @@
8383
SHOULD_FAIL_WEB_APPS = [
8484
TEST_DIR / "pipenv-and-micropipenv-should-fail-test-app",
8585
]
86-
86+
UNSTABLE_WEB_APP = [
87+
"pipenv-test-app",
88+
]
8789
MINIMAL_WEB_APPS: list[Path] = []
8890
if "minimal" in VERSION:
8991
WEB_APPS = COMMON_WEB_APPS
@@ -101,6 +103,7 @@
101103
TEST_DIR=TEST_DIR,
102104
WEB_APPS=WEB_APPS,
103105
SHOULD_FAIL_WEB_APPS=SHOULD_FAIL_WEB_APPS,
106+
UNSTABLE_WEB_APP=UNSTABLE_WEB_APP,
104107
BRANCH_TO_TEST=BRANCH_TO_TEST,
105108
DEPLOYED_PSQL_IMAGE=DEPLOYED_PSQL_IMAGE,
106109
IMAGE_TAG=IMAGE_TAG,

test/test_container_application.py

Lines changed: 101 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,76 +6,113 @@
66
from conftest import VARS
77

88

9-
@pytest.fixture(params=VARS.WEB_APPS, ids=[app.name for app in VARS.WEB_APPS])
10-
def build_s2i_app(request) -> ContainerTestLib:
11-
"""
12-
Build a S2I application.
13-
"""
14-
container_lib = ContainerTestLib(VARS.IMAGE_NAME)
15-
app_name = request.param.name
16-
s2i_app = container_lib.build_as_df(
17-
app_path=request.param,
18-
s2i_args="--pull-policy=never",
19-
src_image=VARS.IMAGE_NAME,
20-
dst_image=f"{VARS.IMAGE_NAME}-{app_name}",
9+
class TestPythonApplication:
10+
@pytest.fixture(
11+
scope="class", params=VARS.WEB_APPS, ids=[app.name for app in VARS.WEB_APPS]
2112
)
22-
yield s2i_app
23-
s2i_app.cleanup()
13+
def build_s2i_app(self, request):
14+
container_lib = ContainerTestLib(VARS.IMAGE_NAME)
15+
app_name = request.param.name
16+
s2i_app = container_lib.build_as_df(
17+
app_path=request.param,
18+
s2i_args="--pull-policy=never",
19+
src_image=VARS.IMAGE_NAME,
20+
dst_image=f"{VARS.IMAGE_NAME}-{app_name}",
21+
)
22+
yield s2i_app
23+
s2i_app.cleanup()
2424

25+
@pytest.mark.parametrize(
26+
"container_args",
27+
[
28+
"--user 100001",
29+
"--user 12345",
30+
"-e ENABLE_INIT_WRAPPER=true",
31+
],
32+
)
33+
def test_application(self, build_s2i_app, container_args):
34+
"""
35+
Test if container works
36+
Python version is properly set
37+
Application response on specific port and specific URL.
2538
26-
@pytest.mark.usefixtures("build_s2i_app")
27-
@pytest.mark.parametrize(
28-
"container_args",
29-
[
30-
"--user 100001",
31-
"--user 12345",
32-
"-e ENABLE_INIT_WRAPPER=true",
33-
],
34-
)
35-
def test_application(build_s2i_app, container_args):
36-
"""
37-
Test if container works
38-
Python version is properly set
39-
Application response on specific port and specific URL.
39+
"""
40+
cid_file_name = build_s2i_app.app_name
41+
assert build_s2i_app.create_container(
42+
cid_file_name=cid_file_name,
43+
container_args=container_args,
44+
)
45+
assert ContainerImage.wait_for_cid(cid_file_name=cid_file_name)
46+
python_version = PodmanCLIWrapper.podman_run_command_and_remove(
47+
cid_file_name=VARS.IMAGE_NAME, cmd="echo \\$PYTHON_VERSION"
48+
).strip()
49+
python_version_output = PodmanCLIWrapper.podman_run_command_and_remove(
50+
cid_file_name=VARS.IMAGE_NAME, cmd="python --version"
51+
)
52+
assert f"Python {python_version}." in python_version_output
53+
cip = build_s2i_app.get_cip(cid_file_name=cid_file_name)
54+
assert cip
55+
port = 8080
56+
if "different-port" in build_s2i_app.app_name:
57+
port = 8085
58+
assert build_s2i_app.test_response(url=f"http://{cip}", port=port)
4059

41-
"""
42-
s2i_app = build_s2i_app
43-
cid_file_name = s2i_app.app_name
44-
assert s2i_app.create_container(
45-
cid_file_name=cid_file_name,
46-
container_args=container_args,
47-
)
48-
assert ContainerImage.wait_for_cid(cid_file_name=cid_file_name)
49-
python_version = PodmanCLIWrapper.podman_run_command_and_remove(
50-
cid_file_name=VARS.IMAGE_NAME, cmd="echo \\$PYTHON_VERSION"
51-
).strip()
52-
python_version_output = PodmanCLIWrapper.podman_run_command_and_remove(
53-
cid_file_name=VARS.IMAGE_NAME, cmd="python --version"
60+
61+
class TestPythonShouldFailApplication:
62+
@pytest.mark.parametrize(
63+
"should_fail_app",
64+
VARS.SHOULD_FAIL_WEB_APPS,
5465
)
55-
assert f"Python {python_version}." in python_version_output
56-
cip = s2i_app.get_cip(cid_file_name=cid_file_name)
57-
assert cip
58-
port = 8080
59-
if "different-port" in s2i_app.app_name:
60-
port = 8085
61-
assert s2i_app.test_response(url=f"http://{cip}", port=port)
66+
def test_application_should_fail(self, should_fail_app):
67+
"""
68+
Test if build fails for should fail apps
6269
70+
"""
71+
container_lib = ContainerTestLib(VARS.IMAGE_NAME)
72+
app_name = should_fail_app.name
73+
s2i_app_should_fail = container_lib.build_as_df(
74+
app_path=should_fail_app,
75+
s2i_args="--pull-policy=never",
76+
src_image=VARS.IMAGE_NAME,
77+
dst_image=f"{VARS.IMAGE_NAME}-{app_name}",
78+
)
79+
assert not s2i_app_should_fail
6380

64-
@pytest.mark.parametrize(
65-
"should_fail_app",
66-
VARS.SHOULD_FAIL_WEB_APPS,
67-
)
68-
def test_application_should_fail(should_fail_app):
69-
"""
70-
Test if build fails for should fail apps
7181

72-
"""
73-
container_lib = ContainerTestLib(VARS.IMAGE_NAME)
74-
app_name = should_fail_app.name
75-
s2i_app_should_fail = container_lib.build_as_df(
76-
app_path=should_fail_app,
77-
s2i_args="--pull-policy=never",
78-
src_image=VARS.IMAGE_NAME,
79-
dst_image=f"{VARS.IMAGE_NAME}-{app_name}",
82+
class TestPythonUnstableApplication:
83+
@pytest.mark.parametrize(
84+
"unstable_app",
85+
VARS.UNSTABLE_WEB_APP,
8086
)
81-
assert not s2i_app_should_fail
87+
def test_unstable_test(self, unstable_app):
88+
"""
89+
Test if unstable test works
90+
"""
91+
container_lib = ContainerTestLib(VARS.IMAGE_NAME)
92+
s2i_app_unstable = container_lib.build_as_df(
93+
app_path=VARS.TEST_DIR / f"{unstable_app}-test-app",
94+
s2i_args="--pull-policy=never",
95+
src_image=VARS.IMAGE_NAME,
96+
dst_image=f"{VARS.IMAGE_NAME}-{unstable_app}",
97+
)
98+
if not s2i_app_unstable:
99+
pytest.skip(f"Build failed for unstable app {unstable_app}")
100+
cid_file_name = s2i_app_unstable.app_name
101+
assert s2i_app_unstable.create_container(
102+
cid_file_name=cid_file_name,
103+
container_args=s2i_app_unstable,
104+
)
105+
assert ContainerImage.wait_for_cid(cid_file_name=cid_file_name)
106+
python_version = PodmanCLIWrapper.podman_run_command_and_remove(
107+
cid_file_name=VARS.IMAGE_NAME, cmd="echo \\$PYTHON_VERSION"
108+
).strip()
109+
python_version_output = PodmanCLIWrapper.podman_run_command_and_remove(
110+
cid_file_name=VARS.IMAGE_NAME, cmd="python --version"
111+
)
112+
assert f"Python {python_version}." in python_version_output
113+
cip = s2i_app_unstable.get_cip(cid_file_name=cid_file_name)
114+
assert cip
115+
port = 8080
116+
if "different-port" in s2i_app_unstable.app_name:
117+
port = 8085
118+
assert s2i_app_unstable.test_response(url=f"http://{cip}", port=port)

test/test_container_basics.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ def test_scl_usage(self):
7878
def test_dockerfiles(self, dockerfile):
7979
if "minimal" in VARS.VERSION:
8080
pytest.skip("Skipping tests 'test_dockerfiles' for minimal versions.")
81-
app_url = f"https://github.com/sclorg/django-ex.git@{VARS.BRANCH_TO_TEST}"
8281
assert self.app.build_test_container(
8382
dockerfile=VARS.TEST_DIR / "from-dockerfile" / dockerfile,
84-
app_url=app_url,
83+
app_url="https://github.com/sclorg/django-ex.git@4.2.x",
8584
app_dir="app-src",
8685
)
8786
assert self.app.test_app_dockerfile()

0 commit comments

Comments
 (0)