IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40944


Ignore:
Timestamp:
Oct 14, 2019, 4:59:32 PM (7 years ago)
Author:
fairlamb
Message:

Tidy up tests, and removed now unused files

Location:
branches/ipp-259_genericise_backups/tools/backups
Files:
5 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • branches/ipp-259_genericise_backups/tools/backups/backup.py

    r40937 r40944  
    2929
    3030        config = ConfigParser()
     31        expected_class = configparser.ConfigParser
    3132        if config_class_or_filepath is None:
    32             raise errs.ConfigError(config_class_or_filepath, "Neither config settings or filepath of config given")
    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):
    3435            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)
    3739
    3840        self.read_default_section(config)
  • branches/ipp-259_genericise_backups/tools/backups/backup_test.py

    r40937 r40944  
    103103    def test_failure_if_no_defaults_provided(self):
    104104        config = ConfigParser()
    105         with pytest.raises(errs.ConfigError):
     105        with pytest.raises(errs.ConfigError) as e_empty:
    106106            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:
    109110            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:
    112114            Backup(config_file="/not/a/real/file.config")
     115        assert "ValidationError: Config filepath does not exist" in str(e_nofile)
    113116
    114117    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  
    88from backups.backup import Backup
    99
    10 DEFAULT_CONFIG_FILE = path.join(path.dirname(__file__), 'confluence_backup.config')
     10EXPECTED_CONFIG_FILE = path.join(path.dirname(__file__), './confluence_backup.config')
    1111
    1212
    1313class ConfluenceBackup(Backup):
    1414
    15     def __init__(self, config_file=DEFAULT_CONFIG_FILE):
     15    def __init__(self, config_file=EXPECTED_CONFIG_FILE):
    1616        self.load_config(config_file)
    1717
     
    6969        nargs='?',
    7070        help='specify the location of a config that matches the ConfigSchema',
    71         default=DEFAULT_CONFIG_FILE)
     71        default=EXPECTED_CONFIG_FILE)
    7272
    7373    return parser.parse_args()
  • branches/ipp-259_genericise_backups/tools/backups/confluence_backup_test.py

    r40937 r40944  
    1212
    1313
    14 JIRA_TEST_CONFIG = os.path.join(os.path.dirname(__file__), './testing/confluence_test.config')
     14CONF_TEST_CONFIG = os.path.join(os.path.dirname(__file__), './testing/confluence_test.config')
    1515
    1616
     
    113113
    114114    def test_load_from_config_file(self):
    115         jb = ConfluenceBackup(config_file=JIRA_TEST_CONFIG)
     115        jb = ConfluenceBackup(config_file=CONF_TEST_CONFIG)
    116116        self.assert_defaults(jb)
    117117
    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)
    123125
    124126    def test_default_arguments(self):
    125         jb = ConfluenceBackup(config_file=JIRA_TEST_CONFIG)
     127        jb = ConfluenceBackup(config_file=CONF_TEST_CONFIG)
    126128        self.assert_defaults(jb)
    127129
     
    166168
    167169    def test_nonexistant_config_file_raises_error(self):
    168         with pytest.raises(errs.ConfigError):
     170        with pytest.raises(errs.ValidationError) as e:
    169171            ConfluenceBackup("not a real file path")
     172        assert "ValidationError: Config filepath does not exist" in str(e)
    170173
    171174    def test_main_loads_default_and_fails_due_to_missing_paths(self):
    172175        with pytest.raises(errs.ValidationError) as e:
    173176            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)
    175178
    176179
     
    180183
    181184    def test_get_confluence_backup_date_format(self):
    182         jb = ConfluenceBackup(config_file=JIRA_TEST_CONFIG)
     185        jb = ConfluenceBackup(config_file=CONF_TEST_CONFIG)
    183186        today = datetime.date.today()
    184187        expected_format = today.strftime("%Y_%m_%d")
     
    190193
    191194    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)
    193196        # return_value = jb._copy_confluence_backup()
    194197        with pytest.raises(ValidationError) as e:
  • branches/ipp-259_genericise_backups/tools/backups/jira_backup.py

    r40937 r40944  
    88from backups.backup import Backup
    99
    10 DEFAULT_CONFIG_FILE = path.join(path.dirname(__file__), 'jira_backup.config')
     10EXPECTED_CONFIG_FILE = path.join(path.dirname(__file__), './jira_backup.config')
    1111
    1212
    1313class JiraBackup(Backup):
    1414
    15     def __init__(self, config_file=DEFAULT_CONFIG_FILE):
     15    def __init__(self, config_file=EXPECTED_CONFIG_FILE):
    1616        self.load_config(config_file)
    1717
     
    6969        nargs='?',
    7070        help='specify the location of a config that matches the ConfigSchema',
    71         default=DEFAULT_CONFIG_FILE)
     71        default=EXPECTED_CONFIG_FILE)
    7272
    7373    return parser.parse_args()
  • branches/ipp-259_genericise_backups/tools/backups/jira_backup_test.py

    r40937 r40944  
    116116        self.assert_defaults(jb)
    117117
    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)
    123125
    124126    def test_default_arguments(self):
     
    166168
    167169    def test_nonexistant_config_file_raises_error(self):
    168         with pytest.raises(errs.ConfigError):
     170        with pytest.raises(errs.ValidationError) as e:
    169171            JiraBackup("not a real file path")
     172        assert "ValidationError: Config filepath does not exist" in str(e)
    170173
    171174    def test_main_loads_default_and_fails_due_to_missing_paths(self):
    172175        with pytest.raises(errs.ValidationError) as e:
    173176            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)
    175178
    176179
Note: See TracChangeset for help on using the changeset viewer.