@@ -352,6 +352,41 @@ def test_api_product_endpoint_update_permissions(self):
352352 product1 = Product .unsecured_objects .get (pk = self .product1 .pk )
353353 self .assertEqual ("Updated Name" , product1 .name )
354354
355+ def test_api_product_endpoint_imports_action (self ):
356+ url = reverse ("api_v2:product-imports" , args = [self .product1 .uuid ])
357+
358+ self .client .login (username = self .base_user .username , password = "secret" )
359+ response = self .client .get (url )
360+ self .assertEqual (status .HTTP_404_NOT_FOUND , response .status_code )
361+
362+ # Required permissions
363+ add_perm (self .base_user , "add_product" )
364+ assign_perm ("view_product" , self .base_user , self .product1 )
365+
366+ response = self .client .get (url )
367+ self .assertEqual (status .HTTP_200_OK , response .status_code )
368+ self .assertEqual (0 , self .product1 .scancodeprojects .count ())
369+ self .assertEqual ([], response .data )
370+
371+ ScanCodeProject .objects .create (
372+ product = self .product1 ,
373+ dataspace = self .product1 .dataspace ,
374+ type = ScanCodeProject .ProjectType .LOAD_SBOMS ,
375+ status = ScanCodeProject .Status .SUCCESS ,
376+ input_file = ContentFile ("Data" , name = "data.json" ),
377+ )
378+
379+ response = self .client .get (url )
380+ self .assertEqual (status .HTTP_200_OK , response .status_code )
381+ self .assertEqual (1 , self .product1 .scancodeprojects .count ())
382+ self .assertEqual (1 , len (response .data ))
383+ entry = response .data [0 ]
384+ self .assertEqual (ScanCodeProject .ProjectType .LOAD_SBOMS , entry ["type" ])
385+ self .assertEqual ("data.json" , entry ["input_filename" ])
386+ self .assertEqual (ScanCodeProject .Status .SUCCESS , entry ["status" ])
387+ self .assertEqual ([], entry ["import_log" ])
388+ self .assertEqual ({}, entry ["results" ])
389+
355390 def test_api_product_endpoint_load_sboms_action (self ):
356391 url = reverse ("api_v2:product-load-sboms" , args = [self .product1 .uuid ])
357392
0 commit comments