Skip to content

tests(code_mappings): Remove usage of called_with assertions #43199

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

Merged
merged 6 commits into from
Jan 13, 2023

Conversation

armenzg
Copy link
Member

@armenzg armenzg commented Jan 12, 2023

In #42712 it was reported that the usage of called_with is not correct.

I tried using assert_called_with but there were various issues to fix it.

… it was not testing what we intended.

Unfortunately, I have not been able to fix it in any of the cases.
In #42712 it was reported that are usage of `called_with` is incorrect.

Unfortunately, using `assert_called_with` does not work because comparing `NodeData` would require extra work to make the comparison of two objects work well.
In #42712 it was reported that the usage of `called_with` is not correct and it indeed does not work.

This part of the test is not as important as it used to be. We can remove it.
@@ -72,10 +70,6 @@ class GitHubIntegrationTest(IntegrationTestCase):
provider = GitHubIntegrationProvider
base_url = "https://api.github.com"

@pytest.fixture(autouse=True)
def inject_fixtures(self, caplog):
Copy link
Member Author

Choose a reason for hiding this comment

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

This is not needed anymore since we won't do assertions in the logger.

@@ -643,33 +637,22 @@ def test_get_trees_for_org(self):
),
}

with patch("sentry.integrations.utils.code_mapping.logger") as logger:
Copy link
Member Author

Choose a reason for hiding this comment

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

This is mostly a left indent since we won't be patching the logger anymore.

with patch("sentry.integrations.utils.code_mapping.logger") as logger:
assert not cache.get("githubtrees:repositories:Test-Organization")
# This allows checking for caching related output
self._caplog.set_level(logging.INFO, logger="sentry")
Copy link
Member Author

Choose a reason for hiding this comment

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

Removing this line.

"The Github App does not have access to Test-Organization/baz.",
"Caching trees for Test-Organization",
]:
assert logger.info.called_with(msg)
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed this block.


# Calling a second time should produce the same results
trees = installation.get_trees_for_org()
assert logger.info.called_with("Using cached trees for Test-Organization.")
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed this line.

self._call_post_process_group(data)
assert mock_derive_code_mappings.delay.call_count == 1
# Because we only run on dry run mode even if the official flag is set
assert mock_derive_code_mappings.delay.called_with(self.project.id, data, True)
Copy link
Member Author

Choose a reason for hiding this comment

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

I tried switching to assert_called_with, however, the NodeData object event though it was the same was not handling well comparing one of it's properties. IIRC correctly, a dictionary of properties would not compared to be the same because the key/values were out of order.

Instead of working to fix the comparison I decided to remove it. If we ever change the delay call, we should spend time to change it to not use a NodeData by extracting the information we need (e.g. stacktrace and project info).

Copy link
Member

Choose a reason for hiding this comment

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

Removing the test seems okay. FYI Python introduced ordering in dictionaries, based on order of insertion as of 3.6 or 3.7.

@armenzg armenzg marked this pull request as ready for review January 13, 2023 13:47
@armenzg armenzg requested review from a team January 13, 2023 13:47
@armenzg armenzg merged commit 1e30da4 into master Jan 13, 2023
@armenzg armenzg deleted the armenzg/code-mappings/fix-derive-code-mappings-tests branch January 13, 2023 18:54
@github-actions github-actions bot locked and limited conversation to collaborators Jan 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants