- Timestamp:
- Oct 11, 2019, 3:49:23 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ipp-259_genericise_backups/tools/backups/backup_test.py
r40932 r40937 27 27 source_machine = socket.gethostname() 28 28 config['DEFAULT'] = \ 29 { 30 'backup_paths' : backup_paths, 31 'source_machine' : source_machine, 32 'verbose' : verbose, 33 } 29 { 'backup_paths' : backup_paths 30 , 'source_machine' : source_machine 31 , 'verbose' : verbose 32 } 34 33 return config 35 34 … … 107 106 Backup(config_file=config) 108 107 109 with pytest.raises(errs. ConfigError):108 with pytest.raises(errs.ValidationError): 110 109 Backup(config_file=None) 111 110 … … 136 135 backy.default_dict['source_machine'] = actual_hostname 137 136 assert backy.hostname_is_valid() is True 137 138 139 class TestFilepathVerifications(object): 140 141 def test_default_target_paths_do_not_exist_in_testing(self): 142 backy = Backup(config_file=TEST_DEFAULT_CONFIG_FILE) 143 assert backy.target_backup_paths_ok() is False 144 145 def test_raising_an_error_if_a_backup_path_does_not_exist(self): 146 with pytest.raises(errs.ValidationError) as e: 147 backy = Backup(config_file=TEST_DEFAULT_CONFIG_FILE) 148 backy.target_backup_paths_ok(raise_error=True) 149 assert "ValidationError: target path does not exist" in str(e) 150 151 def test_an_incorrect_path_then_correct_path(self, tmpdir): 152 backy = Backup(config_file=TEST_DEFAULT_CONFIG_FILE) 153 154 backy.default_dict['backup_paths'] = ["/not/real/path"] 155 assert backy.target_backup_paths_ok() is False 156 157 backy.default_dict['backup_paths'] = [tmpdir] 158 assert backy.target_backup_paths_ok() is True 159 160 def test_backup_paths_created_if_make_dirs_given(self, tmpdir): 161 config = ConfigParser() 162 config['DEFAULT'] = \ 163 { 'backup_paths' : f"{tmpdir}/bck1/bobby/backup, {tmpdir}/bck2" 164 , 'source_machine' : 'rocket' 165 , 'verbose' : 'True' 166 } 167 bck1_path = os.path.join(tmpdir, 'bck1') 168 bck1b_path = os.path.join(tmpdir, 'bck1/bobby') 169 bck1bb_path = os.path.join(tmpdir, 'bck1/bobby/backup') 170 bck2_path = os.path.join(tmpdir, 'bck2') 171 assert not os.path.exists(bck1_path) 172 assert not os.path.exists(bck1b_path) 173 assert not os.path.exists(bck1bb_path) 174 assert not os.path.exists(bck2_path) 175 # backup dirs not created automatically 176 Backup(config) 177 assert not os.path.exists(bck1_path) 178 assert not os.path.exists(bck1b_path) 179 assert not os.path.exists(bck1bb_path) 180 assert not os.path.exists(bck2_path) 181 182 # make_dirs included in config - when loaded dirs created. 183 config['DEFAULT'] = \ 184 { 'backup_paths' : f"{tmpdir}/bck1/bobby/backup, {tmpdir}/bck2" 185 , 'source_machine' : 'rocket' 186 , 'verbose' : 'True' 187 , 'make_dirs' : 'True' 188 } 189 backy = Backup(config) 190 assert backy.default_dict['make_dirs'] is True 191 assert os.path.exists(bck1_path) 192 assert os.path.exists(bck1b_path) 193 assert os.path.exists(bck1bb_path) 194 assert os.path.exists(bck2_path) 138 195 139 196 … … 265 322 assert not os.path.exists(expected_tar1) 266 323 backy._run_tar() 267 print(expected_tar1)268 324 assert os.path.exists(expected_tar1) 269 325 … … 422 478 """ 423 479 424 dumper_password = "not_a_real_password"425 426 480 def test_mysql_dump_is_ok(self, tmpdir): 427 481 config = make_default_config(tmpdir, ['bck1', 'bck2']) … … 442 496 assert not os.path.exists(expected_dump1) 443 497 assert not os.path.exists(expected_dump2) 444 backy._run_mysqldump()498 result = backy._run_mysqldump() 445 499 assert os.path.exists(expected_dump1) 446 500 assert os.path.exists(expected_dump2) 501 502 assert result == 0 447 503 448 504 def test_mysql_dump_fails_with_incorrect_password(self, tmpdir):
Note:
See TracChangeset
for help on using the changeset viewer.
