2727from framework import ramcache
2828
2929
30- class FeaturesAPITest (testing_config .CustomTestCase ):
30+ class FeaturesAPITestDelete (testing_config .CustomTestCase ):
3131
3232 def setUp (self ):
3333 self .feature_1 = models .Feature (
@@ -95,6 +95,31 @@ def test_delete__not_found(self):
9595 revised_feature = models .Feature .get_by_id (self .feature_id )
9696 self .assertFalse (revised_feature .deleted )
9797
98+
99+ class FeaturesAPITestGet (testing_config .CustomTestCase ):
100+
101+ def setUp (self ):
102+ self .feature_1 = models .Feature (
103+ name = 'feature one' , summary = 'sum' , category = 1 , visibility = 1 ,
104+ standardization = 1 , web_dev_views = 1 , impl_status_chrome = 5 ,
105+ intent_stage = models .INTENT_IMPLEMENT , shipped_milestone = 1 )
106+ self .feature_1 .put ()
107+ self .feature_id = self .feature_1 .key .integer_id ()
108+
109+ self .request_path = '/api/v0/features'
110+ self .handler = features_api .FeaturesAPI ()
111+
112+ self .app_admin = models .AppUser (email = 'admin@example.com' )
113+ self .app_admin .is_admin = True
114+ self .app_admin .put ()
115+
116+ def tearDown (self ):
117+ self .feature_1 .key .delete ()
118+ self .app_admin .key .delete ()
119+ testing_config .sign_out ()
120+ ramcache .flush_all ()
121+ ramcache .check_for_distributed_invalidation ()
122+
98123 def test_get__all_listed (self ):
99124 """Get all features that are listed."""
100125 with register .app .test_request_context (self .request_path ):
@@ -105,16 +130,14 @@ def test_get__all_listed(self):
105130 self .assertEqual (1 , len (actual_response ))
106131 self .assertEqual ('feature one' , actual_response [0 ]['name' ])
107132
108- def test_get__unlisted_no_perms (self ):
133+ def test_get__all_unlisted_no_perms (self ):
109134 """JSON feed does not include unlisted features for users who can't edit."""
110135 self .feature_1 .unlisted = True
111136 self .feature_1 .put ()
112137
113138 # No signed-in user
114139 with register .app .test_request_context (self .request_path ):
115- actual_response = self .handler .do_get ()
116- # Comparing only the total number of features and name of the feature
117- # as certain fields like `updated` cannot be compared
140+ actual_response = self .handler .do_get ()
118141 self .assertEqual (0 , len (actual_response ))
119142
120143 # Signed-in user with no permissions
@@ -123,15 +146,73 @@ def test_get__unlisted_no_perms(self):
123146 actual_response = self .handler .do_get ()
124147 self .assertEqual (0 , len (actual_response ))
125148
126- def test_get__unlisted_can_edit (self ):
149+ def test_get__all_unlisted_can_edit (self ):
127150 """JSON feed includes unlisted features for users who may edit."""
128151 self .feature_1 .unlisted = True
129152 self .feature_1 .put ()
130153
154+ # Signed-in user with permissions
155+ testing_config .sign_in ('admin@example.com' , 123567890 )
156+ with register .app .test_request_context (self .request_path ):
157+ actual_response = self .handler .do_get ()
158+ self .assertEqual (1 , len (actual_response ))
159+ self .assertEqual ('feature one' , actual_response [0 ]['name' ])
160+
161+ def test_get__in_milestone_listed (self ):
162+ """Get all features in a specific milestone that are listed."""
163+ # Atleast one feature is present in milestone
164+ with register .app .test_request_context (self .request_path + '?milestone=1' ):
165+ actual_response = self .handler .do_get ()
166+ self .assertEqual (1 , len (actual_response ))
167+ self .assertEqual ('feature one' , actual_response [0 ]['name' ])
168+ self .assertEqual (1 , actual_response [0 ]['browsers' ]['chrome' ]['status' ]['milestone_str' ])
169+
170+ # No Feature is present in milestone
171+ with register .app .test_request_context (self .request_path + '?milestone=2' ):
172+ actual_response = self .handler .do_get ()
173+ self .assertEqual (0 , len (actual_response ))
174+
175+ def test_get__in_milestone_unlisted_no_perms (self ):
176+ """JSON feed does not include unlisted features for users who can't edit."""
177+ self .feature_1 .unlisted = True
178+ self .feature_1 .put ()
179+
131180 # No signed-in user
181+ with register .app .test_request_context (self .request_path + '?milestone=1' ):
182+ actual_response = self .handler .do_get ()
183+ self .assertEqual (0 , len (actual_response ))
184+
132185 # Signed-in user with no permissions
186+ testing_config .sign_in ('one@example.com' , 123567890 )
187+ with register .app .test_request_context (self .request_path + '?milestone=1' ):
188+ actual_response = self .handler .do_get ()
189+ self .assertEqual (0 , len (actual_response ))
190+
191+ def test_get__in_milestone_unlisted_can_edit (self ):
192+ """JSON feed includes unlisted features for users who may edit."""
193+ self .feature_1 .unlisted = True
194+ self .feature_1 .put ()
195+
196+ # Signed-in user with permissions
133197 testing_config .sign_in ('admin@example.com' , 123567890 )
134- with register .app .test_request_context (self .request_path ):
198+
199+ # Feature is present in milestone
200+ with register .app .test_request_context (self .request_path + '?milestone=1' ):
135201 actual_response = self .handler .do_get ()
136202 self .assertEqual (1 , len (actual_response ))
137- self .assertEqual ('feature one' , actual_response [0 ]['name' ])
203+ self .assertEqual ('feature one' , actual_response [0 ]['name' ])
204+ self .assertEqual (1 , actual_response [0 ]['browsers' ]['chrome' ]['status' ]['milestone_str' ])
205+
206+ # Feature is not present in milestone
207+ with register .app .test_request_context (self .request_path + '?milestone=2' ):
208+ actual_response = self .handler .do_get ()
209+ self .assertEqual (0 , len (actual_response ))
210+
211+ @mock .patch ('flask.abort' )
212+ def test_get__in_milestone_invalid_query (self , mock_abort ):
213+ """Invalid value of milestone should not be processed."""
214+
215+ # Feature is present in milestone
216+ with register .app .test_request_context (self .request_path + '?milestone=chromium' ):
217+ actual_response = self .handler .do_get ()
218+ mock_abort .assert_called_once_with (400 , description = 'Invalid Milestone' )
0 commit comments