2222from dje .models import Dataspace
2323from dje .tests import create_admin
2424from dje .tests import create_superuser
25+ from dje .tests import wrap_as_temp_uploaded_file
2526from license_library .models import License
2627from license_library .models import LicenseChoice
2728from organization .models import Owner
@@ -714,7 +715,8 @@ def setUp(self):
714715
715716 def test_product_portfolio_product_import_from_scan_proper (self ):
716717 scan_input_location = self .testfiles_path / "import_from_scan.json"
717- importer = ImportFromScan (self .product1 , self .super_user , scan_input_location )
718+ upload_file = wrap_as_temp_uploaded_file (scan_input_location )
719+ importer = ImportFromScan (self .product1 , self .super_user , upload_file )
718720 warnings , created_counts = importer .save ()
719721 self .assertEqual ([], warnings )
720722 self .assertEqual (
@@ -750,14 +752,16 @@ def test_product_portfolio_product_import_from_scan_proper(self):
750752 self .assertDictEqual (expected_details , resource .additional_details )
751753
752754 # Make sure we do not create duplicates on re-importing
753- importer = ImportFromScan (self .product1 , self .super_user , scan_input_location )
755+ upload_file = wrap_as_temp_uploaded_file (scan_input_location )
756+ importer = ImportFromScan (self .product1 , self .super_user , upload_file )
754757 warnings , created_counts = importer .save ()
755758 self .assertEqual ([], warnings )
756759 self .assertEqual ({}, created_counts )
757760
758761 def test_product_portfolio_product_import_from_scan_scanpipe_results (self ):
759762 scan_input_location = self .testfiles_path / "scancodeio_scan_codebase_results.json"
760- importer = ImportFromScan (self .product1 , self .super_user , scan_input_location )
763+ upload_file = wrap_as_temp_uploaded_file (scan_input_location )
764+ importer = ImportFromScan (self .product1 , self .super_user , upload_file )
761765 warnings , created_counts = importer .save ()
762766 self .assertEqual ([], warnings )
763767 self .assertEqual (
@@ -790,21 +794,24 @@ def test_product_portfolio_product_import_from_scan_scanpipe_results(self):
790794 self .assertDictEqual (expected_details , resource .additional_details )
791795
792796 # Make sure we do not create duplicates on re-importing
793- importer = ImportFromScan (self .product1 , self .super_user , scan_input_location )
797+ upload_file = wrap_as_temp_uploaded_file (scan_input_location )
798+ importer = ImportFromScan (self .product1 , self .super_user , upload_file )
794799 warnings , created_counts = importer .save ()
795800 self .assertEqual ([], warnings )
796801 self .assertEqual ({}, created_counts )
797802
798803 def test_product_portfolio_product_import_from_scan_package_without_purl (self ):
799804 scan_input_location = self .testfiles_path / "package_without_purl.json"
800- importer = ImportFromScan (self .product1 , self .super_user , scan_input_location )
805+ upload_file = wrap_as_temp_uploaded_file (scan_input_location )
806+ importer = ImportFromScan (self .product1 , self .super_user , upload_file )
801807 warnings , created_counts = importer .save ()
802808 self .assertEqual ([], warnings )
803809 self .assertEqual ({}, created_counts )
804810
805811 def test_product_portfolio_product_import_from_scan_duplicated_purl_are_imported_once (self ):
806812 scan_input_location = self .testfiles_path / "duplicated_purl.json"
807- importer = ImportFromScan (self .product1 , self .super_user , scan_input_location )
813+ upload_file = wrap_as_temp_uploaded_file (scan_input_location )
814+ importer = ImportFromScan (self .product1 , self .super_user , upload_file )
808815 warnings , created_counts = importer .save ()
809816
810817 self .assertEqual ([], warnings )
@@ -828,28 +835,32 @@ def test_product_portfolio_product_import_from_scan_duplicated_purl_are_imported
828835 self .assertIn ("artifacts/six-1.14.0/setup.py" , codebase_resources )
829836
830837 def test_product_portfolio_product_import_from_scan_input_file_errors (self ):
831- expected = "The file content is not proper JSON. "
838+ expected = "Invalid JSON file: Expecting value: line 1 column 1 (char 0) "
832839 scan_input_location = Path (__file__ )
833- importer = ImportFromScan (self .product1 , self .super_user , scan_input_location )
840+ upload_file = wrap_as_temp_uploaded_file (scan_input_location )
841+ importer = ImportFromScan (self .product1 , self .super_user , upload_file )
834842 with self .assertRaisesMessage (ValidationError , expected ):
835843 importer .save ()
836844
837845 expected = "The uploaded file is not a proper ScanCode output results."
838846 scan_input_location = self .testfiles_path / "json_but_not_scan_results.json"
839- importer = ImportFromScan (self .product1 , self .super_user , scan_input_location )
847+ upload_file = wrap_as_temp_uploaded_file (scan_input_location )
848+ importer = ImportFromScan (self .product1 , self .super_user , upload_file )
840849 with self .assertRaisesMessage (ValidationError , expected ):
841850 importer .save ()
842851
843852 options_str = "--copyright --package"
844853 expected = f"The Scan run is missing those required options: { options_str } "
845854 scan_input_location = self .testfiles_path / "missing_scancode_options.json"
846- importer = ImportFromScan (self .product1 , self .super_user , scan_input_location )
855+ upload_file = wrap_as_temp_uploaded_file (scan_input_location )
856+ importer = ImportFromScan (self .product1 , self .super_user , upload_file )
847857 with self .assertRaisesMessage (ValidationError , expected ):
848858 importer .save ()
849859
850860 expected = "'This ScanCode.io output does not include packages nor dependencies data."
851861 scan_input_location = self .testfiles_path / "missing_correct_pipeline.json"
852- importer = ImportFromScan (self .product1 , self .super_user , scan_input_location )
862+ upload_file = wrap_as_temp_uploaded_file (scan_input_location )
863+ importer = ImportFromScan (self .product1 , self .super_user , upload_file )
853864 with self .assertRaisesMessage (ValidationError , expected ):
854865 importer .save ()
855866
@@ -859,13 +870,13 @@ def test_product_portfolio_product_import_from_scan_input_data_validation_errors
859870 "Ensure this value has at most 1024 characters (it has 3466)."
860871 )
861872 scan_input_location = self .testfiles_path / "package_data_validation_error.json"
862- importer = ImportFromScan (
863- self .product1 , self .super_user , scan_input_location , stop_on_error = True
864- )
873+ upload_file = wrap_as_temp_uploaded_file (scan_input_location )
874+ importer = ImportFromScan (self .product1 , self .super_user , upload_file , stop_on_error = True )
865875 with self .assertRaisesMessage (ValidationError , expected ):
866876 importer .save ()
867877
868- importer = ImportFromScan (self .product1 , self .super_user , scan_input_location )
878+ upload_file = wrap_as_temp_uploaded_file (scan_input_location )
879+ importer = ImportFromScan (self .product1 , self .super_user , upload_file )
869880 warnings , created_counts = importer .save ()
870881 expected = [
871882 "pkg:pypi/six?uuid=bbe2794a-d81a-4728-a66d-5700a3735977 license_expression: "
0 commit comments