From 9129fde56c718f268940adaed9a872ed1f4960ab Mon Sep 17 00:00:00 2001 From: Koshy John Date: Thu, 20 Mar 2025 14:38:47 -0700 Subject: [PATCH 1/2] Test code comment explanation --- src/core/src/core_logic/ExecutionConfig.py | 6 +-- src/core/tests/Test_ExecutionConfig.py | 44 ++++++---------------- 2 files changed, 14 insertions(+), 36 deletions(-) diff --git a/src/core/src/core_logic/ExecutionConfig.py b/src/core/src/core_logic/ExecutionConfig.py index e5d0ab36..04cec562 100644 --- a/src/core/src/core_logic/ExecutionConfig.py +++ b/src/core/src/core_logic/ExecutionConfig.py @@ -108,9 +108,9 @@ def __get_max_patch_publish_date(self, health_store_id): """ Obtains implicit date ceiling for published date - converts pub_off_sku_2024.04.01 to 20240401T000000Z """ max_patch_publish_date = str() if health_store_id is not None and health_store_id != "": - split = health_store_id.rsplit("_", 1) - if len(split) == 2 and len(split[1]) == 10: - max_patch_publish_date = "{0}T000000Z".format(split[1].replace(".", "")) + date_candidate = str(health_store_id)[-10:].replace(".", "") # last 10 characters and remove '.' + if len(date_candidate) == 8 and date_candidate.isdigit() and str(health_store_id)[-11:-10] == "_": + max_patch_publish_date = date_candidate + "T000000Z" self.composite_logger.log_debug("[EC] Getting max patch publish date. [MaxPatchPublishDate={0}][HealthStoreId={1}]".format(str(max_patch_publish_date), str(health_store_id))) return max_patch_publish_date diff --git a/src/core/tests/Test_ExecutionConfig.py b/src/core/tests/Test_ExecutionConfig.py index d6047918..f0298c31 100644 --- a/src/core/tests/Test_ExecutionConfig.py +++ b/src/core/tests/Test_ExecutionConfig.py @@ -27,42 +27,20 @@ def setUp(self): def tearDown(self): pass - def test_healthstoreid_acceptable_format(self): - argument_composer = ArgumentComposer() - argument_composer.health_store_id = str("pub_off_sku_2020.09.29") - runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.YUM) - self.assertTrue(runtime.execution_config.max_patch_publish_date == "20200929T000000Z") - runtime.stop() - - argument_composer = ArgumentComposer() - argument_composer.health_store_id = str("pu_b_off_sk_u_2020.09.29") - runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.YUM) - self.assertTrue(runtime.execution_config.max_patch_publish_date == "20200929T000000Z") - runtime.stop() - - def test_healthstoreid_unacceptable_format(self): - argument_composer = ArgumentComposer() - argument_composer.health_store_id = str() - runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.YUM) - self.assertTrue(runtime.execution_config.max_patch_publish_date == str()) - runtime.stop() - - argument_composer = ArgumentComposer() - argument_composer.health_store_id = str("pub_off_sku_20.09.29") - runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.YUM) - self.assertTrue(runtime.execution_config.max_patch_publish_date == str()) - runtime.stop() - - argument_composer = ArgumentComposer() - argument_composer.health_store_id = str("pub_off_sku_2020.9.29") - runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.YUM) - self.assertTrue(runtime.execution_config.max_patch_publish_date == str()) - runtime.stop() + def test_get_max_patch_publish_date(self): + test_input_output_table = [ + ["pub_off_sku_2020.09.29", "20200929T000000Z"], + ["pu_b_off_sk_u_2020.09.29", "20200929T000000Z"], + [str(), str()], + ["pub_off_sku_20.09.29", str()], + ["pub_off_sku_2020.9.29", str()], + ["pub_off_sk_u2020.09.29", str()] + ] argument_composer = ArgumentComposer() - argument_composer.health_store_id = str("pub_off_sk_u2020.09.29") runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.YUM) - self.assertTrue(runtime.execution_config.max_patch_publish_date == str()) + for row in test_input_output_table: + self.assertEqual(runtime.execution_config._ExecutionConfig__get_max_patch_publish_date(row[0]), row[1]) runtime.stop() From e11b537ad33df03ed0f50997abfea9c8c5afc8ee Mon Sep 17 00:00:00 2001 From: Koshy John Date: Thu, 20 Mar 2025 14:41:42 -0700 Subject: [PATCH 2/2] Validate against prod code comment --- src/core/tests/Test_ExecutionConfig.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/tests/Test_ExecutionConfig.py b/src/core/tests/Test_ExecutionConfig.py index f0298c31..60515c7a 100644 --- a/src/core/tests/Test_ExecutionConfig.py +++ b/src/core/tests/Test_ExecutionConfig.py @@ -34,7 +34,8 @@ def test_get_max_patch_publish_date(self): [str(), str()], ["pub_off_sku_20.09.29", str()], ["pub_off_sku_2020.9.29", str()], - ["pub_off_sk_u2020.09.29", str()] + ["pub_off_sk_u2020.09.29", str()], + ["x_2020.09.29", "20200929T000000Z"] # theoretically okay ] argument_composer = ArgumentComposer()