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

tests(code_mapping): Remove logging assertions #43152

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
52 changes: 18 additions & 34 deletions tests/sentry/integrations/github/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
from unittest.mock import MagicMock, patch
from urllib.parse import urlencode, urlparse

Expand Down Expand Up @@ -72,10 +71,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()

Expand Down Expand Up @@ -643,33 +638,22 @@ def test_get_trees_for_org(self):
),
}

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")
# 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)

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.")
assert trees == expected_trees
# Calling a second time should produce the same results
trees = installation.get_trees_for_org()
assert trees == expected_trees