1717from component_catalog .models import Package
1818from component_catalog .tests import make_package
1919from dejacode_toolkit .scancodeio import ScanCodeIO
20- from dejacode_toolkit .scancodeio import check_for_existing_scan_workaround
2120from dejacode_toolkit .scancodeio import get_hash_uid
2221from dejacode_toolkit .scancodeio import get_notice_text_from_key_files
22+ from dejacode_toolkit .scancodeio import update_package_from_existing_scan_data
2323from dje .models import Dataspace
2424from dje .models import History
2525from dje .tasks import scancodeio_submit_scan
@@ -67,41 +67,38 @@ def test_scancodeio_submit_scan_task(self, mock_submit_scan, mock_request_head):
6767
6868 expected = [
6969 mock .call ("http://okurl.com" , user_uuid , dataspace_uuid ),
70- mock .call ().__bool__ (),
7170 mock .call ("https://okurl2.com" , user_uuid , dataspace_uuid ),
72- mock .call ().__bool__ (),
7371 ]
7472 self .assertEqual (expected , mock_submit_scan .mock_calls )
7573
7674 @mock .patch ("requests.sessions.Session.get" )
7775 def test_scancodeio_fetch_scan_list (self , mock_session_get ):
7876 scancodeio = ScanCodeIO (self .dataspace )
79- self .assertIsNone ( scancodeio . fetch_scan_list () )
80- self .assertFalse ( mock_session_get . called )
77+ dataspace_uid = get_hash_uid ( self .dataspace . uuid )
78+ user_uid = get_hash_uid ( self .basic_user . uuid )
8179
82- scancodeio .fetch_scan_list (user = self . basic_user )
80+ scancodeio .fetch_scan_list ()
8381 params = mock_session_get .call_args .kwargs ["params" ]
84- expected = {"format" : "json" , "name__endswith" : get_hash_uid (self .basic_user .uuid )}
82+ expected = {
83+ "format" : "json" ,
84+ "name__contains" : dataspace_uid ,
85+ }
8586 self .assertEqual (expected , params )
8687
87- scancodeio .fetch_scan_list (dataspace = self .basic_user . dataspace )
88+ scancodeio .fetch_scan_list (user = self .basic_user )
8889 params = mock_session_get .call_args .kwargs ["params" ]
8990 expected = {
9091 "format" : "json" ,
91- "name__contains" : get_hash_uid (self .basic_user .dataspace .uuid ),
92+ "name__contains" : dataspace_uid ,
93+ "label" : user_uid ,
9294 }
9395 self .assertEqual (expected , params )
9496
95- scancodeio .fetch_scan_list (
96- user = self .basic_user ,
97- dataspace = self .basic_user .dataspace ,
98- extra_params = "extra" ,
99- )
97+ scancodeio .fetch_scan_list (extra_params = "extra" )
10098 params = mock_session_get .call_args .kwargs ["params" ]
10199 expected = {
102100 "format" : "json" ,
103- "name__contains" : get_hash_uid (self .basic_user .dataspace .uuid ),
104- "name__endswith" : get_hash_uid (self .basic_user .uuid ),
101+ "name__contains" : get_hash_uid (self .dataspace .uuid ),
105102 "extra_params" : "extra" ,
106103 }
107104 self .assertEqual (expected , params )
@@ -115,16 +112,11 @@ def test_scancodeio_fetch_scan_info(self, mock_session_get):
115112 params = mock_session_get .call_args .kwargs ["params" ]
116113 expected = {
117114 "name__startswith" : get_hash_uid (uri ),
118- "name__contains" : get_hash_uid (self .basic_user . dataspace .uuid ),
115+ "name__contains" : get_hash_uid (self .dataspace .uuid ),
119116 "format" : "json" ,
120117 }
121118 self .assertEqual (expected , params )
122119
123- scancodeio .fetch_scan_info (uri = uri , user = self .basic_user )
124- params = mock_session_get .call_args .kwargs ["params" ]
125- expected ["name__endswith" ] = get_hash_uid (self .basic_user .uuid )
126- self .assertEqual (expected , params )
127-
128120 @mock .patch ("dejacode_toolkit.scancodeio.ScanCodeIO.request_get" )
129121 def test_scancodeio_find_project (self , mock_request_get ):
130122 scancodeio = ScanCodeIO (self .dataspace )
@@ -340,19 +332,13 @@ def test_scancodeio_get_notice_text_from_key_files(self):
340332 self .assertEqual ("" , notice_text )
341333
342334 @mock .patch ("component_catalog.models.Package.update_from_scan" )
343- def test_scancodeio_check_for_existing_scan_workaround (self , mock_update_from_scan ):
335+ def test_scancodeio_update_package_from_existing_scan_data (self , mock_update_from_scan ):
344336 mock_update_from_scan .return_value = ["updated_field" ]
345337 download_url = self .package1 .download_url
346338 user = self .basic_user
347339
348- response_json = None
349- results = check_for_existing_scan_workaround (response_json , download_url , user )
350- self .assertIsNone (results )
351-
352- response_json = {"success" : True }
353- results = check_for_existing_scan_workaround (response_json , download_url , user )
340+ results = update_package_from_existing_scan_data ("unknown_url" , user )
354341 self .assertIsNone (results )
355342
356- response_json = {"name" : "project with this name already exists." }
357- results = check_for_existing_scan_workaround (response_json , download_url , user )
343+ results = update_package_from_existing_scan_data (download_url , user )
358344 self .assertEqual (["updated_field" ], results )
0 commit comments