@@ -141,6 +141,94 @@ def test_get_all_components_with_fields_and_paging(self) -> None:
141141 self .assertEqual ("Tethys.Logging" , components [0 ]["name" ])
142142 self .assertEqual ("DE" , components [0 ]["ownerCountry" ])
143143
144+ @responses .activate
145+ def test_get_all_components_with_all_details (self ) -> None :
146+ lib = SW360 (self .MYURL , self .MYTOKEN , False )
147+ lib .force_no_session = True
148+ self ._add_login_response ()
149+ actual = lib .login_api ()
150+ self .assertTrue (actual )
151+
152+ responses .add (
153+ method = responses .GET ,
154+ url = self .MYURL + "resource/api/components?allDetails=true" , # noqa
155+ body = '{"_embedded": {"sw360:components": [{"name": "Tethys.Logging", "ownerCountry": "DE", "componentType": "OSS", "externalIds": {"package-url": "pkg:nuget/Tethys.Logging"}}]}}' , # noqa
156+ status = 200 ,
157+ content_type = "application/json" ,
158+ adding_headers = {"Authorization" : "Token " + self .MYTOKEN },
159+ )
160+
161+ components = lib .get_all_components (all_details = True )
162+ self .assertIsNotNone (components )
163+ self .assertTrue (len (components ) > 0 )
164+ self .assertEqual ("Tethys.Logging" , components [0 ]["name" ])
165+ self .assertEqual ("DE" , components [0 ]["ownerCountry" ])
166+
167+ @responses .activate
168+ def test_get_all_components_with_all_details_and_sorting (self ) -> None :
169+ lib = SW360 (self .MYURL , self .MYTOKEN , False )
170+ lib .force_no_session = True
171+ self ._add_login_response ()
172+ actual = lib .login_api ()
173+ self .assertTrue (actual )
174+
175+ responses .add (
176+ method = responses .GET ,
177+ url = self .MYURL + "resource/api/components?allDetails=true&sort=name%2Cdesc" , # noqa
178+ body = '{"_embedded": {"sw360:components": [{"name": "Tethys.Logging", "ownerCountry": "DE", "componentType": "OSS", "externalIds": {"package-url": "pkg:nuget/Tethys.Logging"}}]}}' , # noqa
179+ status = 200 ,
180+ content_type = "application/json" ,
181+ adding_headers = {"Authorization" : "Token " + self .MYTOKEN },
182+ )
183+
184+ components = lib .get_all_components (all_details = True , sort = "name,desc" )
185+ self .assertIsNotNone (components )
186+ self .assertTrue (len (components ) > 0 )
187+ self .assertEqual ("Tethys.Logging" , components [0 ]["name" ])
188+ self .assertEqual ("DE" , components [0 ]["ownerCountry" ])
189+
190+ @responses .activate
191+ def test_get_all_components_invalid_reply (self ) -> None :
192+ lib = SW360 (self .MYURL , self .MYTOKEN , False )
193+ lib .force_no_session = True
194+ self ._add_login_response ()
195+ actual = lib .login_api ()
196+ self .assertTrue (actual )
197+
198+ responses .add (
199+ method = responses .GET ,
200+ url = self .MYURL + "resource/api/components" , # noqa
201+ body = '{"_xxembedded": {"sw360:components": [{"name": "Tethys.Logging", "ownerCountry": "DE", "componentType": "OSS", "externalIds": {"package-url": "pkg:nuget/Tethys.Logging"}}]}}' , # noqa
202+ status = 200 ,
203+ content_type = "application/json" ,
204+ adding_headers = {"Authorization" : "Token " + self .MYTOKEN },
205+ )
206+
207+ components = lib .get_all_components (all_details = True , sort = "name,desc" )
208+ self .assertIsNotNone (components )
209+ self .assertTrue (len (components ) == 0 )
210+
211+ @responses .activate
212+ def test_get_all_components_invalid_reply2 (self ) -> None :
213+ lib = SW360 (self .MYURL , self .MYTOKEN , False )
214+ lib .force_no_session = True
215+ self ._add_login_response ()
216+ actual = lib .login_api ()
217+ self .assertTrue (actual )
218+
219+ responses .add (
220+ method = responses .GET ,
221+ url = self .MYURL + "resource/api/components" , # noqa
222+ body = '{"_embedded": {"xxsw360:components": [{"name": "Tethys.Logging", "ownerCountry": "DE", "componentType": "OSS", "externalIds": {"package-url": "pkg:nuget/Tethys.Logging"}}]}}' , # noqa
223+ status = 200 ,
224+ content_type = "application/json" ,
225+ adding_headers = {"Authorization" : "Token " + self .MYTOKEN },
226+ )
227+
228+ components = lib .get_all_components (all_details = True , sort = "name,desc" )
229+ self .assertIsNotNone (components )
230+ self .assertTrue (len (components ) == 0 )
231+
144232 @responses .activate
145233 def test_get_all_components_by_type (self ) -> None :
146234 lib = SW360 (self .MYURL , self .MYTOKEN , False )
@@ -184,6 +272,48 @@ def test_get_all_components_by_type_no_result(self) -> None:
184272 components = lib .get_components_by_type ("OSS" )
185273 self .assertEqual ([], components )
186274
275+ @responses .activate
276+ def test_get_all_components_by_type_invalid_reply (self ) -> None :
277+ lib = SW360 (self .MYURL , self .MYTOKEN , False )
278+ lib .force_no_session = True
279+ self ._add_login_response ()
280+ actual = lib .login_api ()
281+ self .assertTrue (actual )
282+
283+ responses .add (
284+ method = responses .GET ,
285+ url = self .MYURL + "resource/api/components?type=OSS" ,
286+ body = '{"_xxembedded": {"sw360:components": [{"name": "Tethys.Logging", "ownerCountry": "DE", "componentType": "OSS", "externalIds": {"package-url": "pkg:nuget/Tethys.Logging"}}]}}' , # noqa
287+ status = 200 ,
288+ content_type = "application/json" ,
289+ adding_headers = {"Authorization" : "Token " + self .MYTOKEN },
290+ )
291+
292+ components = lib .get_components_by_type ("OSS" )
293+ self .assertIsNotNone (components )
294+ self .assertTrue (len (components ) == 0 )
295+
296+ @responses .activate
297+ def test_get_all_components_by_type_invalid_reply2 (self ) -> None :
298+ lib = SW360 (self .MYURL , self .MYTOKEN , False )
299+ lib .force_no_session = True
300+ self ._add_login_response ()
301+ actual = lib .login_api ()
302+ self .assertTrue (actual )
303+
304+ responses .add (
305+ method = responses .GET ,
306+ url = self .MYURL + "resource/api/components?type=OSS" ,
307+ body = '{"_embedded": {"xxsw360:components": [{"name": "Tethys.Logging", "ownerCountry": "DE", "componentType": "OSS", "externalIds": {"package-url": "pkg:nuget/Tethys.Logging"}}]}}' , # noqa
308+ status = 200 ,
309+ content_type = "application/json" ,
310+ adding_headers = {"Authorization" : "Token " + self .MYTOKEN },
311+ )
312+
313+ components = lib .get_components_by_type ("OSS" )
314+ self .assertIsNotNone (components )
315+ self .assertTrue (len (components ) == 0 )
316+
187317 @responses .activate
188318 def test_get_component (self ) -> None :
189319 lib = SW360 (self .MYURL , self .MYTOKEN , False )
@@ -291,6 +421,27 @@ def test_get_components_by_external_id_full_answer(self) -> None:
291421 self .assertTrue (len (components ) > 0 )
292422 self .assertEqual ("Tethys.Logging" , components [0 ]["name" ])
293423
424+ @responses .activate
425+ def test_get_components_by_external_id_invalid_answer (self ) -> None :
426+ lib = SW360 (self .MYURL , self .MYTOKEN , False )
427+ lib .force_no_session = True
428+ self ._add_login_response ()
429+ actual = lib .login_api ()
430+ self .assertTrue (actual )
431+
432+ responses .add (
433+ method = responses .GET ,
434+ url = self .MYURL + "resource/api/components/searchByExternalIds?package-url=pkg:nuget/Tethys.Logging" , # noqa
435+ body = '{"_xxembedded":{"sw360:components" :[{"name": "Tethys.Logging", "componentType": "OSS", "externalIds": {"package-url": "pkg:nuget/Tethys.Logging"}}]}}' , # noqa
436+ status = 200 ,
437+ content_type = "application/json" ,
438+ adding_headers = {"Authorization" : "Token " + self .MYTOKEN },
439+ )
440+
441+ components = lib .get_components_by_external_id ("package-url" , "pkg:nuget/Tethys.Logging" )
442+ self .assertIsNotNone (components )
443+ self .assertTrue (len (components ) == 0 )
444+
294445 @responses .activate
295446 def test_update_component_external_id_add_fresh_id (self ) -> None :
296447 lib = SW360 (self .MYURL , self .MYTOKEN , False )
0 commit comments