- Timestamp:
- Oct 9, 2019, 2:15:34 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ipp-259_genericise_backups/tools/backups/backup_test.py
r40931 r40932 186 186 assert os.path.exists(expected2file) 187 187 188 def copy_fails_if_source_file_does_not_exist(self, tmpdir):188 def test_copy_fails_if_source_file_does_not_exist(self, tmpdir): 189 189 config = make_default_config(tmpdir, ['bck1', 'bck2']) 190 190 source = os.path.join(tmpdir, "and_specific_file.jpeg") … … 196 196 assert not os.path.exists(source) 197 197 backy = Backup(config) 198 with pytest.raises(errs. SubprocessError):198 with pytest.raises(errs.ValidationError): 199 199 backy._run_copy() 200 200 201 def copy_fails_if_destination_does_not_exist(self, tmpdir):201 def test_copy_fails_if_destination_does_not_exist(self, tmpdir): 202 202 config = ConfigParser() 203 203 … … 214 214 assert not os.path.exists(backup_does_not_exist) 215 215 backy = Backup(config) 216 with pytest.raises(errs. SubprocessError):216 with pytest.raises(errs.ValidationError): 217 217 backy._run_copy() 218 218 … … 298 298 299 299 300 # class TestRunningRsync(): 301 302 # def test_simply_rsync(self): 303 # assert True is False 304 305 # def test_rsync_with_additional_args(self): 306 # assert True is False 300 class TestRunningRsync(): 301 302 def test_simple_rsync(self, tmpdir): 303 config = make_default_config(tmpdir, ['bck1', 'bck2']) 304 source = os.path.join(tmpdir, "and_specific_file.jpeg") 305 config['RSYNC'] = {'sources' : f"{source}"} 306 307 # make file to be copied 308 Path(source).touch() 309 310 backy = Backup(config) 311 312 expected1file = os.path.join(tmpdir, 'bck1', 'and_specific_file.jpeg') 313 expected2file = os.path.join(tmpdir, 'bck2', 'and_specific_file.jpeg') 314 assert not os.path.exists(expected1file) 315 assert not os.path.exists(expected2file) 316 backy._run_rsync() 317 assert os.path.exists(expected1file) 318 assert os.path.exists(expected2file) 319 320 def test_rsync_with_additional_args(self, tmpdir): 321 config = make_default_config(tmpdir, ['bck1', 'bck2']) 322 source1 = os.path.join(tmpdir, "some_dir") 323 source2 = os.path.join(tmpdir, "and_specific_file.jpeg") 324 config['RSYNC'] = \ 325 { 'sources' : f"{source1}, {source2}" 326 , 'additional_args' : "-v -z -r --progress" 327 } 328 329 os.makedirs(source1) 330 Path(source2).touch() 331 332 backy = Backup(config) 333 334 expected1dir = os.path.join(tmpdir, 'bck1', 'some_dir') 335 expected1file = os.path.join(tmpdir, 'bck1', 'and_specific_file.jpeg') 336 expected2dir = os.path.join(tmpdir, 'bck2', 'some_dir') 337 expected2file = os.path.join(tmpdir, 'bck2', 'and_specific_file.jpeg') 338 assert not os.path.exists(expected1dir) 339 assert not os.path.exists(expected1file) 340 assert not os.path.exists(expected2dir) 341 assert not os.path.exists(expected2file) 342 backy._run_rsync() 343 assert os.path.exists(expected1dir) 344 assert os.path.exists(expected1file) 345 assert os.path.exists(expected2dir) 346 assert os.path.exists(expected2file) 347 348 def test_rsync_fails_if_source_file_does_not_exist(self, tmpdir): 349 config = make_default_config(tmpdir, ['bck1', 'bck2']) 350 source = os.path.join(tmpdir, "and_specific_file.jpeg") 351 config['RSYNC'] = \ 352 { 'sources' : f"{source}" 353 , 'additional_args' : '-r' 354 } 355 356 assert not os.path.exists(source) 357 backy = Backup(config) 358 with pytest.raises(errs.ValidationError): 359 backy._run_rsync() 360 361 def test_rsync_fails_if_destination_does_not_exist(self, tmpdir): 362 config = ConfigParser() 363 364 backup_does_not_exist = os.path.join(tmpdir, 'does_not_exist') 365 366 config['DEFAULT'] = \ 367 { 'backup_paths' : backup_does_not_exist 368 , 'source_machine': socket.gethostname() 369 } 370 source = os.path.join(tmpdir, "and_specific_file.jpeg") 371 Path(source).touch() 372 config['RSYNC'] = {'sources' : f"{source}"} 373 374 assert not os.path.exists(backup_does_not_exist) 375 backy = Backup(config) 376 with pytest.raises(errs.ValidationError): 377 backy._run_rsync() 378 379 def test_rsync_requires_dash_r_arg_for_copying_dirs(self, tmpdir): 380 config = make_default_config(tmpdir, ['bck1', 'bck2']) 381 source = os.path.join(tmpdir, "some_dir") 382 config['RSYNC'] = \ 383 { 'sources' : f"{source}" 384 } 385 os.makedirs(source) 386 387 backy = Backup(config) 388 expected1dir = os.path.join(tmpdir, 'bck1', 'some_dir') 389 expected2dir = os.path.join(tmpdir, 'bck2', 'some_dir') 390 assert not os.path.exists(expected1dir) 391 assert not os.path.exists(expected2dir) 392 backy._run_rsync() 393 assert not os.path.exists(expected1dir) 394 assert not os.path.exists(expected2dir) 395 396 config['RSYNC'] = \ 397 { 'sources' : f"{source}" 398 , 'additional_args' : '-r' 399 } 400 401 backy = Backup(config) 402 expected1dir = os.path.join(tmpdir, 'bck1', 'some_dir') 403 expected2dir = os.path.join(tmpdir, 'bck2', 'some_dir') 404 assert not os.path.exists(expected1dir) 405 assert not os.path.exists(expected2dir) 406 backy._run_rsync() 407 assert os.path.exists(expected1dir) 408 assert os.path.exists(expected2dir) 307 409 308 410
Note:
See TracChangeset
for help on using the changeset viewer.
