Skip to content

Commit 3d3aa8b

Browse files
committed
fix moar tests
1 parent cb20a68 commit 3d3aa8b

File tree

4 files changed

+40
-21
lines changed

4 files changed

+40
-21
lines changed

src/sentry/models/group.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ def from_event_id(self, project, event_id):
175175
def filter_by_event_id(self, project_ids, event_id):
176176
from sentry.utils import snuba
177177

178-
group_ids = set()
179-
180178
group_ids = set([evt['issue'] for evt in snuba.raw_query(
181179
start=datetime.utcfromtimestamp(0),
182180
end=datetime.utcnow(),
@@ -186,7 +184,7 @@ def filter_by_event_id(self, project_ids, event_id):
186184
'event_id': [event_id],
187185
'project_id': project_ids,
188186
},
189-
limit=1,
187+
limit=1000,
190188
referrer="Group.filter_by_event_id",
191189
)['data']])
192190

tests/sentry/api/endpoints/test_group_integration_details.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,42 @@
44
import mock
55
from datetime import timedelta
66
from django.utils import timezone
7+
import copy
78

89
from sentry.integrations.example.integration import ExampleIntegration
910
from sentry.integrations.exceptions import IntegrationError
1011
from sentry.models import Activity, ExternalIssue, GroupLink, Integration
1112
from sentry.testutils import APITestCase
1213
from sentry.utils.http import absolute_uri
14+
from sentry.testutils.factories import DEFAULT_EVENT_DATA
1315

1416

1517
class GroupIntegrationDetailsTest(APITestCase):
1618
def setUp(self):
1719
super(GroupIntegrationDetailsTest, self).setUp()
1820
self.min_ago = timezone.now() - timedelta(minutes=1)
21+
self.event = self.store_event(
22+
data={
23+
'event_id': 'a' * 32,
24+
'timestamp': self.min_ago.isoformat()[:19],
25+
'message': 'message',
26+
'stacktrace': copy.deepcopy(DEFAULT_EVENT_DATA['stacktrace']),
27+
},
28+
project_id=self.project.id
29+
)
30+
self.group = self.event.group
1931

2032
def test_simple_get_link(self):
2133
self.login_as(user=self.user)
2234
org = self.organization
23-
group = self.create_group()
2435
integration = Integration.objects.create(
2536
provider='example',
2637
name='Example',
2738
)
2839
integration.add_organization(org, self.user)
2940

30-
path = u'/api/0/issues/{}/integrations/{}/?action=link'.format(group.id, integration.id)
41+
path = u'/api/0/issues/{}/integrations/{}/?action=link'.format(
42+
self.group.id, integration.id)
3143

3244
with self.feature('organizations:integrations-issue-basic'):
3345
response = self.client.get(path)
@@ -67,13 +79,12 @@ def test_simple_get_link(self):
6779
def test_simple_get_create(self):
6880
self.login_as(user=self.user)
6981
org = self.organization
70-
group = self.create_group()
71-
self.create_event(group=group)
7282
integration = Integration.objects.create(
7383
provider='example',
7484
name='Example',
7585
)
7686
integration.add_organization(org, self.user)
87+
group = self.group
7788

7889
path = u'/api/0/issues/{}/integrations/{}/?action=create'.format(group.id, integration.id)
7990

@@ -105,7 +116,7 @@ def test_simple_get_create(self):
105116
'required': True,
106117
}, {
107118
'default': ('Sentry Issue: [%s](%s)\n\n```\n'
108-
'Stacktrace (most recent call last):\n\n '
119+
'Stacktrace (most recent call first):\n\n '
109120
'File "sentry/models/foo.py", line 29, in build_msg\n '
110121
'string_max_length=self.string_max_length)\n\nmessage\n```'
111122
) % (group.qualified_short_id, absolute_uri(group.get_absolute_url(params={'referrer': 'example_integration'}))),
@@ -127,15 +138,14 @@ def test_simple_get_create(self):
127138
def test_get_create_with_error(self):
128139
self.login_as(user=self.user)
129140
org = self.organization
130-
group = self.create_group()
131-
self.create_event(group=group)
132141
integration = Integration.objects.create(
133142
provider='example',
134143
name='Example',
135144
)
136145
integration.add_organization(org, self.user)
137146

138-
path = u'/api/0/issues/{}/integrations/{}/?action=create'.format(group.id, integration.id)
147+
path = u'/api/0/issues/{}/integrations/{}/?action=create'.format(
148+
self.group.id, integration.id)
139149

140150
with self.feature('organizations:integrations-issue-basic'):
141151
with mock.patch.object(ExampleIntegration, 'get_create_issue_config', side_effect=IntegrationError('oops')):
@@ -147,15 +157,14 @@ def test_get_create_with_error(self):
147157
def test_get_feature_disabled(self):
148158
self.login_as(user=self.user)
149159
org = self.organization
150-
group = self.create_group()
151-
self.create_event(group=group)
152160
integration = Integration.objects.create(
153161
provider='example',
154162
name='Example',
155163
)
156164
integration.add_organization(org, self.user)
157165

158-
path = u'/api/0/issues/{}/integrations/{}/?action=create'.format(group.id, integration.id)
166+
path = u'/api/0/issues/{}/integrations/{}/?action=create'.format(
167+
self.group.id, integration.id)
159168

160169
with self.feature({'organizations:integrations-issue-basic': False}):
161170
response = self.client.get(path)
@@ -173,7 +182,6 @@ def test_simple_put(self):
173182
integration.add_organization(org, self.user)
174183

175184
path = u'/api/0/issues/{}/integrations/{}/'.format(group.id, integration.id)
176-
177185
with self.feature('organizations:integrations-issue-basic'):
178186
response = self.client.put(path, data={
179187
'externalIssue': 'APP-123'

tests/sentry/integrations/github/test_issues.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import responses
44
import six
5+
from datetime import timedelta
56

67
from mock import patch
78
from exam import fixture
89
from django.test import RequestFactory
10+
from django.utils import timezone
911

1012
from sentry.integrations.github.integration import GitHubIntegration
1113
from sentry.models import Integration, ExternalIssue
@@ -28,6 +30,7 @@ def setUp(self):
2830
)
2931
self.model.add_organization(self.organization, self.user)
3032
self.integration = GitHubIntegration(self.model, self.organization.id)
33+
self.min_ago = (timezone.now() - timedelta(minutes=1)).isoformat()[:19]
3134

3235
@responses.activate
3336
@patch('sentry.integrations.github.client.get_jwt', return_value='jwt_token_1')
@@ -158,6 +161,7 @@ def test_repo_dropdown_choices(self, mock_get_jwt):
158161
event = self.store_event(
159162
data={
160163
'event_id': 'a' * 32,
164+
'timestamp': self.min_ago,
161165
},
162166
project_id=self.project.id,
163167
)
@@ -247,6 +251,7 @@ def test_default_repo_link_fields(self, mock_get_jwt):
247251
event = self.store_event(
248252
data={
249253
'event_id': 'a' * 32,
254+
'timestamp': self.min_ago,
250255
},
251256
project_id=self.project.id,
252257
)
@@ -291,6 +296,7 @@ def test_default_repo_create_fields(self, mock_get_jwt):
291296
event = self.store_event(
292297
data={
293298
'event_id': 'a' * 32,
299+
'timestamp': self.min_ago,
294300
},
295301
project_id=self.project.id,
296302
)
@@ -322,6 +328,7 @@ def test_default_repo_link_fields_no_repos(self, mock_get_jwt):
322328
event = self.store_event(
323329
data={
324330
'event_id': 'a' * 32,
331+
'timestamp': self.min_ago,
325332
},
326333
project_id=self.project.id,
327334
)
@@ -348,6 +355,7 @@ def test_default_repo_create_fields_no_repos(self, mock_get_jwt):
348355
event = self.store_event(
349356
data={
350357
'event_id': 'a' * 32,
358+
'timestamp': self.min_ago,
351359
},
352360
project_id=self.project.id,
353361
)

tests/sentry/integrations/jira/test_integration.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import six
77
import pytest
88
import copy
9+
from datetime import timedelta
910

1011
from django.core.urlresolvers import reverse
1112
from django.utils import timezone
@@ -437,14 +438,18 @@ def integration(self):
437438
self.user)
438439
return integration
439440

441+
def setUp(self):
442+
super(JiraIntegrationTest, self).setUp()
443+
self.min_ago = (timezone.now() - timedelta(minutes=1)).isoformat()[:19]
444+
440445
def test_get_create_issue_config(self):
441446
org = self.organization
442447
self.login_as(self.user)
443448
event = self.store_event(
444449
data={
445450
'event_id': 'a' * 32,
446451
'message': 'message',
447-
'timestamp': timezone.now().isoformat(),
452+
'timestamp': self.min_ago,
448453
'stacktrace': copy.deepcopy(DEFAULT_EVENT_DATA['stacktrace']),
449454
},
450455
project_id=self.project.id,
@@ -524,7 +529,7 @@ def test_get_create_issue_config_with_default_and_param(self):
524529
data={
525530
'event_id': 'a' * 32,
526531
'message': 'message',
527-
'timestamp': timezone.now().isoformat(),
532+
'timestamp': self.min_ago,
528533
'stacktrace': copy.deepcopy(DEFAULT_EVENT_DATA['stacktrace']),
529534
},
530535
project_id=self.project.id,
@@ -561,7 +566,7 @@ def test_get_create_issue_config_with_default(self):
561566
data={
562567
'event_id': 'a' * 32,
563568
'message': 'message',
564-
'timestamp': timezone.now().isoformat(),
569+
'timestamp': self.min_ago,
565570
'stacktrace': copy.deepcopy(DEFAULT_EVENT_DATA['stacktrace']),
566571
},
567572
project_id=self.project.id,
@@ -598,7 +603,7 @@ def test_get_create_issue_config_with_label_default(self):
598603
data={
599604
'event_id': 'a' * 32,
600605
'message': 'message',
601-
'timestamp': timezone.now().isoformat(),
606+
'timestamp': self.min_ago,
602607
'stacktrace': copy.deepcopy(DEFAULT_EVENT_DATA['stacktrace']),
603608
},
604609
project_id=self.project.id,
@@ -637,7 +642,7 @@ def test_get_create_issue_config__no_projects(self):
637642
event = self.store_event(
638643
data={
639644
'message': 'oh no',
640-
'timestamp': timezone.now().isoformat()
645+
'timestamp': self.min_ago,
641646
},
642647
project_id=self.project.id
643648
)
@@ -663,7 +668,7 @@ def test_get_create_issue_config__no_issue_config(self):
663668
event = self.store_event(
664669
data={
665670
'message': 'oh no',
666-
'timestamp': timezone.now().isoformat()
671+
'timestamp': self.min_ago,
667672
},
668673
project_id=self.project.id
669674
)

0 commit comments

Comments
 (0)