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

Update assertInstanceEqual to fix JSON comparison of 'data_schema' keys. #3568

Merged

Conversation

PavelSafronov
Copy link
Contributor

This fixes the issue where assertInstanceEqual test code was relying on JSON columns to have the same formatting as the incoming data, which is typically not the case.

Closes: #3116

What's Changed

Update assertInstanceEqual to fix JSON comparison of 'data_schema' keys.
This fixes the issue where assertInstanceEqual test code was relying on JSON columns to have the same formatting as the incoming data, which is typically not the case.
This only impacts test code.

This fixes the issue where assertInstanceEqual was relying on JSON columns to have the same formatting as the incoming data, which is typically not the case.
Copy link
Contributor

@jathanism jathanism left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

@@ -284,7 +284,7 @@ def setUpTestData(cls):
cls.form_data = {
"name": "Schema X",
"slug": "schema-x",
"data_schema": '{"type": "object", "properties": {"baz": {"type": "string"}}}',
"data_schema": '{"type": "object","properties": {"baz": {"type": "string"}}}',
Copy link
Contributor

@jathanism jathanism Apr 11, 2023

Choose a reason for hiding this comment

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

Please revert this line, or is the expectation here that this is what comes back from MySQL? If so, can you please add a comment that explains why this is so?

Or... Could we instead rely on the mixin code to sort this? I'm asking because if someone like myself see the lack of a space between commas and tries to "fix" it without context, we might have a bad time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please revert this line, or is the expectation here that this is what comes back from MySQL? If so, can you please add a comment that explains why this is so?

The change is actually to intentionally introduce a difference between input and MySQL output.

If you revert the other changes in this PR but keep this line, nautobot tests will start to fail, because they are testing that the input string (this one) is identical to the JSON returned by MySQL. I wanted to include this not-quite-formatted JSON to ensure that the correct JSON formatting is happening in the test.

I can keep this line and add the above explanation, or revert this change. Up to you. I get that it's weird to have poorly-formatted JSON as a test input.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please keep the line and add the comment to explain for posterity. Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like @bryanculver got there first and added the comment about formatting, no action required on my part. Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

😎

Comment on lines 225 to 226
newJsonText = json.dumps(obj, sort_keys=True)
return newJsonText
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
newJsonText = json.dumps(obj, sort_keys=True)
return newJsonText
return json.dumps(obj, sort_keys=True)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will make this change.

Comment on lines 223 to 224
def standardize_json(self, jsonText):
obj = json.loads(jsonText)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know I'm being pedantic, but we don't use camelCase in Python and our linters will scream.

Suggested change
def standardize_json(self, jsonText):
obj = json.loads(jsonText)
def standardize_json(self, data):
obj = json.loads(data)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, thanks for clarifying, fixing! This is my first time with Python, so I'm happy to learn the conventions.

- avoid unnecessary variable
- avoid camelCase in parameters
@bryanculver bryanculver mentioned this pull request Apr 14, 2023
6 tasks
Copy link
Contributor

@jathanism jathanism left a comment

Choose a reason for hiding this comment

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

Looking great! Thanks for the straightforward fix. If you could please just address the one comment, this is good to go.

@glennmatthews glennmatthews merged commit bc7a89c into nautobot:develop Apr 14, 2023
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tests are making assumptions about underlying data
4 participants