Skip to content

Commit

Permalink
Dynamically generate invalid config files in unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: aadityasinha-dotcom <[email protected]>
  • Loading branch information
aadityasinha-dotcom committed Oct 10, 2023
1 parent a7e61a9 commit 0e3b5c4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/core/zowe/core_for_zowe_sdk/config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/fixtures/invalid.zowe.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 7 additions & 2 deletions tests/unit/test_zowe_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0e3b5c4

Please sign in to comment.