@@ -199,6 +199,22 @@ def test_scanpipe_management_command_create_project_execute(self):
199199 "Project other_project created with work directory" , out .getvalue ()
200200 )
201201
202+ @override_settings (SCANCODEIO_GLOBAL_WEBHOOK = {"target_url" : "https://webhook.url" })
203+ @mock .patch .object (Project , "setup_global_webhook" )
204+ def test_scanpipe_management_command_create_project_no_global_webhook (
205+ self , mock_setup_webhook
206+ ):
207+ out = StringIO ()
208+ options = ["--no-global-webhook" ]
209+ call_command ("create-project" , "my_project" , * options , stdout = out )
210+ self .assertIn ("Project my_project created" , out .getvalue ())
211+ mock_setup_webhook .assert_not_called ()
212+
213+ options = []
214+ call_command ("create-project" , "my_project_v2" , * options , stdout = out )
215+ self .assertIn ("Project my_project_v2 created" , out .getvalue ())
216+ mock_setup_webhook .assert_called ()
217+
202218 def test_scanpipe_management_command_batch_create (self ):
203219 expected = "You must provide either --input-directory or --input-list as input."
204220 with self .assertRaisesMessage (CommandError , expected ):
@@ -277,6 +293,28 @@ def test_scanpipe_management_command_batch_create_input_list_csv(self):
277293 self .assertEqual ("" , input_source3 .tag )
278294 self .assertFalse (input_source3 .exists ())
279295
296+ @override_settings (SCANCODEIO_GLOBAL_WEBHOOK = {"target_url" : "https://webhook.url" })
297+ @mock .patch .object (Project , "setup_global_webhook" )
298+ def test_scanpipe_management_command_batch_create_global_webhook (
299+ self , mock_setup_webhook
300+ ):
301+ input_directory = self .data / "commands" / "batch-create-directory"
302+ options = ["--input-directory" , str (input_directory )]
303+ out = StringIO ()
304+ call_command ("batch-create" , * options , stdout = out )
305+ self .assertIn ("2 projects created." , out .getvalue ())
306+ mock_setup_webhook .assert_not_called ()
307+
308+ options += [
309+ "--create-global-webhook" ,
310+ "--project-name-suffix" ,
311+ "with-webhook" ,
312+ ]
313+ out = StringIO ()
314+ call_command ("batch-create" , * options , stdout = out )
315+ self .assertIn ("2 projects created." , out .getvalue ())
316+ mock_setup_webhook .assert_called ()
317+
280318 def test_scanpipe_management_command_add_input_file (self ):
281319 out = StringIO ()
282320
@@ -1288,3 +1326,19 @@ def test_scanpipe_management_command_mixin_create_project_execute(self):
12881326 execute = True ,
12891327 run_async = True ,
12901328 )
1329+
1330+ @override_settings (SCANCODEIO_GLOBAL_WEBHOOK = {"target_url" : "https://webhook.url" })
1331+ @mock .patch .object (Project , "setup_global_webhook" )
1332+ def test_scanpipe_management_command_mixin_create_project_no_global_webhook (
1333+ self , mock_setup_webhook
1334+ ):
1335+ project = self .create_project_command .create_project (
1336+ name = "no global webhook" ,
1337+ create_global_webhook = False ,
1338+ )
1339+ self .assertTrue (project .pk )
1340+ mock_setup_webhook .assert_not_called ()
1341+
1342+ project = self .create_project_command .create_project (name = "with global webhook" )
1343+ self .assertTrue (project .pk )
1344+ mock_setup_webhook .assert_called ()
0 commit comments