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..60515c7a 100644 --- a/src/core/tests/Test_ExecutionConfig.py +++ b/src/core/tests/Test_ExecutionConfig.py @@ -27,42 +27,21 @@ 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()], + ["x_2020.09.29", "20200929T000000Z"] # theoretically okay + ] 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()