5
5
from sentry .testutils .cases import OrganizationDashboardWidgetTestCase
6
6
7
7
8
- class OrganizationDashboardsStarredOrderTest (OrganizationDashboardWidgetTestCase ):
8
+ class StarredDashboardTestCase (OrganizationDashboardWidgetTestCase ):
9
+ def create_dashboard_favorite (self , dashboard , user , organization , position ):
10
+ DashboardFavoriteUser .objects .create (
11
+ dashboard = dashboard , user_id = user .id , organization = organization , position = position
12
+ )
13
+
14
+ def do_request (self , * args , ** kwargs ):
15
+ with self .feature ("organizations:dashboards-starred-reordering" ):
16
+ return super ().do_request (* args , ** kwargs )
17
+
18
+
19
+ class OrganizationDashboardsStarredTest (StarredDashboardTestCase ):
9
20
def setUp (self ):
10
21
super ().setUp ()
11
22
self .login_as (self .user )
12
23
self .url = reverse (
13
- "sentry-api-0-organization-dashboard-starred-order " ,
24
+ "sentry-api-0-organization-dashboard-starred" ,
14
25
kwargs = {"organization_id_or_slug" : self .organization .slug },
15
26
)
16
27
self .dashboard_1 = self .create_dashboard (title = "Dashboard 1" )
17
28
self .dashboard_2 = self .create_dashboard (title = "Dashboard 2" )
18
29
self .dashboard_3 = self .create_dashboard (title = "Dashboard 3" )
19
30
20
- def create_dashboard_favorite (self , dashboard , user , organization , position ):
21
- DashboardFavoriteUser .objects .create (
22
- dashboard = dashboard , user_id = user .id , organization = organization , position = position
31
+ def test_get_favorite_dashboards (self ):
32
+ self .create_dashboard_favorite (self .dashboard_1 , self .user , self .organization , 2 )
33
+ self .create_dashboard_favorite (self .dashboard_2 , self .user , self .organization , 0 )
34
+ self .create_dashboard_favorite (self .dashboard_3 , self .user , self .organization , 1 )
35
+
36
+ # Add a dashboard starred by another user to verify that it is not returned
37
+ other_user = self .
create_user (
"[email protected] " )
38
+ other_dashboard = self .create_dashboard (title = "Other Dashboard" )
39
+ self .create_dashboard_favorite (other_dashboard , other_user , self .organization , 0 )
40
+
41
+ response = self .do_request ("get" , self .url )
42
+ assert response .status_code == 200
43
+ assert len (response .data ) == 3
44
+ assert [int (dashboard ["id" ]) for dashboard in response .data ] == [
45
+ self .dashboard_2 .id ,
46
+ self .dashboard_3 .id ,
47
+ self .dashboard_1 .id ,
48
+ ]
49
+
50
+
51
+ class OrganizationDashboardsStarredOrderTest (StarredDashboardTestCase ):
52
+ def setUp (self ):
53
+ super ().setUp ()
54
+ self .login_as (self .user )
55
+ self .url = reverse (
56
+ "sentry-api-0-organization-dashboard-starred-order" ,
57
+ kwargs = {"organization_id_or_slug" : self .organization .slug },
23
58
)
59
+ self .dashboard_1 = self .create_dashboard (title = "Dashboard 1" )
60
+ self .dashboard_2 = self .create_dashboard (title = "Dashboard 2" )
61
+ self .dashboard_3 = self .create_dashboard (title = "Dashboard 3" )
24
62
25
63
def test_reorder_dashboards (self ):
26
64
self .create_dashboard_favorite (self .dashboard_1 , self .user , self .organization , 0 )
@@ -40,14 +78,11 @@ def test_reorder_dashboards(self):
40
78
]
41
79
42
80
# Reorder the favorited dashboards
43
- with self .feature ("organizations:dashboards-starred-reordering" ):
44
- response = self .do_request (
45
- "put" ,
46
- self .url ,
47
- data = {
48
- "dashboard_ids" : [self .dashboard_3 .id , self .dashboard_1 .id , self .dashboard_2 .id ]
49
- },
50
- )
81
+ response = self .do_request (
82
+ "put" ,
83
+ self .url ,
84
+ data = {"dashboard_ids" : [self .dashboard_3 .id , self .dashboard_1 .id , self .dashboard_2 .id ]},
85
+ )
51
86
assert response .status_code == 204
52
87
53
88
assert list (
@@ -67,14 +102,11 @@ def test_throws_an_error_if_dashboard_ids_are_not_unique(self):
67
102
self .create_dashboard_favorite (self .dashboard_2 , self .user , self .organization , 1 )
68
103
self .create_dashboard_favorite (self .dashboard_3 , self .user , self .organization , 2 )
69
104
70
- with self .feature ("organizations:dashboards-starred-reordering" ):
71
- response = self .do_request (
72
- "put" ,
73
- self .url ,
74
- data = {
75
- "dashboard_ids" : [self .dashboard_1 .id , self .dashboard_1 .id , self .dashboard_2 .id ]
76
- },
77
- )
105
+ response = self .do_request (
106
+ "put" ,
107
+ self .url ,
108
+ data = {"dashboard_ids" : [self .dashboard_1 .id , self .dashboard_1 .id , self .dashboard_2 .id ]},
109
+ )
78
110
assert response .status_code == 400
79
111
assert response .data == {
80
112
"dashboard_ids" : ["Single dashboard cannot take up multiple positions" ]
@@ -85,12 +117,11 @@ def test_throws_an_error_if_reordered_dashboard_ids_are_not_complete(self):
85
117
self .create_dashboard_favorite (self .dashboard_2 , self .user , self .organization , 1 )
86
118
self .create_dashboard_favorite (self .dashboard_3 , self .user , self .organization , 2 )
87
119
88
- with self .feature ("organizations:dashboards-starred-reordering" ):
89
- response = self .do_request (
90
- "put" ,
91
- self .url ,
92
- data = {"dashboard_ids" : [self .dashboard_1 .id , self .dashboard_2 .id ]},
93
- )
120
+ response = self .do_request (
121
+ "put" ,
122
+ self .url ,
123
+ data = {"dashboard_ids" : [self .dashboard_1 .id , self .dashboard_2 .id ]},
124
+ )
94
125
assert response .status_code == 400
95
126
assert response .data == {
96
127
"detail" : ErrorDetail (
@@ -104,14 +135,11 @@ def test_allows_reordering_even_if_no_initial_positions(self):
104
135
self .create_dashboard_favorite (self .dashboard_2 , self .user , self .organization , 1 )
105
136
self .create_dashboard_favorite (self .dashboard_3 , self .user , self .organization , 2 )
106
137
107
- with self .feature ("organizations:dashboards-starred-reordering" ):
108
- response = self .do_request (
109
- "put" ,
110
- self .url ,
111
- data = {
112
- "dashboard_ids" : [self .dashboard_3 .id , self .dashboard_1 .id , self .dashboard_2 .id ]
113
- },
114
- )
138
+ response = self .do_request (
139
+ "put" ,
140
+ self .url ,
141
+ data = {"dashboard_ids" : [self .dashboard_3 .id , self .dashboard_1 .id , self .dashboard_2 .id ]},
142
+ )
115
143
assert response .status_code == 204
116
144
117
145
assert list (
0 commit comments