Skip to content

Commit 477cbdc

Browse files
committed
Use VARS.TEST_APP instead of string
Use variable TEST_DIR instead of again definition. Check if both variables asserts. Use and operator Use already defined variable instead of hardcoding them Co-authored-by: Lumír 'Frenzy' Balhar <frenzy.madness@gmail.com> Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
1 parent 9776469 commit 477cbdc

File tree

4 files changed

+29
-25
lines changed

4 files changed

+29
-25
lines changed

test/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
OS=OS,
3838
VERSION=VERSION,
3939
IMAGE_NAME=os.getenv("IMAGE_NAME"),
40-
TEST_DIR=Path(__file__).parent.absolute(),
40+
TEST_DIR=TEST_DIR,
4141
TAG=TAGS.get(OS),
4242
TEST_APP=TEST_APP,
4343
VERY_LONG_DB_NAME=VERY_LONG_DB_NAME,

test/test_container_basics.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ def teardown_method(self):
3939
"""
4040
self.app_image.cleanup()
4141

42-
def test_s2i_usage(self):
42+
def test_connection_without_mount(self):
4343
"""
4444
Test if MySQL container failed in case of invalid combinations.
4545
Steps are:
4646
1. Test if the container creation fails with invalid combinations of arguments
4747
2. Test if the container creation succeeds with valid combinations of arguments
4848
3. Test if the database connection works
4949
"""
50-
cid_config_build = "s2i_usage_build"
50+
cid_mount = "connection_without_mount"
5151
self.app_image.assert_container_creation_fails(
52-
cid_file_name=cid_config_build,
52+
cid_file_name=cid_mount,
5353
command="",
5454
container_args=[
5555
"-e MYSQL_USER=root",
@@ -58,24 +58,26 @@ def test_s2i_usage(self):
5858
"-e MYSQL_ROOT_PASSWORD=pass",
5959
],
6060
)
61+
operation_user = "operations_user"
62+
operation_pass = "operations_pass"
6163
assert self.app_image.create_container(
62-
cid_file_name=cid_config_build,
64+
cid_file_name=cid_mount,
6365
container_args=[
6466
"-e MYSQL_USER=config_test_user",
6567
"-e MYSQL_PASSWORD=config_test_user",
6668
"-e MYSQL_DATABASE=db",
67-
"-e MYSQL_OPERATIONS_USER=operations_user",
68-
"-e MYSQL_OPERATIONS_PASSWORD=operations_user",
69+
f"-e MYSQL_OPERATIONS_USER={operation_user}",
70+
f"-e MYSQL_OPERATIONS_PASSWORD={operation_pass}",
6971
],
7072
)
71-
cip, cid = self.app_image.get_cip_cid(cid_file_name=cid_config_build)
72-
assert cip, cid
73+
cip, cid = self.app_image.get_cip_cid(cid_file_name=cid_mount)
74+
assert cip and cid
7375
assert self.app_image.test_db_connection(
74-
container_ip=cip, username="operations_user", password="operations_user"
76+
container_ip=cip, username=operation_user, password=operation_pass
7577
)
7678
PodmanCLIWrapper.call_podman_command(cmd=f"stop {cid}")
7779

78-
def test_s2i_usage_with_mount(self):
80+
def test_connection_with_mount(self):
7981
"""
8082
Test if the MySQL container works properly with mounted application directory.
8183
Steps are:
@@ -84,30 +86,33 @@ def test_s2i_usage_with_mount(self):
8486
3. Test if the database connection works with the operations user
8587
"""
8688
data_dir = tempfile.mkdtemp(prefix="/tmp/mysql-test_data")
87-
shutil.copytree(VARS.TEST_DIR / "test-app", f"{data_dir}/test-app")
89+
shutil.copytree(VARS.TEST_APP, f"{data_dir}/test-app")
8890
assert ContainerTestLibUtils.commands_to_run(
8991
commands_to_run=[
9092
f"chown -R 27:27 {data_dir}/test-app",
9193
]
9294
)
93-
cid_s2i_test_mount = "s2i_test_mount"
95+
cid_with_mount = "connection_with_mount"
96+
operation_user = "operations_user"
97+
operation_pass = "operations_pass"
98+
9499
self.app_image.create_container(
95-
cid_file_name=cid_s2i_test_mount,
100+
cid_file_name=cid_with_mount,
96101
container_args=[
97102
"-e MYSQL_USER=config_test_user",
98103
"-e MYSQL_PASSWORD=config_test_user",
99104
"-e MYSQL_DATABASE=db",
100-
"-e MYSQL_OPERATIONS_USER=operations_user",
101-
"-e MYSQL_OPERATIONS_PASSWORD=operations_pass",
105+
f"-e MYSQL_OPERATIONS_USER={operation_user}",
106+
f"-e MYSQL_OPERATIONS_PASSWORD={operation_pass}",
102107
f"-v {data_dir}/test-app:/opt/app-root/src/:z",
103108
],
104109
)
105-
cip, cid = self.app_image.get_cip_cid(cid_file_name=cid_s2i_test_mount)
106-
assert cip, cid
110+
cip, cid = self.app_image.get_cip_cid(cid_file_name=cid_with_mount)
111+
assert cip and cid
107112
assert self.app_image.test_db_connection(
108113
container_ip=cip,
109-
username="operations_user",
110-
password="operations_pass",
114+
username=operation_user,
115+
password=operation_pass,
111116
max_attempts=10,
112117
)
113118
PodmanCLIWrapper.call_podman_command(cmd=f"stop {cid}")

test/test_container_configuration.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def test_configuration_auto_calculated_settings(self):
173173
docker_args="--memory=512m",
174174
)
175175
cip, cid = self.db_config.get_cip_cid(cid_file_name=cid_config_test)
176-
assert cip, cid
176+
assert cip and cid
177177
assert self.db_config.test_db_connection(
178178
container_ip=cip,
179179
username=username,
@@ -217,7 +217,6 @@ def test_configuration_auto_calculated_settings(self):
217217
assert "COLLATE=latin2_czech_cs" in show_table_output
218218
PodmanCLIWrapper.call_podman_command(cmd=f"stop {cid}")
219219

220-
# FIX
221220
def test_configuration_options_settings(self):
222221
"""
223222
Test MySQL container configuration options.
@@ -249,7 +248,7 @@ def test_configuration_options_settings(self):
249248
],
250249
)
251250
cip, cid = self.db_config.get_cip_cid(cid_file_name=cid_config_test)
252-
assert cip, cid
251+
assert cip and cid
253252
assert self.db_config.test_db_connection(
254253
container_ip=cip,
255254
username=username,

test/test_container_general.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ def test_datadir_actions(self):
188188
],
189189
)
190190
cip, cid = self.db_image.get_cip_cid(cid_file_name=cid_testupg1)
191-
assert cip, cid
191+
assert cip and cid
192192
assert self.db_image.test_db_connection(
193-
container_ip=cip, username="user", password="foo"
193+
container_ip=cip, username=mysql_user, password=mysql_password
194194
)
195195
PodmanCLIWrapper.call_podman_command(cmd=f"stop {cid}")
196196

0 commit comments

Comments
 (0)