IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 24, 2019, 2:41:04 PM (7 years ago)
Author:
fairlamb
Message:

Merge IPP-259 into trunk: Improved backup programs

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools

  • trunk/tools/backups/utils/subprocess_utils_test.py

    r40898 r40967  
    55
    66from pathlib import Path
    7 from backups.utils.errors import SubprocessError, ValidationError
     7from .errors import SubprocessError, ValidationError
    88
    99
     
    164164        assert bool(new_stats.st_mode & stat.S_IWOTH) is True
    165165        assert bool(new_stats.st_mode & stat.S_IXOTH) is True
     166
     167
     168class TestLocalRsyncWrapper(object):
     169    """This is essentially a copy of the 'copy' tests above.
     170    """
     171
     172    def test_rsync_raises_validation_error_with_no_args(self):
     173        with pytest.raises(ValidationError):
     174            utils.local_rsync_wrapper(None)
     175
     176    def test_rsync_fails_with_invalid_args(self, tmpdir):
     177        with pytest.raises(SubprocessError):
     178            utils.local_rsync_wrapper(["not a real file", "not a valid rsync_location"])
     179
     180    def test_rsync_fails_if_source_does_not_exist(self, tmpdir):
     181        with pytest.raises(SubprocessError):
     182            utils.local_rsync_wrapper(["not a real file", tmpdir])
     183
     184    def test_simple_rsync(self, tmpdir):
     185        real_file = make_a_real_file(tmpdir, "real_file.txt")
     186        expected_filepath = os.path.join(tmpdir, "copied_file.txt")
     187        assert not os.path.isfile(expected_filepath)
     188
     189        result = utils.local_rsync_wrapper(["-v", real_file, expected_filepath])
     190        assert os.path.isfile(expected_filepath)
     191        assert result == 0
     192
     193    def test_simple_rsync_to_directory(self, tmpdir):
     194
     195        # Setup source file and target dir
     196        filename = "real_file.txt"
     197        real_file = make_a_real_file(tmpdir, filename)
     198
     199        destination_dir = os.path.join(tmpdir, "destination")
     200        os.makedirs(destination_dir)
     201        assert os.path.exists(destination_dir)
     202
     203        expected_filepath = os.path.join(destination_dir, filename)
     204        assert not os.path.exists(expected_filepath)
     205
     206        # run rsync function and confirm rsync exists (and original)
     207        result = utils.local_rsync_wrapper([real_file, destination_dir])
     208        assert result == 0
     209        assert os.path.isfile(real_file)
     210        assert os.path.exists(expected_filepath)
     211
     212    def test_rsyncing_directories_and_subdirectories(self, tmpdir):
     213
     214        subdir = os.path.join(tmpdir, "subdir")
     215        subsubdir = os.path.join(subdir, "subsubdir")
     216        os.makedirs(subsubdir)
     217        filename_a = "file_in_subdir.txt"
     218        filename_b = "file_in_subsubdir.txt"
     219        make_a_real_file(subdir, filename_a)
     220        make_a_real_file(subsubdir, filename_b)
     221
     222        destination_dir = os.path.join(tmpdir, "destination")
     223        os.makedirs(destination_dir)
     224        expected_filepath_a = os.path.join(destination_dir, "subdir", filename_a)
     225        expected_filepath_b = os.path.join(destination_dir, "subdir", "subsubdir", filename_b)
     226        assert not os.path.exists(expected_filepath_a)
     227        assert not os.path.exists(expected_filepath_b)
     228
     229        # silently passes without -r, just skips over directories
     230        assert not os.path.exists(expected_filepath_a)
     231        assert not os.path.exists(expected_filepath_b)
     232
     233        utils.local_rsync_wrapper([subdir, destination_dir])
     234        assert not os.path.exists(expected_filepath_a)
     235        assert not os.path.exists(expected_filepath_b)
     236
     237        # requires -r to copy directories (and contents)
     238        utils.local_rsync_wrapper(["-r", subdir, destination_dir])
     239        assert os.path.exists(expected_filepath_a)
     240        assert os.path.exists(expected_filepath_b)
Note: See TracChangeset for help on using the changeset viewer.