IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40945


Ignore:
Timestamp:
Oct 15, 2019, 12:27:24 PM (7 years ago)
Author:
fairlamb
Message:

re-add file for testing generic backup config; corerctly name ConfigSchemaSection class

Location:
branches/ipp-259_genericise_backups/tools/backups
Files:
1 added
4 edited

Legend:

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

    r40944 r40945  
    1010import backups.utils.errors as errs
    1111import backups.utils.subprocess_utils as sub_utils
    12 from backups.utils.config_parse_helper import ConfigSchema, ConfigSchemaLine
     12from backups.utils.config_parse_helper import ConfigSchemaSection, ConfigSchemaLine
    1313
    1414DEFAULT_CONFIG_FILE = path.join(path.dirname(__file__), 'atlassian_backups.config')
     
    6868        return self.run_mysqldump
    6969
    70     DEFAULT_SCHEMA = ConfigSchema('DEFAULT',
     70    DEFAULT_SCHEMA = ConfigSchemaSection('DEFAULT',
    7171        [ ConfigSchemaLine('backup_paths', True, list, cfg_help.SpecialSchemaProcessing.commma_separated)
    7272        , ConfigSchemaLine('source_machine', True, str)
     
    7676    )
    7777
    78     def read_default_section(self, config: ConfigParser, schema: ConfigSchema=DEFAULT_SCHEMA):
     78    def read_default_section(self, config: ConfigParser, schema: ConfigSchemaSection=DEFAULT_SCHEMA):
    7979        self.default_dict = cfg_help.parse_config(config, schema)
    8080        self.hostname_is_valid()
    8181        self.maybe_make_backup_dirs()
    8282
    83     COPY_SCHEMA = ConfigSchema('COPY',
     83    COPY_SCHEMA = ConfigSchemaSection('COPY',
    8484        [ ConfigSchemaLine('sources', True, list, cfg_help.SpecialSchemaProcessing.commma_separated)
    8585        , ConfigSchemaLine('additional_args', False, list, cfg_help.SpecialSchemaProcessing.space_separated)
     
    8787    )
    8888
    89     def read_copy_config_section(self, config: ConfigParser, schema: ConfigSchema=COPY_SCHEMA):
     89    def read_copy_config_section(self, config: ConfigParser, schema: ConfigSchemaSection=COPY_SCHEMA):
    9090        self.copy_dict = cfg_help.parse_config(config, schema)
    9191
    92     TAR_SCHEMA = ConfigSchema('TAR',
     92    TAR_SCHEMA = ConfigSchemaSection('TAR',
    9393        [ ConfigSchemaLine('sources', True, list, cfg_help.SpecialSchemaProcessing.commma_separated)
    9494        , ConfigSchemaLine('additional_args', False, list, cfg_help.SpecialSchemaProcessing.space_separated)
     
    9898    )
    9999
    100     def read_tar_config_section(self, config: ConfigParser, schema: ConfigSchema=TAR_SCHEMA):
     100    def read_tar_config_section(self, config: ConfigParser, schema: ConfigSchemaSection=TAR_SCHEMA):
    101101        self.tar_dict = cfg_help.parse_config(config, schema)
    102102
    103     RSYNC_SCHEMA = ConfigSchema('RSYNC',
     103    RSYNC_SCHEMA = ConfigSchemaSection('RSYNC',
    104104        [ ConfigSchemaLine('sources', True, list, cfg_help.SpecialSchemaProcessing.commma_separated)
    105105        , ConfigSchemaLine('additional_args', False, list, cfg_help.SpecialSchemaProcessing.space_separated)
     
    107107    )
    108108
    109     def read_rsync_config_section(self, config: ConfigParser, schema: ConfigSchema=RSYNC_SCHEMA):
     109    def read_rsync_config_section(self, config: ConfigParser, schema: ConfigSchemaSection=RSYNC_SCHEMA):
    110110        self.rsync_dict = cfg_help.parse_config(config, schema)
    111111
    112     MYSQLDUMP_SCHEMA = ConfigSchema('MYSQLDUMP',
     112    MYSQLDUMP_SCHEMA = ConfigSchemaSection('MYSQLDUMP',
    113113        [ ConfigSchemaLine('user', True, str)
    114114        , ConfigSchemaLine('password', True, str)
     
    120120    )
    121121
    122     def read_mysqldump_config_section(self, config: ConfigParser, schema: ConfigSchema=MYSQLDUMP_SCHEMA):
     122    def read_mysqldump_config_section(self, config: ConfigParser, schema: ConfigSchemaSection=MYSQLDUMP_SCHEMA):
    123123        self.mysqldump_dict = cfg_help.parse_config(config, schema)
    124124
  • branches/ipp-259_genericise_backups/tools/backups/backup_test.py

    r40944 r40945  
    1010
    1111
    12 TEST_DEFAULT_CONFIG_FILE = os.path.join(os.path.dirname(__file__), 'testing/full_backup_config.config')
     12TEST_DEFAULT_CONFIG_FILE = os.path.join(os.path.dirname(__file__), 'testing/backup_test.config')
    1313
    1414
  • branches/ipp-259_genericise_backups/tools/backups/utils/config_parse_helper.py

    r40937 r40945  
    3535
    3636
    37 class ConfigSchema():
     37class ConfigSchemaSection():
    3838    """Defines a schema to be used. Consists of a single section name and
    3939multiple config lines"""
     
    7676
    7777
    78 def parse_config(config: ConfigParser(), schema: ConfigSchema) -> dict:
     78def parse_config(config: ConfigParser(), schema: ConfigSchemaSection) -> dict:
    7979    """For a given config it will extract all values defined by the schema
    8080and return them as a dictionary of the keys and the assoicated value as the
  • branches/ipp-259_genericise_backups/tools/backups/utils/config_parse_helper_test.py

    r40919 r40945  
    4141
    4242
    43 class TestConfigSchema():
     43class TestConfigSchemaSection():
    4444
    4545    def test_initalising_schema(self):
     
    4848        csl3 = helper.ConfigSchemaLine('some_float', False, float)
    4949
    50         schema = helper.ConfigSchema( 'section_name', [csl1, csl2, csl3] )
     50        schema = helper.ConfigSchemaSection( 'section_name', [csl1, csl2, csl3] )
    5151        assert schema.options == { 'is_cool' : csl1
    5252                                 , 'fav_word' : csl2
     
    5454                                 }
    5555
    56     def test_empty_schema_ok(self):
    57         helper.ConfigSchema("ok_with_none", None)
    58         helper.ConfigSchema("ok_with_empty", [])
    59 
    60     def test_schema_fails_if_options_are_not_a_list(self):
     56    def test_empty_schema_section_ok(self):
     57        helper.ConfigSchemaSection("ok_with_none", None)
     58        helper.ConfigSchemaSection("ok_with_empty", [])
     59
     60    def test_schema_section_fails_if_options_are_not_a_list(self):
    6161        with pytest.raises(ValidationError):
    62             helper.ConfigSchema("fails_if_not_a_list", True)
     62            helper.ConfigSchemaSection("fails_if_not_a_list", True)
    6363
    6464        csl = helper.ConfigSchemaLine('key1', True, bool)
    6565        with pytest.raises(ValidationError):
    66             helper.ConfigSchema("even_fails_on_a_single_csl", csl)
     66            helper.ConfigSchemaSection("even_fails_on_a_single_csl", csl)
    6767
    6868    def test_adding_to_schema(self):
    69         config = helper.ConfigSchema("adding", [])
     69        config = helper.ConfigSchemaSection("adding", [])
    7070        assert config.options == {}
    7171
     
    8888
    8989    def test_adding_a_duplicate_key_to_schema_replaces_previous(self):
    90         config = helper.ConfigSchema("adding", [])
     90        config = helper.ConfigSchemaSection("adding", [])
    9191        assert config.options == {}
    9292
     
    153153
    154154        csl1 = helper.ConfigSchemaLine('Required_key', True, bool)
    155         schema = helper.ConfigSchema('DEFAULT', [csl1] )
     155        schema = helper.ConfigSchemaSection('DEFAULT', [csl1] )
    156156
    157157        with pytest.raises(ConfigError):
    158158            helper.parse_config(config, schema)
    159159
    160     def test_schema_of_only_optional_values_is_ok(self):
     160    def test_schema_section_with_only_optional_values_is_ok(self):
    161161        csl1 = helper.ConfigSchemaLine('not_required', False, bool)
    162162        csl2 = helper.ConfigSchemaLine('not_required_either', False, float)
    163         schema = helper.ConfigSchema('DEFAULT', [csl1, csl2] )
     163        schema = helper.ConfigSchemaSection('DEFAULT', [csl1, csl2] )
    164164        config = self.make_simple_config()
    165165        result = helper.parse_config(config, schema)
    166166        assert result == {}
    167167
    168     def test_parsing_schema_with_ints(self):
     168    def test_parsing_schema_section_with_ints(self):
    169169        csl1 = helper.ConfigSchemaLine('inty', False, int)
    170         schema = helper.ConfigSchema('DEFAULT', [csl1] )
     170        schema = helper.ConfigSchemaSection('DEFAULT', [csl1] )
    171171        config = self.make_simple_config()
    172172        result = helper.parse_config(config, schema)
    173173        assert result == { 'inty' : 3}
    174174
    175     def test_parsing_schema_with_floats(self):
     175    def test_parsing_schema_section_with_floats(self):
    176176        csl1 = helper.ConfigSchemaLine('floaty', False, float)
    177         schema = helper.ConfigSchema('DEFAULT', [csl1] )
     177        schema = helper.ConfigSchemaSection('DEFAULT', [csl1] )
    178178        config = self.make_simple_config()
    179179        result = helper.parse_config(config, schema)
    180180        assert result == { 'floaty' : 3.141 }
    181181
    182     def test_parsing_schema_with_bools(self):
     182    def test_parsing_schema_section_with_bools(self):
    183183        csl1 = helper.ConfigSchemaLine('mr_bool', True, bool)
    184         schema = helper.ConfigSchema('DEFAULT', [csl1] )
     184        schema = helper.ConfigSchemaSection('DEFAULT', [csl1] )
    185185        config = self.make_simple_config()
    186186        result = helper.parse_config(config, schema)
    187187        assert result == { 'mr_bool' : True }
    188188
    189     def test_parsing_schema_with_strs(self):
     189    def test_parsing_schema_section_with_strs(self):
    190190        csl1 = helper.ConfigSchemaLine('stringer', True, str)
    191         schema = helper.ConfigSchema('DEFAULT', [csl1] )
     191        schema = helper.ConfigSchemaSection('DEFAULT', [csl1] )
    192192        config = self.make_simple_config()
    193193        result = helper.parse_config(config, schema)
    194194        assert result == { 'stringer' : 'bell' }
    195195
    196     def test_parsing_schema_with_lists_comma_separated(self):
     196    def test_parsing_schema_section_with_lists_comma_separated(self):
    197197        csl1 = helper.ConfigSchemaLine('listo_comma', False, list,
    198198            helper.SpecialSchemaProcessing.commma_separated)
    199         schema = helper.ConfigSchema('DEFAULT', [csl1] )
     199        schema = helper.ConfigSchemaSection('DEFAULT', [csl1] )
    200200        config = self.make_simple_config()
    201201        result = helper.parse_config(config, schema)
     
    207207                         }
    208208
    209     def test_parsing_schema_with_lists_space_separated(self):
     209    def test_parsing_schema_section_with_lists_space_separated(self):
    210210        csl1 = helper.ConfigSchemaLine('listo_space', False, list,
    211211            helper.SpecialSchemaProcessing.space_separated)
    212         schema = helper.ConfigSchema('DEFAULT', [csl1] )
     212        schema = helper.ConfigSchemaSection('DEFAULT', [csl1] )
    213213        config = self.make_simple_config()
    214214        result = helper.parse_config(config, schema)
     
    231231            helper.SpecialSchemaProcessing.commma_separated)
    232232
    233         schema = helper.ConfigSchema('DEFAULT', [csl_float])
     233        schema = helper.ConfigSchemaSection('DEFAULT', [csl_float])
    234234        result = helper.parse_config(config, schema)
    235235        assert result == { 'floaty' : 3.141 }
    236236        assert type(result['floaty']) is float
    237237
    238         schema = helper.ConfigSchema('DEFAULT', [csl_int])
     238        schema = helper.ConfigSchemaSection('DEFAULT', [csl_int])
    239239        with pytest.raises(ValueError):
    240240            helper.parse_config(config, schema)
    241241
    242         schema = helper.ConfigSchema('DEFAULT', [csl_bool])
     242        schema = helper.ConfigSchemaSection('DEFAULT', [csl_bool])
    243243        with pytest.raises(ValueError):
    244244            helper.parse_config(config, schema)
    245245
    246         schema = helper.ConfigSchema('DEFAULT', [csl_str])
     246        schema = helper.ConfigSchemaSection('DEFAULT', [csl_str])
    247247        result = helper.parse_config(config, schema)
    248248        assert result == { 'floaty' : '3.141' }
    249249        assert type(result['floaty']) is str
    250250
    251         schema = helper.ConfigSchema('DEFAULT', [csl_list])
     251        schema = helper.ConfigSchemaSection('DEFAULT', [csl_list])
    252252        result = helper.parse_config(config, schema)
    253253        assert result == { 'floaty' : ['3.141'] }
    254254        assert type(result['floaty']) is list
    255255
    256     def test_parsing_schema_fails_with_unknown_type(self):
     256    def test_parsing_schema_line_fails_with_unknown_type(self):
    257257        csl1 = helper.ConfigSchemaLine('floaty', True, dict)
    258         schema = helper.ConfigSchema('DEFAULT', [csl1] )
     258        schema = helper.ConfigSchemaSection('DEFAULT', [csl1] )
    259259        config = self.make_simple_config()
    260260        with pytest.raises(ConfigError):
     
    267267        for e in helper.SpecialSchemaProcessing:
    268268            csl = helper.ConfigSchemaLine('enum_checker', False, list, e)
    269             schema = helper.ConfigSchema('DEFAULT', [csl])
     269            schema = helper.ConfigSchemaSection('DEFAULT', [csl])
    270270
    271271            result = helper.parse_config(config, schema)
     
    283283        csl6 = helper.ConfigSchemaLine('listo_space', False, list,
    284284            helper.SpecialSchemaProcessing.space_separated)
    285         schema = helper.ConfigSchema('FULL_TEST', [csl1, csl2, csl3, csl4, csl5, csl6])
     285        schema = helper.ConfigSchemaSection('FULL_TEST', [csl1, csl2, csl3, csl4, csl5, csl6])
    286286
    287287        result = helper.parse_config(config, schema)
Note: See TracChangeset for help on using the changeset viewer.