1- from datetime import timedelta
1+ from datetime import datetime , timedelta
2+ from datetime import timezone as datetime_timezone
23from unittest .mock import Mock , patch
34
45import pytest
@@ -83,7 +84,9 @@ class TestCommitContext(TestCommitContextMixin):
8384 "sentry.integrations.github.GitHubIntegration.get_commit_context" ,
8485 return_value = {
8586 "commitId" : "asdfwreqr" ,
86- "committedDate" : "2023-02-14T11:11Z" ,
87+ "committedDate" : (datetime .now (tz = datetime_timezone .utc ) - timedelta (days = 7 )).strftime (
88+ "%Y-%m-%dT%H:%M:%SZ"
89+ ),
8790 "commitMessage" : "placeholder commit message" ,
8891 "commitAuthorName" : "" ,
8992 "commitAuthorEmail" : "admin@localhost" ,
@@ -141,11 +144,51 @@ def test_failed_to_fetch_commit_context_record(self, mock_get_commit_context, mo
141144 error_message = "integration_failed" ,
142145 )
143146
147+ @patch ("sentry.tasks.commit_context.logger" )
144148 @patch (
145149 "sentry.integrations.github.GitHubIntegration.get_commit_context" ,
146150 return_value = {
147151 "commitId" : "asdfasdf" ,
148- "committedDate" : "2023-02-14T11:11Z" ,
152+ "committedDate" : (
153+ datetime .now (tz = datetime_timezone .utc ) - timedelta (days = 370 )
154+ ).strftime ("%Y-%m-%dT%H:%M:%SZ" ),
155+ "commitMessage" : "placeholder commit message" ,
156+ "commitAuthorName" : "" ,
157+ "commitAuthorEmail" : "admin@localhost" ,
158+ },
159+ )
160+ def test_found_commit_is_too_old (self , mock_get_commit_context , mock_logger ):
161+ with self .tasks ():
162+ assert not GroupOwner .objects .filter (group = self .event .group ).exists ()
163+ event_frames = get_frame_paths (self .event )
164+ process_commit_context (
165+ event_id = self .event .event_id ,
166+ event_platform = self .event .platform ,
167+ event_frames = event_frames ,
168+ group_id = self .event .group_id ,
169+ project_id = self .event .project_id ,
170+ )
171+
172+ assert mock_logger .info .call_count == 1
173+ mock_logger .info .assert_called_with (
174+ "process_commit_context.find_commit_context" ,
175+ extra = {
176+ "event" : self .event .event_id ,
177+ "group" : self .event .group_id ,
178+ "organization" : self .event .group .project .organization_id ,
179+ "reason" : "could_not_fetch_commit_context" ,
180+ "code_mappings_count" : 1 ,
181+ "fallback" : True ,
182+ },
183+ )
184+
185+ @patch (
186+ "sentry.integrations.github.GitHubIntegration.get_commit_context" ,
187+ return_value = {
188+ "commitId" : "asdfasdf" ,
189+ "committedDate" : (datetime .now (tz = datetime_timezone .utc ) - timedelta (days = 7 )).strftime (
190+ "%Y-%m-%dT%H:%M:%SZ"
191+ ),
149192 "commitMessage" : "placeholder commit message" ,
150193 "commitAuthorName" : "" ,
151194 "commitAuthorEmail" : "admin@localhost" ,
@@ -170,7 +213,9 @@ def test_no_matching_commit_in_db(self, mock_get_commit_context):
170213 "sentry.integrations.github.GitHubIntegration.get_commit_context" ,
171214 return_value = {
172215 "commitId" : "asdfwreqr" ,
173- "committedDate" : "2023-02-14T11:11Z" ,
216+ "committedDate" : (datetime .now (tz = datetime_timezone .utc ) - timedelta (days = 7 )).strftime (
217+ "%Y-%m-%dT%H:%M:%SZ"
218+ ),
174219 "commitMessage" : "placeholder commit message" ,
175220 "commitAuthorName" : "" ,
176221 "commitAuthorEmail" : "admin@localhost" ,
@@ -255,7 +300,9 @@ def test_no_inapp_frame_in_stacktrace(self, mock_process_suspect_commits):
255300 "sentry.integrations.github.GitHubIntegration.get_commit_context" ,
256301 return_value = {
257302 "commitId" : "somekey" ,
258- "committedDate" : "2023-02-14T11:11Z" ,
303+ "committedDate" : (datetime .now (tz = datetime_timezone .utc ) - timedelta (days = 7 )).strftime (
304+ "%Y-%m-%dT%H:%M:%SZ"
305+ ),
259306 "commitMessage" : "placeholder commit message" ,
260307 "commitAuthorName" : "" ,
261308 "commitAuthorEmail" : "[email protected] " , @@ -296,7 +343,9 @@ def test_commit_author_not_in_sentry(self, mock_get_commit_context):
296343 "sentry.integrations.github.GitHubIntegration.get_commit_context" ,
297344 return_value = {
298345 "commitId" : "somekey" ,
299- "committedDate" : "2023-02-14T11:11Z" ,
346+ "committedDate" : (datetime .now (tz = datetime_timezone .utc ) - timedelta (days = 7 )).strftime (
347+ "%Y-%m-%dT%H:%M:%SZ"
348+ ),
300349 "commitMessage" : "placeholder commit message" ,
301350 "commitAuthorName" : "" ,
302351 "commitAuthorEmail" : "[email protected] " , @@ -337,7 +386,9 @@ def test_commit_author_no_user(self, mock_get_commit_context, mock_get_users_for
337386 "sentry.integrations.github.GitHubIntegration.get_commit_context" ,
338387 return_value = {
339388 "commitId" : "somekey" ,
340- "committedDate" : "2023-02-14T11:11Z" ,
389+ "committedDate" : (datetime .now (tz = datetime_timezone .utc ) - timedelta (days = 7 )).strftime (
390+ "%Y-%m-%dT%H:%M:%SZ"
391+ ),
341392 "commitMessage" : "placeholder commit message" ,
342393 "commitAuthorName" : "" ,
343394 "commitAuthorEmail" : "[email protected] " , @@ -423,7 +474,9 @@ def after_return(self, status, retval, task_id, args, kwargs, einfo):
423474 Mock (
424475 return_value = {
425476 "commitId" : "asdfwreqr" ,
426- "committedDate" : "2023-02-14T11:11Z" ,
477+ "committedDate" : (datetime .now (tz = datetime_timezone .utc ) - timedelta (days = 7 )).strftime (
478+ "%Y-%m-%dT%H:%M:%SZ"
479+ ),
427480 "commitMessage" : "placeholder commit message" ,
428481 "commitAuthorName" : "" ,
429482 "commitAuthorEmail" : "admin@localhost" ,
0 commit comments