IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 9, 2019, 11:25:06 AM (7 years ago)
Author:
fairlamb
Message:

added mysqldump to the backup class + tests; tests are skipped as they require some mysql setup

File:
1 edited

Legend:

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

    r40924 r40931  
    294294        assert not os.path.exists(expected_tar2)
    295295        backy._run_tar()
    296         print(expected_tar1)
    297         print(expected_tar2)
    298296        assert os.path.exists(expected_tar1)
    299297        assert os.path.exists(expected_tar2)
     
    309307
    310308
    311 # class TestRunningMysqldump():
    312 
    313 #     def test_simply_mysqldump(self):
    314 #         assert True is False
    315 
    316 #     def test_mysqldump_with_additional_args(self):
    317 #         assert True is False
     309@pytest.mark.skip(reason="Requires a fake database to be setup")
     310class TestMysqlBackup(object):
     311    """ The mySQL dump tests require the machine on which they are
     312running to have a mysql database running with a user called
     313'dumper' and a password set to 'not_a_real_password'.
     314
     315In production, a proper password should be set on the server and in the config
     316file. DO NOT USE THE ABOVE IN PRODUCTION
     317
     318To change the password:
     319UPDATE mysql.user SET authentication_string = PASSWORD('NEW_USER_PASSWORD')WHERE User = 'user-name' AND Host = 'localhost';FLUSH PRIVILEGES;
     320"""
     321
     322    dumper_password = "not_a_real_password"
     323
     324    def test_mysql_dump_is_ok(self, tmpdir):
     325        config = make_default_config(tmpdir, ['bck1', 'bck2'])
     326        config['MYSQLDUMP'] = \
     327        { 'user' : 'dumper'
     328        , 'password' : 'not_a_real_password'
     329        , 'db_name' : 'jiradb'
     330        , 'target_filename' : "cool_dump.sql"
     331        , 'prefix_date' : True
     332        }
     333
     334        backy = Backup(config)
     335
     336        date = bckup.get_date()
     337
     338        expected_dump1 = os.path.join(tmpdir, 'bck1', f'{date}_cool_dump.sql')
     339        expected_dump2 = os.path.join(tmpdir, 'bck2', f'{date}_cool_dump.sql')
     340        assert not os.path.exists(expected_dump1)
     341        assert not os.path.exists(expected_dump2)
     342        backy._run_mysqldump()
     343        assert os.path.exists(expected_dump1)
     344        assert os.path.exists(expected_dump2)
     345
     346    def test_mysql_dump_fails_with_incorrect_password(self, tmpdir):
     347        config = make_default_config(tmpdir, ['bck1', 'bck2'])
     348        config['MYSQLDUMP'] = \
     349        { 'user' : 'dumper'
     350        , 'password' : 'incorrect_password'
     351        , 'db_name' : 'jiradb'
     352        , 'target_filename' : "cool_dump.sql"
     353        , 'prefix_date' : True
     354        }
     355
     356        backy = Backup(config)
     357        with pytest.raises(errs.SubprocessError):
     358            backy._run_mysqldump()
Note: See TracChangeset for help on using the changeset viewer.