Changeset 40944
- Timestamp:
- Oct 14, 2019, 4:59:32 PM (7 years ago)
- Location:
- branches/ipp-259_genericise_backups/tools/backups
- Files:
-
- 5 deleted
- 6 edited
-
backup.py (modified) (1 diff)
-
backup_test.py (modified) (1 diff)
-
confluence_backup.config (deleted)
-
confluence_backup.py (modified) (2 diffs)
-
confluence_backup_test.py (modified) (5 diffs)
-
fixture_test.py (deleted)
-
full_atlassian_backup_test.py (deleted)
-
jira_backup.config (deleted)
-
jira_backup.py (modified) (2 diffs)
-
jira_backup_test.py (modified) (2 diffs)
-
testing/full_backup_config.config (deleted)
Legend:
- Unmodified
- Added
- Removed
-
branches/ipp-259_genericise_backups/tools/backups/backup.py
r40937 r40944 29 29 30 30 config = ConfigParser() 31 expected_class = configparser.ConfigParser 31 32 if config_class_or_filepath is None: 32 raise errs. ConfigError(config_class_or_filepath, "Neither config settings or filepath of configgiven")33 elif isinstance(config_class_or_filepath, configparser.ConfigParser):33 raise errs.ValidationError("ValidationError: config settings or filepath to config must be given") 34 elif isinstance(config_class_or_filepath, expected_class): 34 35 config = config_class_or_filepath 35 elif path.exists(config_class_or_filepath): 36 config.read(config_class_or_filepath) 36 elif not path.exists(config_class_or_filepath): 37 raise errs.ValidationError(f"ValidationError: Config filepath does not exist (or incorrect class given, expected: {expected_class})") 38 config.read(config_class_or_filepath) 37 39 38 40 self.read_default_section(config) -
branches/ipp-259_genericise_backups/tools/backups/backup_test.py
r40937 r40944 103 103 def test_failure_if_no_defaults_provided(self): 104 104 config = ConfigParser() 105 with pytest.raises(errs.ConfigError) :105 with pytest.raises(errs.ConfigError) as e_empty: 106 106 Backup(config_file=config) 107 108 with pytest.raises(errs.ValidationError): 107 assert "is required but was not found in config" in str(e_empty) 108 109 with pytest.raises(errs.ValidationError) as e_none: 109 110 Backup(config_file=None) 110 111 with pytest.raises(errs.ConfigError): 111 assert "ValidationError: Backup class must be given a config" in str(e_none) 112 113 with pytest.raises(errs.ValidationError) as e_nofile: 112 114 Backup(config_file="/not/a/real/file.config") 115 assert "ValidationError: Config filepath does not exist" in str(e_nofile) 113 116 114 117 def test_nothing_should_be_set_to_run_if_not_present(self, tmpdir): -
branches/ipp-259_genericise_backups/tools/backups/confluence_backup.py
r40937 r40944 8 8 from backups.backup import Backup 9 9 10 DEFAULT_CONFIG_FILE = path.join(path.dirname(__file__), 'confluence_backup.config')10 EXPECTED_CONFIG_FILE = path.join(path.dirname(__file__), './confluence_backup.config') 11 11 12 12 13 13 class ConfluenceBackup(Backup): 14 14 15 def __init__(self, config_file= DEFAULT_CONFIG_FILE):15 def __init__(self, config_file=EXPECTED_CONFIG_FILE): 16 16 self.load_config(config_file) 17 17 … … 69 69 nargs='?', 70 70 help='specify the location of a config that matches the ConfigSchema', 71 default= DEFAULT_CONFIG_FILE)71 default=EXPECTED_CONFIG_FILE) 72 72 73 73 return parser.parse_args() -
branches/ipp-259_genericise_backups/tools/backups/confluence_backup_test.py
r40937 r40944 12 12 13 13 14 JIRA_TEST_CONFIG = os.path.join(os.path.dirname(__file__), './testing/confluence_test.config')14 CONF_TEST_CONFIG = os.path.join(os.path.dirname(__file__), './testing/confluence_test.config') 15 15 16 16 … … 113 113 114 114 def test_load_from_config_file(self): 115 jb = ConfluenceBackup(config_file= JIRA_TEST_CONFIG)115 jb = ConfluenceBackup(config_file=CONF_TEST_CONFIG) 116 116 self.assert_defaults(jb) 117 117 118 def test_default_config_loads_with_no_args(self): 119 default_config = jbck_mod.DEFAULT_CONFIG_FILE 120 assert os.path.exists(default_config) 121 jb = ConfluenceBackup() 122 self.assert_defaults(jb) 118 def test_default_config_fails_to_load_if_the_file_does_not_exist(self): 119 default_config = jbck_mod.EXPECTED_CONFIG_FILE 120 assert not os.path.exists(default_config) 121 122 with pytest.raises(errs.ValidationError) as e: 123 ConfluenceBackup() 124 assert "ValidationError: Config filepath does not exist" in str(e) 123 125 124 126 def test_default_arguments(self): 125 jb = ConfluenceBackup(config_file= JIRA_TEST_CONFIG)127 jb = ConfluenceBackup(config_file=CONF_TEST_CONFIG) 126 128 self.assert_defaults(jb) 127 129 … … 166 168 167 169 def test_nonexistant_config_file_raises_error(self): 168 with pytest.raises(errs. ConfigError):170 with pytest.raises(errs.ValidationError) as e: 169 171 ConfluenceBackup("not a real file path") 172 assert "ValidationError: Config filepath does not exist" in str(e) 170 173 171 174 def test_main_loads_default_and_fails_due_to_missing_paths(self): 172 175 with pytest.raises(errs.ValidationError) as e: 173 176 jbck_mod.main() 174 assert "ValidationError: target path does not exist:" in str(e)177 assert "ValidationError: Config filepath does not exist" in str(e) 175 178 176 179 … … 180 183 181 184 def test_get_confluence_backup_date_format(self): 182 jb = ConfluenceBackup(config_file= JIRA_TEST_CONFIG)185 jb = ConfluenceBackup(config_file=CONF_TEST_CONFIG) 183 186 today = datetime.date.today() 184 187 expected_format = today.strftime("%Y_%m_%d") … … 190 193 191 194 def test_copying_fails_if_paths_not_present(self): 192 jb = ConfluenceBackup(config_file= JIRA_TEST_CONFIG)195 jb = ConfluenceBackup(config_file=CONF_TEST_CONFIG) 193 196 # return_value = jb._copy_confluence_backup() 194 197 with pytest.raises(ValidationError) as e: -
branches/ipp-259_genericise_backups/tools/backups/jira_backup.py
r40937 r40944 8 8 from backups.backup import Backup 9 9 10 DEFAULT_CONFIG_FILE = path.join(path.dirname(__file__), 'jira_backup.config')10 EXPECTED_CONFIG_FILE = path.join(path.dirname(__file__), './jira_backup.config') 11 11 12 12 13 13 class JiraBackup(Backup): 14 14 15 def __init__(self, config_file= DEFAULT_CONFIG_FILE):15 def __init__(self, config_file=EXPECTED_CONFIG_FILE): 16 16 self.load_config(config_file) 17 17 … … 69 69 nargs='?', 70 70 help='specify the location of a config that matches the ConfigSchema', 71 default= DEFAULT_CONFIG_FILE)71 default=EXPECTED_CONFIG_FILE) 72 72 73 73 return parser.parse_args() -
branches/ipp-259_genericise_backups/tools/backups/jira_backup_test.py
r40937 r40944 116 116 self.assert_defaults(jb) 117 117 118 def test_default_config_loads_with_no_args(self): 119 default_config = jbck_mod.DEFAULT_CONFIG_FILE 120 assert os.path.exists(default_config) 121 jb = JiraBackup() 122 self.assert_defaults(jb) 118 def test_default_config_fails_to_load_if_the_file_does_not_exist(self): 119 default_config = jbck_mod.EXPECTED_CONFIG_FILE 120 assert not os.path.exists(default_config) 121 122 with pytest.raises(errs.ValidationError) as e: 123 JiraBackup() 124 assert "ValidationError: Config filepath does not exist" in str(e) 123 125 124 126 def test_default_arguments(self): … … 166 168 167 169 def test_nonexistant_config_file_raises_error(self): 168 with pytest.raises(errs. ConfigError):170 with pytest.raises(errs.ValidationError) as e: 169 171 JiraBackup("not a real file path") 172 assert "ValidationError: Config filepath does not exist" in str(e) 170 173 171 174 def test_main_loads_default_and_fails_due_to_missing_paths(self): 172 175 with pytest.raises(errs.ValidationError) as e: 173 176 jbck_mod.main() 174 assert "ValidationError: target path does not exist:" in str(e)177 assert "ValidationError: Config filepath does not exist" in str(e) 175 178 176 179
Note:
See TracChangeset
for help on using the changeset viewer.
