44import mock
55from datetime import timedelta
66from django .utils import timezone
7+ import copy
78
89from sentry .integrations .example .integration import ExampleIntegration
910from sentry .integrations .exceptions import IntegrationError
1011from sentry .models import Activity , ExternalIssue , GroupLink , Integration
1112from sentry .testutils import APITestCase
1213from sentry .utils .http import absolute_uri
14+ from sentry .testutils .factories import DEFAULT_EVENT_DATA
1315
1416
1517class 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 \n message\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'
0 commit comments