1
- from datetime import datetime , timedelta
2
- from datetime import timezone as datetime_timezone
1
+ from datetime import timedelta
3
2
from unittest .mock import Mock , patch
4
3
5
4
import pytest
@@ -84,9 +83,7 @@ class TestCommitContext(TestCommitContextMixin):
84
83
"sentry.integrations.github.GitHubIntegration.get_commit_context" ,
85
84
return_value = {
86
85
"commitId" : "asdfwreqr" ,
87
- "committedDate" : (datetime .now (tz = datetime_timezone .utc ) - timedelta (days = 7 )).strftime (
88
- "%Y-%m-%dT%H:%M:%SZ"
89
- ),
86
+ "committedDate" : "2023-02-14T11:11Z" ,
90
87
"commitMessage" : "placeholder commit message" ,
91
88
"commitAuthorName" : "" ,
92
89
"commitAuthorEmail" : "admin@localhost" ,
@@ -144,51 +141,11 @@ def test_failed_to_fetch_commit_context_record(self, mock_get_commit_context, mo
144
141
error_message = "integration_failed" ,
145
142
)
146
143
147
- @patch ("sentry.tasks.commit_context.logger" )
148
144
@patch (
149
145
"sentry.integrations.github.GitHubIntegration.get_commit_context" ,
150
146
return_value = {
151
147
"commitId" : "asdfasdf" ,
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
- ),
148
+ "committedDate" : "2023-02-14T11:11Z" ,
192
149
"commitMessage" : "placeholder commit message" ,
193
150
"commitAuthorName" : "" ,
194
151
"commitAuthorEmail" : "admin@localhost" ,
@@ -213,9 +170,7 @@ def test_no_matching_commit_in_db(self, mock_get_commit_context):
213
170
"sentry.integrations.github.GitHubIntegration.get_commit_context" ,
214
171
return_value = {
215
172
"commitId" : "asdfwreqr" ,
216
- "committedDate" : (datetime .now (tz = datetime_timezone .utc ) - timedelta (days = 7 )).strftime (
217
- "%Y-%m-%dT%H:%M:%SZ"
218
- ),
173
+ "committedDate" : "2023-02-14T11:11Z" ,
219
174
"commitMessage" : "placeholder commit message" ,
220
175
"commitAuthorName" : "" ,
221
176
"commitAuthorEmail" : "admin@localhost" ,
@@ -300,9 +255,7 @@ def test_no_inapp_frame_in_stacktrace(self, mock_process_suspect_commits):
300
255
"sentry.integrations.github.GitHubIntegration.get_commit_context" ,
301
256
return_value = {
302
257
"commitId" : "somekey" ,
303
- "committedDate" : (datetime .now (tz = datetime_timezone .utc ) - timedelta (days = 7 )).strftime (
304
- "%Y-%m-%dT%H:%M:%SZ"
305
- ),
258
+ "committedDate" : "2023-02-14T11:11Z" ,
306
259
"commitMessage" : "placeholder commit message" ,
307
260
"commitAuthorName" : "" ,
308
261
"commitAuthorEmail" : "[email protected] " ,
@@ -343,9 +296,7 @@ def test_commit_author_not_in_sentry(self, mock_get_commit_context):
343
296
"sentry.integrations.github.GitHubIntegration.get_commit_context" ,
344
297
return_value = {
345
298
"commitId" : "somekey" ,
346
- "committedDate" : (datetime .now (tz = datetime_timezone .utc ) - timedelta (days = 7 )).strftime (
347
- "%Y-%m-%dT%H:%M:%SZ"
348
- ),
299
+ "committedDate" : "2023-02-14T11:11Z" ,
349
300
"commitMessage" : "placeholder commit message" ,
350
301
"commitAuthorName" : "" ,
351
302
"commitAuthorEmail" : "[email protected] " ,
@@ -386,9 +337,7 @@ def test_commit_author_no_user(self, mock_get_commit_context, mock_get_users_for
386
337
"sentry.integrations.github.GitHubIntegration.get_commit_context" ,
387
338
return_value = {
388
339
"commitId" : "somekey" ,
389
- "committedDate" : (datetime .now (tz = datetime_timezone .utc ) - timedelta (days = 7 )).strftime (
390
- "%Y-%m-%dT%H:%M:%SZ"
391
- ),
340
+ "committedDate" : "2023-02-14T11:11Z" ,
392
341
"commitMessage" : "placeholder commit message" ,
393
342
"commitAuthorName" : "" ,
394
343
"commitAuthorEmail" : "[email protected] " ,
@@ -474,9 +423,7 @@ def after_return(self, status, retval, task_id, args, kwargs, einfo):
474
423
Mock (
475
424
return_value = {
476
425
"commitId" : "asdfwreqr" ,
477
- "committedDate" : (datetime .now (tz = datetime_timezone .utc ) - timedelta (days = 7 )).strftime (
478
- "%Y-%m-%dT%H:%M:%SZ"
479
- ),
426
+ "committedDate" : "2023-02-14T11:11Z" ,
480
427
"commitMessage" : "placeholder commit message" ,
481
428
"commitAuthorName" : "" ,
482
429
"commitAuthorEmail" : "admin@localhost" ,
0 commit comments