5
5
from sentry .api .serializers .rest_framework .groupsearchview import GroupSearchViewValidatorResponse
6
6
from sentry .issues .endpoints .organization_group_search_views import DEFAULT_VIEWS
7
7
from sentry .models .groupsearchview import GroupSearchView
8
+ from sentry .models .groupsearchviewstarred import GroupSearchViewStarred
8
9
from sentry .testutils .cases import APITestCase , TransactionTestCase
9
10
from sentry .testutils .helpers .features import with_feature
10
11
@@ -159,9 +160,18 @@ def setUp(self) -> None:
159
160
@with_feature ({"organizations:issue-stream-custom-views" : True })
160
161
@with_feature ({"organizations:global-views" : True })
161
162
def test_deletes_missing_views (self ) -> None :
163
+ starred_views = GroupSearchViewStarred .objects .filter (
164
+ organization = self .organization , user_id = self .user .id
165
+ )
166
+
167
+ # Verify that no starred views exist initially
168
+ assert len (starred_views ) == 0
169
+
162
170
views = self .client .get (self .url ).data
163
171
164
172
update_custom_view_three = views [2 ]
173
+ # Store the ID of the view we're going to delete
174
+ deleted_view_id = views [1 ]["id" ]
165
175
166
176
views .pop (1 )
167
177
response = self .get_success_response (self .organization .slug , views = views )
@@ -175,6 +185,22 @@ def test_deletes_missing_views(self) -> None:
175
185
assert are_views_equal (response .data [0 ], views [0 ])
176
186
assert are_views_equal (response .data [1 ], update_custom_view_three )
177
187
188
+ starred_views = GroupSearchViewStarred .objects .filter (
189
+ organization = self .organization , user_id = self .user .id
190
+ )
191
+ assert len (starred_views ) == len (response .data )
192
+ for idx , view in enumerate (response .data ):
193
+ assert starred_views [idx ].position == idx
194
+ assert starred_views [idx ].position == view ["position" ]
195
+ assert str (starred_views [idx ].group_search_view .id ) == view ["id" ]
196
+
197
+ # Verify that the deleted view is no longer in the starred table
198
+ assert not GroupSearchViewStarred .objects .filter (
199
+ organization = self .organization ,
200
+ user_id = self .user .id ,
201
+ group_search_view_id = deleted_view_id ,
202
+ ).exists ()
203
+
178
204
@with_feature ({"organizations:issue-stream-custom-views" : True })
179
205
@with_feature ({"organizations:global-views" : True })
180
206
def test_adds_view_with_no_id (self ) -> None :
@@ -194,6 +220,15 @@ def test_adds_view_with_no_id(self) -> None:
194
220
assert response .data [3 ]["query" ] == "is:unresolved"
195
221
assert response .data [3 ]["querySort" ] == "date"
196
222
223
+ starred_views = GroupSearchViewStarred .objects .filter (
224
+ organization = self .organization , user_id = self .user .id
225
+ )
226
+ assert len (starred_views ) == len (response .data )
227
+ for idx , view in enumerate (response .data ):
228
+ assert starred_views [idx ].position == idx
229
+ assert starred_views [idx ].position == view ["position" ]
230
+ assert str (starred_views [idx ].group_search_view .id ) == view ["id" ]
231
+
197
232
@with_feature ({"organizations:issue-stream-custom-views" : True })
198
233
@with_feature ({"organizations:global-views" : True })
199
234
def test_reorder_views (self ) -> None :
@@ -214,6 +249,15 @@ def test_reorder_views(self) -> None:
214
249
assert are_views_equal (response .data [1 ], view_one )
215
250
assert are_views_equal (response .data [2 ], views [2 ])
216
251
252
+ starred_views = GroupSearchViewStarred .objects .filter (
253
+ organization = self .organization , user_id = self .user .id
254
+ )
255
+ assert len (starred_views ) == len (response .data )
256
+ for idx , view in enumerate (response .data ):
257
+ assert starred_views [idx ].position == idx
258
+ assert starred_views [idx ].position == view ["position" ]
259
+ assert str (starred_views [idx ].group_search_view .id ) == view ["id" ]
260
+
217
261
@with_feature ({"organizations:issue-stream-custom-views" : True })
218
262
@with_feature ({"organizations:global-views" : True })
219
263
def test_rename_views (self ) -> None :
@@ -264,6 +308,15 @@ def test_change_everything(self) -> None:
264
308
assert response .data [0 ]["query" ] == "is:resolved"
265
309
assert response .data [0 ]["querySort" ] == "freq"
266
310
311
+ starred_views = GroupSearchViewStarred .objects .filter (
312
+ organization = self .organization , user_id = self .user .id
313
+ )
314
+ assert len (starred_views ) == len (response .data )
315
+ for idx , view in enumerate (response .data ):
316
+ assert starred_views [idx ].position == idx
317
+ assert starred_views [idx ].position == view ["position" ]
318
+ assert str (starred_views [idx ].group_search_view .id ) == view ["id" ]
319
+
267
320
@with_feature ({"organizations:issue-stream-custom-views" : True })
268
321
@with_feature ({"organizations:global-views" : True })
269
322
def test_invalid_no_views (self ) -> None :
@@ -343,6 +396,15 @@ def test_updated_deleted_view(self) -> None:
343
396
assert response .data [1 ]["querySort" ] == view_one ["querySort" ]
344
397
assert are_views_equal (response .data [2 ], views [2 ])
345
398
399
+ starred_views = GroupSearchViewStarred .objects .filter (
400
+ organization = self .organization , user_id = self .user .id
401
+ )
402
+ assert len (starred_views ) == len (response .data )
403
+ for idx , view in enumerate (response .data ):
404
+ assert starred_views [idx ].position == idx
405
+ assert starred_views [idx ].position == view ["position" ]
406
+ assert str (starred_views [idx ].group_search_view .id ) == view ["id" ]
407
+
346
408
347
409
class OrganizationGroupSearchViewsWithPageFiltersPutTest (BaseGSVTestCase ):
348
410
endpoint = "sentry-api-0-organization-group-search-views"
0 commit comments