IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 22, 2019, 2:30:49 PM (7 years ago)
Author:
fairlamb
Message:

fixed calling as main + tests, removed argsparse from most

File:
1 edited

Legend:

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

    r40952 r40962  
    66from pathlib import Path
    77
    8 import backups.backup as bckup
    9 import backups.confluence_backup as jbck_mod
    10 import backups.utils.errors as errs
    11 from backups.confluence_backup import ConfluenceBackup
    12 from backups.utils.errors import ValidationError
    13 from backups.utils.config_parse_helper import ConfigSchema
     8import backup as bckup
     9import confluence_backup as cbck_mod
     10
     11from confluence_backup import ConfluenceBackup
     12from utils.errors import ValidationError
     13from utils.config_parse_helper import ConfigSchema
    1414
    1515CONF_TEST_CONFIG = os.path.join(os.path.dirname(__file__), './testing/confluence_test.config')
     
    6767
    6868    # Create backup files that will be copied
    69     confluence_backup_name = ConfluenceBackup.get_confluence_backup_date_format() + "_confluence_test_file.zip"
     69    confluence_backup_name = f"confluence-xml-backup-{ConfluenceBackup.get_confluence_backup_date_format()}.zip"
    7070    confluence_backup_filepath = os.path.join(confluence_backup_path, confluence_backup_name)
    7171    Path(confluence_backup_filepath).touch()
     
    9696            }
    9797        assert jb.copy_dict == \
    98             { 'sources' : ['/var/atlassian/application-data/confluence/export']
     98            { 'sources' : ['/var/atlassian/application-data/confluence/backups']
    9999            , 'additional_args' : ['-v']
    100100            }
    101101        assert jb.tar_dict == \
    102             { 'sources' : ['/var/atlassian/application-data/confluence/data']
     102            { 'sources' : ['/var/atlassian/application-data/confluence/attachments']
    103103            , 'additional_args' : ['--verbose', '-z', '-p', '-cf']
    104104            , 'target_filename' : 'confluence.tar.gz'
     
    118118
    119119    def test_default_config_fails_to_load_if_the_file_does_not_exist(self):
    120         default_config = jbck_mod.EXPECTED_CONFIG_FILE
     120        default_config = cbck_mod.EXPECTED_CONFIG_FILE
    121121        assert not os.path.exists(default_config)
    122122
    123         with pytest.raises(errs.ValidationError) as e:
     123        with pytest.raises(ValidationError) as e:
    124124            ConfluenceBackup()
    125125        assert "ValidationError: Config filepath does not exist" in str(e)
     
    174174
    175175    def test_nonexistant_config_file_raises_error(self):
    176         with pytest.raises(errs.ValidationError) as e:
     176        with pytest.raises(ValidationError) as e:
    177177            ConfluenceBackup("not a real file path")
    178178        assert "ValidationError: Config filepath does not exist" in str(e)
    179179
    180180    def test_main_loads_default_and_fails_due_to_missing_paths(self):
    181         with pytest.raises(errs.ValidationError) as e:
    182             jbck_mod.main()
     181        with pytest.raises(ValidationError) as e:
     182            cbck_mod.main()
    183183        assert "ValidationError: Config filepath does not exist" in str(e)
    184184
    185185
     186class TestFullRunFromMain(object):
     187
     188    def test_main_loads_and_runs_fine_when_given_config(self, tmpdir):
     189        config = configparser.ConfigParser()
     190        bpath1 = os.path.join(tmpdir, "path/1")
     191        bpath2 = os.path.join(tmpdir, "path/2")
     192        config['DEFAULT'] = \
     193            { 'backup_paths' :  f"{bpath1}, {bpath2}"
     194            , 'source_machine' : 'rocket'
     195            , 'verbose' : 'True'
     196            }
     197        copy_source = os.path.join(tmpdir, "copy/source")
     198        conf_backup_name = ConfluenceBackup.get_confluence_backup_date_format() + "_conf_test_file.zip"
     199        config['COPY'] = \
     200            { 'sources' : f'{copy_source}'
     201            }
     202        tar_source =  os.path.join(tmpdir, "tar/source")
     203        config['TAR'] = \
     204            { 'sources' : f"{tar_source}"
     205            , 'additional_args' : "--verbose -z -p -cf"
     206            , 'target_filename' : 'conf.tar.gz'
     207            , 'prefix_date' : 'False'
     208            }
     209        os.makedirs(bpath1)
     210        os.makedirs(bpath2)
     211        os.makedirs(copy_source)
     212        os.makedirs(tar_source)
     213        Path(os.path.join(copy_source, conf_backup_name)).touch()
     214
     215        schema = ConfigSchema(None)
     216        schema.add_section(bckup.DEFAULT_SCHEMA_SECTION)
     217        schema.add_section(bckup.COPY_SCHEMA_SECTION)
     218        schema.add_section(bckup.TAR_SCHEMA_SECTION)
     219
     220        cbck_mod.main(config, schema)
     221        assert True is True
     222
     223
    186224class TestCopyingBackups(object):
    187225
     
    189227
    190228    def test_get_confluence_backup_date_format(self):
    191         jb = ConfluenceBackup(config_file=CONF_TEST_CONFIG)
     229        cb = ConfluenceBackup(config_file=CONF_TEST_CONFIG)
    192230        today = datetime.date.today()
    193231        expected_format = today.strftime("%Y_%m_%d")
    194         assert jb.get_confluence_backup_date_format() == expected_format
     232        assert cb.get_confluence_backup_date_format() == expected_format
    195233
    196234        another_date = datetime.date(1988, 11, 23)
    197235        expected_format = another_date.strftime("%Y_%m_%d")
    198         assert jb.get_confluence_backup_date_format(another_date) == expected_format
     236        assert cb.get_confluence_backup_date_format(another_date) == expected_format
    199237
    200238    def test_copying_fails_if_paths_not_present(self):
    201         jb = ConfluenceBackup(config_file=CONF_TEST_CONFIG)
    202         # return_value = jb._copy_confluence_backup()
    203         with pytest.raises(ValidationError) as e:
    204             jb._run_copy()
     239        cb = ConfluenceBackup(config_file=CONF_TEST_CONFIG)
     240        # return_value = cb._copy_confluence_backup()
     241        with pytest.raises(ValidationError) as e:
     242            cb._run_copy()
    205243        assert "ValidationError: target path does not exist:" in str(e)
    206244
     
    208246        create_items_for_full_confluence_backup_test(tmpdir)
    209247        config = make_config(tmpdir)
    210         jb = ConfluenceBackup(config_file=config)
     248        cb = ConfluenceBackup(config_file=config)
    211249
    212250        today = ConfluenceBackup.get_confluence_backup_date_format()
    213         expected_host_backup_copy = os.path.join(tmpdir, "host_backup_path", f"{today}_confluence_test_file.zip" )
    214         expected_backup_1_copy    = os.path.join(tmpdir, "backup_1_path",    f"{today}_confluence_test_file.zip" )
    215         expected_backup_2_copy    = os.path.join(tmpdir, "backup_2_path",    f"{today}_confluence_test_file.zip" )
     251        expected_host_backup_copy = os.path.join(tmpdir, "host_backup_path", f"confluence-xml-backup-{today}.zip" )
     252        expected_backup_1_copy    = os.path.join(tmpdir, "backup_1_path",    f"confluence-xml-backup-{today}.zip" )
     253        expected_backup_2_copy    = os.path.join(tmpdir, "backup_2_path",    f"confluence-xml-backup-{today}.zip" )
    216254        assert not os.path.exists(expected_host_backup_copy)
    217255        assert not os.path.exists(expected_backup_1_copy)
    218256        assert not os.path.exists(expected_backup_2_copy)
    219257
    220         return_value = jb._run_copy()
     258        return_value = cb._run_copy()
    221259        assert return_value == 0
    222260
Note: See TracChangeset for help on using the changeset viewer.