@@ -198,58 +198,85 @@ def test_api_root(
198198 assert content == expected_content
199199
200200
201+ @pytest .mark .parametrize ("is_public" , [True , False ])
201202@pytest .mark .parametrize ("method" , ["get" , "post" , "delete" ])
202203def test_api_root_unauthenticated (
203204 client ,
204205 method ,
206+ is_public ,
205207):
206- func = getattr (client , method )
207- response = func (f"/{ API_ROOTS [0 ].id } /" )
208- assert response .status_code == 401
208+ if is_public :
209+ api_root_id = API_ROOTS [1 ].id
210+ if method == "get" :
211+ expected_status_code = 200
212+ else :
213+ expected_status_code = 405
214+ else :
215+ api_root_id = API_ROOTS [0 ].id
216+ if method == "get" :
217+ expected_status_code = 401
218+ else :
219+ expected_status_code = 405
220+ with patch .object (
221+ client .application .taxii_server .servers .taxii2 .persistence .api ,
222+ "get_api_root" ,
223+ side_effect = GET_API_ROOT_MOCK ,
224+ ):
225+ func = getattr (client , method )
226+ response = func (
227+ f"/{ api_root_id } /" ,
228+ headers = {"Accept" : "application/taxii+json;version=2.1" },
229+ )
230+ assert response .status_code == expected_status_code
209231
210232
211233@pytest .mark .parametrize (
212- ["title" , "description" , "default" , "db_api_roots" ],
234+ ["title" , "description" , "default" , "is_public" , " db_api_roots" ],
213235 [
214236 pytest .param (
215237 "my new api root" , # title
216238 None , # description
217239 False , # default
240+ False , # is_public
218241 [], # db_api_roots
219242 id = "title only" ,
220243 ),
221244 pytest .param (
222245 "my new api root" , # title
223246 "my description" , # description
224247 False , # default
248+ True , # is_public
225249 [], # db_api_roots
226250 id = "title, description" ,
227251 ),
228252 pytest .param (
229253 "my new api root" , # title
230254 None , # description
231255 True , # default
256+ False , # is_public
232257 [], # db_api_roots
233258 id = "title, default" ,
234259 ),
235260 pytest .param (
236261 "my new api root" , # title
237262 "my description" , # description
238263 True , # default
264+ True , # is_public
239265 API_ROOTS_WITH_DEFAULT , # db_api_roots
240266 id = "title, description, default, existing" ,
241267 ),
242268 ],
243269 indirect = ["db_api_roots" ],
244270)
245- def test_add_api_root (app , title , description , default , db_api_roots ):
271+ def test_add_api_root (app , title , description , default , is_public , db_api_roots ):
246272 api_root = app .taxii_server .servers .taxii2 .persistence .api .add_api_root (
247- title , description , default
273+ title , description , default , is_public
248274 )
249275 assert api_root .id is not None
250276 assert api_root .title == title
251277 assert api_root .description == description
252278 assert api_root .default == default
279+ assert api_root .is_public == is_public
253280 db_api_root = (
254281 app .taxii_server .servers .taxii2 .persistence .api .db .session .query (
255282 taxii2models .ApiRoot
@@ -260,6 +287,7 @@ def test_add_api_root(app, title, description, default, db_api_roots):
260287 assert db_api_root .title == title
261288 assert db_api_root .description == description
262289 assert db_api_root .default == default
290+ assert db_api_root .is_public == is_public
263291 if default :
264292 assert (
265293 app .taxii_server .servers .taxii2 .persistence .api .db .session .query (
0 commit comments