Skip to content

Commit

Permalink
Add tests for tar
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb531 committed Jan 7, 2016
1 parent 69b1c99 commit 7d04854
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions swb/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,17 @@ def back_up(wordpress_path, backup_compressor, backup_path, full_backup):

backup_path = os.path.expanduser(backup_path)
create_dir_structure(backup_path)
db_info = get_db_info(wordpress_path)

if full_backup == 'True':

# backup_path is assumed to refer to entire site directory backup
db_info = get_db_info(wordpress_path)
db_contents = dump_uncompressed_db(
db_info['name'], db_info['host'],
db_info['user'], db_info['password'])
create_full_backup(
wordpress_path, db_contents,
backup_path, backup_compressor)
verify_backup_integrity(backup_path)

else:

Expand All @@ -168,7 +167,8 @@ def back_up(wordpress_path, backup_compressor, backup_path, full_backup):
db_info['name'], db_info['host'],
db_info['user'], db_info['password'],
backup_compressor, backup_path)
verify_backup_integrity(backup_path)

verify_backup_integrity(backup_path)


# Decompress the given backup file to a database file in the same directory
Expand Down
16 changes: 14 additions & 2 deletions tests/test_remote_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import subprocess
import nose.tools as nose
import swb.remote as swb
from mock import patch
from tests.fixtures.remote import TEMP_DIR, run_back_up, run_restore
from mock import ANY, patch
from tests.fixtures.remote import TEMP_DIR, WP_PATH, run_back_up, run_restore
from tests.fixtures.remote import set_up, tear_down


Expand Down Expand Up @@ -121,3 +121,15 @@ def test_process_wait_restore():
"""should wait for each process to finish when restoring"""
run_restore(backup_path=BACKUP_PATH, full_backup=FULL_BACKUP)
nose.assert_equal(swb.subprocess.Popen.return_value.wait.call_count, 2)


@nose.with_setup(set_up, tear_down)
@patch('tarfile.open')
def test_tar(tarfile_open):
"""should wait for each process to finish when restoring"""
run_back_up(backup_path=BACKUP_PATH, full_backup=FULL_BACKUP)
tar_path = os.path.splitext(BACKUP_PATH)[0]
tarfile_open.assert_called_once_with(tar_path, 'w')
tarfile_open.return_value.add.assert_called_once_with(
WP_PATH, arcname='mysite')
tarfile_open.return_value.addfile.assert_called_once_with(ANY, ANY)

0 comments on commit 7d04854

Please sign in to comment.