From 0e3b5c46528bcec584616ea8df6fca63dcde53fc Mon Sep 17 00:00:00 2001 From: aadityasinha-dotcom Date: Tue, 10 Oct 2023 21:55:27 +0530 Subject: [PATCH] Dynamically generate invalid config files in unit tests Signed-off-by: aadityasinha-dotcom --- src/core/zowe/core_for_zowe_sdk/config_file.py | 1 + tests/unit/fixtures/invalid.zowe.schema.json | 4 ++-- tests/unit/test_zowe_core.py | 9 +++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/core/zowe/core_for_zowe_sdk/config_file.py b/src/core/zowe/core_for_zowe_sdk/config_file.py index b9e01b3d..aab694f5 100644 --- a/src/core/zowe/core_for_zowe_sdk/config_file.py +++ b/src/core/zowe/core_for_zowe_sdk/config_file.py @@ -158,6 +158,7 @@ def validate_schema( # validate the $schema property if path_schema_json: + print(self.jsonc, path_schema_json) validate_config_json(self.jsonc, path_schema_json, cwd = self.location) def schema_list( diff --git a/tests/unit/fixtures/invalid.zowe.schema.json b/tests/unit/fixtures/invalid.zowe.schema.json index cbb1cc9a..8d1a8a22 100644 --- a/tests/unit/fixtures/invalid.zowe.schema.json +++ b/tests/unit/fixtures/invalid.zowe.schema.json @@ -76,9 +76,9 @@ "description": "The z/OSMF server host name." }, "port": { - "type": "number", + "type": "string", "description": "The z/OSMF server port.", - "default": 443 + "default": "443" }, "user": { "type": "string", diff --git a/tests/unit/test_zowe_core.py b/tests/unit/test_zowe_core.py index bf71ef6f..03fd4097 100644 --- a/tests/unit/test_zowe_core.py +++ b/tests/unit/test_zowe_core.py @@ -633,9 +633,14 @@ def test_profile_loading_with_invalid_schema(self, get_pass_func): # Setup - copy profile to fake filesystem created by pyfakefs with self.assertRaises(ValidationError): custom_file_path = os.path.join(self.custom_dir, "invalid.zowe.config.json") - shutil.copy(self.original_invalid_file_path, custom_file_path) - shutil.copy(self.original_invalid_schema_file_path, self.custom_dir) + # shutil.copy(self.original_invalid_file_path, custom_file_path) + # shutil.copy(self.original_invalid_schema_file_path, self.custom_dir) os.chdir(self.custom_dir) + with open(self.original_file_path, 'r') as f: + original_config = commentjson.load(f) + original_config["$schema"] = "./invalid.zowe.schema.json" + with open(os.path.join(self.custom_dir, "invalid.zowe.config.json"), 'w') as f: + commentjson.dump(original_config, f) self.setUpCreds(custom_file_path, { "profiles.zosmf.properties.user": "user",