-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Changes from all commits
9e5e00b
eb2b1b4
3190af2
7e1a091
7cee354
575bd3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import logging | ||
from unittest.mock import MagicMock, patch | ||
from urllib.parse import urlencode, urlparse | ||
|
||
import pytest | ||
import responses | ||
from django.urls import reverse | ||
|
||
|
@@ -72,10 +70,6 @@ class GitHubIntegrationTest(IntegrationTestCase): | |
provider = GitHubIntegrationProvider | ||
base_url = "https://api.github.com" | ||
|
||
@pytest.fixture(autouse=True) | ||
def inject_fixtures(self, caplog): | ||
self._caplog = caplog | ||
|
||
def setUp(self): | ||
super().setUp() | ||
|
||
|
@@ -643,33 +637,22 @@ def test_get_trees_for_org(self): | |
), | ||
} | ||
|
||
with patch("sentry.integrations.utils.code_mapping.logger") as logger: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
assert not cache.get("githubtrees:repositories:Test-Organization") | ||
# This allows checking for caching related output | ||
self._caplog.set_level(logging.INFO, logger="sentry") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this line. |
||
# Check that the cache is clear | ||
repo_key = "github:repo:Test-Organization/foo:source-code" | ||
assert cache.get("githubtrees:repositories:foo:Test-Organization") is None | ||
assert cache.get(repo_key) is None | ||
trees = installation.get_trees_for_org() | ||
|
||
# These checks are useful since they will be available in the GCP logs | ||
for msg in [ | ||
"The Github App does not have access to Test-Organization/baz.", | ||
"Caching trees for Test-Organization", | ||
]: | ||
assert logger.info.called_with(msg) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed this block. |
||
|
||
assert cache.get("githubtrees:repositories:foo:Test-Organization") == [ | ||
{"full_name": "Test-Organization/foo", "default_branch": "master"}, | ||
{"full_name": "Test-Organization/bar", "default_branch": "main"}, | ||
{"full_name": "Test-Organization/baz", "default_branch": "master"}, | ||
{"full_name": "Test-Organization/xyz", "default_branch": "master"}, | ||
] | ||
assert cache.get(repo_key) == ["src/sentry/api/endpoints/auth_login.py"] | ||
assert trees == expected_trees | ||
assert not cache.get("githubtrees:repositories:Test-Organization") | ||
# Check that the cache is clear | ||
repo_key = "github:repo:Test-Organization/foo:source-code" | ||
assert cache.get("githubtrees:repositories:foo:Test-Organization") is None | ||
assert cache.get(repo_key) is None | ||
trees = installation.get_trees_for_org() | ||
|
||
assert cache.get("githubtrees:repositories:foo:Test-Organization") == [ | ||
{"full_name": "Test-Organization/foo", "default_branch": "master"}, | ||
{"full_name": "Test-Organization/bar", "default_branch": "main"}, | ||
{"full_name": "Test-Organization/baz", "default_branch": "master"}, | ||
{"full_name": "Test-Organization/xyz", "default_branch": "master"}, | ||
] | ||
assert cache.get(repo_key) == ["src/sentry/api/endpoints/auth_login.py"] | ||
assert trees == expected_trees | ||
|
||
# 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.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed this line. |
||
assert trees == expected_trees | ||
# Calling a second time should produce the same results | ||
trees = installation.get_trees_for_org() | ||
assert trees == expected_trees |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
from sentry.models.activity import ActivityIntegration | ||
from sentry.ownership.grammar import Matcher, Owner, Rule, dump_schema | ||
from sentry.rules import init_registry | ||
from sentry.tasks.derive_code_mappings import SUPPORTED_LANGUAGES | ||
from sentry.tasks.merge import merge_groups | ||
from sentry.tasks.post_process import post_process_group, process_event | ||
from sentry.testutils import SnubaTestCase, TestCase | ||
|
@@ -173,19 +174,10 @@ def test_derive_invalid_platform(self, mock_derive_code_mappings): | |
assert mock_derive_code_mappings.delay.call_count == 0 | ||
|
||
@patch("sentry.tasks.derive_code_mappings.derive_code_mappings") | ||
def test_derive_python(self, mock_derive_code_mappings): | ||
data = {"platform": "python"} | ||
self._call_post_process_group(data) | ||
assert mock_derive_code_mappings.delay.call_count == 1 | ||
assert mock_derive_code_mappings.delay.called_with(self.project.id, data, False) | ||
|
||
@patch("sentry.tasks.derive_code_mappings.derive_code_mappings") | ||
def test_derive_js(self, mock_derive_code_mappings): | ||
data = {"platform": "javascript"} | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried switching to 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). There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
def test_derive_supported_languages(self, mock_derive_code_mappings): | ||
for platform in SUPPORTED_LANGUAGES: | ||
self._call_post_process_group({"platform": platform}) | ||
assert mock_derive_code_mappings.delay.call_count == 1 | ||
|
||
|
||
class RuleProcessorTestMixin(BasePostProgressGroupMixin): | ||
|
There was a problem hiding this comment.
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.