Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically generate invalid config files in unit tests #220

Merged
merged 12 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/zowe/core_for_zowe_sdk/config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ def validate_schema(self) -> None:

# validate the $schema property
if path_schema_json:
validate_config_json(self.jsonc, path_schema_json, cwd=self.location)
print(self.jsonc, path_schema_json)
validate_config_json(self.jsonc, path_schema_json, cwd = self.location)

def schema_list(
self,
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 @@ -610,9 +610,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)
aadityasinha-dotcom marked this conversation as resolved.
Show resolved Hide resolved
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:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remove the files like invalid.zowe.config.json or invalidUri.zowe.config.json because other tests were failing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other tests are probably failing because the setUp stage still expects the "invalid" files to exist:

self.fs.add_real_file(self.original_invalid_file_path)
self.fs.add_real_file(self.original_invalid_schema_file_path)
self.fs.add_real_file(self.original_invalidUri_file_path)
self.fs.add_real_file(self.original_invalidUri_schema_file_path)

I think this can be fixed by moving the add_real_file calls for invalid.zowe.config.json inside the specific tests where the files are created.

commentjson.dump(original_config, f)

self.setUpCreds(
custom_file_path,
Expand Down
Loading