|
6 | 6 | from conftest import VARS |
7 | 7 |
|
8 | 8 |
|
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] |
21 | 12 | ) |
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() |
24 | 24 |
|
| 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. |
25 | 38 |
|
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) |
40 | 59 |
|
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, |
54 | 65 | ) |
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 |
62 | 69 |
|
| 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 |
63 | 80 |
|
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 |
71 | 81 |
|
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, |
80 | 86 | ) |
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) |
0 commit comments