1
- from datetime import timedelta
1
+ from datetime import datetime , timedelta
2
+ from datetime import timezone as datetime_timezone
2
3
from unittest .mock import Mock , patch
3
4
4
5
import pytest
@@ -83,7 +84,7 @@ class TestCommitContext(TestCommitContextMixin):
83
84
"sentry.integrations.github.GitHubIntegration.get_commit_context" ,
84
85
return_value = {
85
86
"commitId" : "asdfwreqr" ,
86
- "committedDate" : "2023-02-14T11:11Z" ,
87
+ "committedDate" : ( datetime . now ( tz = datetime_timezone . utc ) - timedelta ( days = 7 )) ,
87
88
"commitMessage" : "placeholder commit message" ,
88
89
"commitAuthorName" : "" ,
89
90
"commitAuthorEmail" : "admin@localhost" ,
@@ -141,11 +142,47 @@ def test_failed_to_fetch_commit_context_record(self, mock_get_commit_context, mo
141
142
error_message = "integration_failed" ,
142
143
)
143
144
145
+ @patch ("sentry.tasks.commit_context.logger" )
144
146
@patch (
145
147
"sentry.integrations.github.GitHubIntegration.get_commit_context" ,
146
148
return_value = {
147
149
"commitId" : "asdfasdf" ,
148
- "committedDate" : "2023-02-14T11:11Z" ,
150
+ "committedDate" : (datetime .now (tz = datetime_timezone .utc ) - timedelta (days = 370 )),
151
+ "commitMessage" : "placeholder commit message" ,
152
+ "commitAuthorName" : "" ,
153
+ "commitAuthorEmail" : "admin@localhost" ,
154
+ },
155
+ )
156
+ def test_found_commit_is_too_old (self , mock_get_commit_context , mock_logger ):
157
+ with self .tasks ():
158
+ assert not GroupOwner .objects .filter (group = self .event .group ).exists ()
159
+ event_frames = get_frame_paths (self .event )
160
+ process_commit_context (
161
+ event_id = self .event .event_id ,
162
+ event_platform = self .event .platform ,
163
+ event_frames = event_frames ,
164
+ group_id = self .event .group_id ,
165
+ project_id = self .event .project_id ,
166
+ )
167
+
168
+ assert mock_logger .info .call_count == 1
169
+ mock_logger .info .assert_called_with (
170
+ "process_commit_context.find_commit_context" ,
171
+ extra = {
172
+ "event" : self .event .event_id ,
173
+ "group" : self .event .group_id ,
174
+ "organization" : self .event .group .project .organization_id ,
175
+ "reason" : "could_not_fetch_commit_context" ,
176
+ "code_mappings_count" : 1 ,
177
+ "fallback" : True ,
178
+ },
179
+ )
180
+
181
+ @patch (
182
+ "sentry.integrations.github.GitHubIntegration.get_commit_context" ,
183
+ return_value = {
184
+ "commitId" : "asdfasdf" ,
185
+ "committedDate" : (datetime .now (tz = datetime_timezone .utc ) - timedelta (days = 7 )),
149
186
"commitMessage" : "placeholder commit message" ,
150
187
"commitAuthorName" : "" ,
151
188
"commitAuthorEmail" : "admin@localhost" ,
@@ -170,7 +207,7 @@ def test_no_matching_commit_in_db(self, mock_get_commit_context):
170
207
"sentry.integrations.github.GitHubIntegration.get_commit_context" ,
171
208
return_value = {
172
209
"commitId" : "asdfwreqr" ,
173
- "committedDate" : "2023-02-14T11:11Z" ,
210
+ "committedDate" : ( datetime . now ( tz = datetime_timezone . utc ) - timedelta ( days = 7 )) ,
174
211
"commitMessage" : "placeholder commit message" ,
175
212
"commitAuthorName" : "" ,
176
213
"commitAuthorEmail" : "admin@localhost" ,
@@ -255,7 +292,7 @@ def test_no_inapp_frame_in_stacktrace(self, mock_process_suspect_commits):
255
292
"sentry.integrations.github.GitHubIntegration.get_commit_context" ,
256
293
return_value = {
257
294
"commitId" : "somekey" ,
258
- "committedDate" : "2023-02-14T11:11Z" ,
295
+ "committedDate" : ( datetime . now ( tz = datetime_timezone . utc ) - timedelta ( days = 7 )) ,
259
296
"commitMessage" : "placeholder commit message" ,
260
297
"commitAuthorName" : "" ,
261
298
"commitAuthorEmail" : "[email protected] " ,
@@ -296,7 +333,7 @@ def test_commit_author_not_in_sentry(self, mock_get_commit_context):
296
333
"sentry.integrations.github.GitHubIntegration.get_commit_context" ,
297
334
return_value = {
298
335
"commitId" : "somekey" ,
299
- "committedDate" : "2023-02-14T11:11Z" ,
336
+ "committedDate" : ( datetime . now ( tz = datetime_timezone . utc ) - timedelta ( days = 7 )) ,
300
337
"commitMessage" : "placeholder commit message" ,
301
338
"commitAuthorName" : "" ,
302
339
"commitAuthorEmail" : "[email protected] " ,
@@ -337,7 +374,7 @@ def test_commit_author_no_user(self, mock_get_commit_context, mock_get_users_for
337
374
"sentry.integrations.github.GitHubIntegration.get_commit_context" ,
338
375
return_value = {
339
376
"commitId" : "somekey" ,
340
- "committedDate" : "2023-02-14T11:11Z" ,
377
+ "committedDate" : ( datetime . now ( tz = datetime_timezone . utc ) - timedelta ( days = 7 )) ,
341
378
"commitMessage" : "placeholder commit message" ,
342
379
"commitAuthorName" : "" ,
343
380
"commitAuthorEmail" : "[email protected] " ,
@@ -423,7 +460,7 @@ def after_return(self, status, retval, task_id, args, kwargs, einfo):
423
460
Mock (
424
461
return_value = {
425
462
"commitId" : "asdfwreqr" ,
426
- "committedDate" : "2023-02-14T11:11Z" ,
463
+ "committedDate" : ( datetime . now ( tz = datetime_timezone . utc ) - timedelta ( days = 7 )) ,
427
464
"commitMessage" : "placeholder commit message" ,
428
465
"commitAuthorName" : "" ,
429
466
"commitAuthorEmail" : "admin@localhost" ,
0 commit comments