@@ -669,6 +669,71 @@ def test_add_local_actions(runner, project, action, existing_paths, missing_path
669
669
assert path .is_symlink ()
670
670
671
671
672
+ @pytest .mark .parametrize ("action, source_exists_after" , [("--copy" , True ), ("--move" , False )])
673
+ def test_add_non_local_actions (runner , project , directory_tree , action , source_exists_after ):
674
+ """Test adding data outside the project with different actions."""
675
+ path = directory_tree / "file1"
676
+
677
+ result = runner .invoke (cli , ["dataset" , "add" , action , "--create" , "local" , path ])
678
+
679
+ assert 0 == result .exit_code , format_result_exception (result )
680
+ assert source_exists_after == path .exists ()
681
+ assert (project .path / "data" / "local" / "file1" ).exists ()
682
+
683
+
684
+ def test_add_non_local_link_action (runner , project , directory_tree ):
685
+ """Test cannot add and link data outside the project."""
686
+ path = directory_tree / "file1"
687
+
688
+ result = runner .invoke (cli , ["dataset" , "add" , "--link" , "--create" , "local" , path ])
689
+
690
+ assert 2 == result .exit_code , format_result_exception (result )
691
+ assert "Cannot use '--link' for files outside of project:" in result .output
692
+
693
+
694
+ @pytest .mark .parametrize ("action, source_exists_after" , [("copy" , True ), ("move" , False )])
695
+ @pytest .mark .serial
696
+ def test_add_default_configured_actions (runner , project , directory_tree , action , source_exists_after ):
697
+ """Test adding data with different actions set in Renku configuration file."""
698
+ path = directory_tree / "file1"
699
+ set_value ("renku" , "default_dataset_add_action" , action , global_only = True )
700
+
701
+ result = runner .invoke (cli , ["dataset" , "add" , "--create" , "local" , path ])
702
+
703
+ assert 0 == result .exit_code , format_result_exception (result )
704
+ assert "The following files will be copied to" not in result .output
705
+ assert path .exists () is source_exists_after
706
+ assert (project .path / "data" / "local" / "file1" ).exists ()
707
+
708
+
709
+ @pytest .mark .serial
710
+ def test_add_default_configured_link (runner , project , directory_tree ):
711
+ """Test adding data with default ``link`` action should prompt the user."""
712
+ path = directory_tree / "file1"
713
+ set_value ("renku" , "default_dataset_add_action" , "link" , global_only = True )
714
+
715
+ result = runner .invoke (cli , ["dataset" , "add" , "--create" , "local" , path ], input = "y\n " )
716
+
717
+ assert 0 == result .exit_code , format_result_exception (result )
718
+ assert "The following files will be copied to" in result .output
719
+ assert path .exists ()
720
+ assert (project .path / "data" / "local" / "file1" ).exists ()
721
+ assert not (project .path / "data" / "local" / "file1" ).is_symlink ()
722
+
723
+
724
+ @pytest .mark .serial
725
+ def test_add_default_configured_invalid_action (runner , project , directory_tree ):
726
+ """Test adding data with an invalid actions set in Renku configuration file."""
727
+ path = directory_tree / "file1"
728
+ set_value ("renku" , "default_dataset_add_action" , "invalid" , global_only = True )
729
+
730
+ result = runner .invoke (cli , ["dataset" , "add" , "--create" , "local" , path ])
731
+
732
+ assert 2 == result .exit_code , format_result_exception (result )
733
+ assert "Invalid default action for adding to datasets in Renku config: 'invalid'." in result .output
734
+ assert "Valid values are 'copy', 'link', and 'move'." in result .output
735
+
736
+
672
737
def test_add_an_empty_directory (runner , project , directory_tree ):
673
738
"""Test adding an empty directory to a dataset."""
674
739
path = directory_tree / "empty-directory"
0 commit comments