Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/svn/tests/test_utils.py
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
def test_init_svn_repo_from_dump(datadir, tmp_path): | def test_init_svn_repo_from_dump(datadir, tmp_path): | ||||
"""Mounting svn repository out of a dump is ok""" | """Mounting svn repository out of a dump is ok""" | ||||
dump_name = "penguinsdbtools2018.dump.gz" | dump_name = "penguinsdbtools2018.dump.gz" | ||||
dump_path = os.path.join(datadir, dump_name) | dump_path = os.path.join(datadir, dump_name) | ||||
tmp_repo, repo_path = utils.init_svn_repo_from_dump( | tmp_repo, repo_path = utils.init_svn_repo_from_dump( | ||||
dump_path, gzip=True, cleanup_dump=False | dump_path, gzip=True, cleanup_dump=False, root_dir=tmp_path | ||||
) | ) | ||||
assert os.path.exists(dump_path), "Dump path should still exists" | assert os.path.exists(dump_path), "Dump path should still exists" | ||||
assert os.path.exists(repo_path), "Repository should exists" | assert os.path.exists(repo_path), "Repository should exists" | ||||
def test_init_svn_repo_from_dump_and_cleanup(datadir, tmp_path): | def test_init_svn_repo_from_dump_and_cleanup(datadir, tmp_path): | ||||
"""Mounting svn repository with a dump cleanup after is ok""" | """Mounting svn repository with a dump cleanup after is ok""" | ||||
dump_name = "penguinsdbtools2018.dump.gz" | dump_name = "penguinsdbtools2018.dump.gz" | ||||
dump_ori_path = os.path.join(datadir, dump_name) | dump_ori_path = os.path.join(datadir, dump_name) | ||||
dump_path = os.path.join(tmp_path, dump_name) | dump_path = os.path.join(tmp_path, dump_name) | ||||
shutil.copyfile(dump_ori_path, dump_path) | shutil.copyfile(dump_ori_path, dump_path) | ||||
assert os.path.exists(dump_path) | assert os.path.exists(dump_path) | ||||
assert os.path.exists(dump_ori_path) | assert os.path.exists(dump_ori_path) | ||||
tmp_repo, repo_path = utils.init_svn_repo_from_dump(dump_path, gzip=True) | tmp_repo, repo_path = utils.init_svn_repo_from_dump( | ||||
dump_path, gzip=True, root_dir=tmp_path | |||||
) | |||||
assert not os.path.exists(dump_path), "Dump path should no longer exists" | assert not os.path.exists(dump_path), "Dump path should no longer exists" | ||||
assert os.path.exists(repo_path), "Repository should exists" | assert os.path.exists(repo_path), "Repository should exists" | ||||
assert os.path.exists(dump_ori_path), "Original dump path should still exists" | assert os.path.exists(dump_ori_path), "Original dump path should still exists" | ||||
def test_init_svn_repo_from_dump_and_cleanup_already_done( | def test_init_svn_repo_from_dump_and_cleanup_already_done( | ||||
datadir, tmp_path, mocker, caplog | datadir, tmp_path, mocker, caplog | ||||
): | ): | ||||
"""Mounting svn repository out of a dump is ok""" | """Mounting svn repository out of a dump is ok""" | ||||
caplog.set_level(logging.INFO, "swh.loader.svn.utils") | caplog.set_level(logging.INFO, "swh.loader.svn.utils") | ||||
dump_name = "penguinsdbtools2018.dump.gz" | dump_name = "penguinsdbtools2018.dump.gz" | ||||
dump_ori_path = os.path.join(datadir, dump_name) | dump_ori_path = os.path.join(datadir, dump_name) | ||||
mock_remove = mocker.patch("os.remove") | mock_remove = mocker.patch("os.remove") | ||||
mock_remove.side_effect = FileNotFoundError | mock_remove.side_effect = FileNotFoundError | ||||
dump_path = os.path.join(tmp_path, dump_name) | dump_path = os.path.join(tmp_path, dump_name) | ||||
shutil.copyfile(dump_ori_path, dump_path) | shutil.copyfile(dump_ori_path, dump_path) | ||||
assert os.path.exists(dump_path) | assert os.path.exists(dump_path) | ||||
assert os.path.exists(dump_ori_path) | assert os.path.exists(dump_ori_path) | ||||
tmp_repo, repo_path = utils.init_svn_repo_from_dump(dump_path, gzip=True) | tmp_repo, repo_path = utils.init_svn_repo_from_dump( | ||||
dump_path, gzip=True, root_dir=tmp_path | |||||
) | |||||
assert os.path.exists(repo_path), "Repository should exists" | assert os.path.exists(repo_path), "Repository should exists" | ||||
assert os.path.exists(dump_ori_path), "Original dump path should still exists" | assert os.path.exists(dump_ori_path), "Original dump path should still exists" | ||||
assert len(caplog.record_tuples) == 1 | assert len(caplog.record_tuples) == 1 | ||||
assert "Failure to remove" in caplog.record_tuples[0][2] | assert "Failure to remove" in caplog.record_tuples[0][2] | ||||
assert mock_remove.called | assert mock_remove.called | ||||
def test_init_svn_repo_from_archive_dump(datadir, tmp_path): | def test_init_svn_repo_from_archive_dump(datadir, tmp_path): | ||||
"""Mounting svn repository out of an archive dump is ok""" | """Mounting svn repository out of an archive dump is ok""" | ||||
dump_name = "penguinsdbtools2018.dump.gz" | dump_name = "penguinsdbtools2018.dump.gz" | ||||
dump_path = os.path.join(datadir, dump_name) | dump_path = os.path.join(datadir, dump_name) | ||||
tmp_repo, repo_path = utils.init_svn_repo_from_archive_dump( | tmp_repo, repo_path = utils.init_svn_repo_from_archive_dump( | ||||
dump_path, cleanup_dump=False | dump_path, cleanup_dump=False, root_dir=tmp_path | ||||
) | ) | ||||
assert os.path.exists(dump_path), "Dump path should still exists" | assert os.path.exists(dump_path), "Dump path should still exists" | ||||
assert os.path.exists(repo_path), "Repository should exists" | assert os.path.exists(repo_path), "Repository should exists" | ||||
def test_init_svn_repo_from_archive_dump_and_cleanup(datadir, tmp_path): | def test_init_svn_repo_from_archive_dump_and_cleanup(datadir, tmp_path): | ||||
"""Mounting svn repository out of a dump is ok""" | """Mounting svn repository out of a dump is ok""" | ||||
dump_name = "penguinsdbtools2018.dump.gz" | dump_name = "penguinsdbtools2018.dump.gz" | ||||
dump_ori_path = os.path.join(datadir, dump_name) | dump_ori_path = os.path.join(datadir, dump_name) | ||||
dump_path = os.path.join(tmp_path, dump_name) | dump_path = os.path.join(tmp_path, dump_name) | ||||
shutil.copyfile(dump_ori_path, dump_path) | shutil.copyfile(dump_ori_path, dump_path) | ||||
assert os.path.exists(dump_path) | assert os.path.exists(dump_path) | ||||
assert os.path.exists(dump_ori_path) | assert os.path.exists(dump_ori_path) | ||||
tmp_repo, repo_path = utils.init_svn_repo_from_archive_dump(dump_path) | tmp_repo, repo_path = utils.init_svn_repo_from_archive_dump( | ||||
dump_path, root_dir=tmp_path | |||||
) | |||||
assert not os.path.exists(dump_path), "Dump path should no longer exists" | assert not os.path.exists(dump_path), "Dump path should no longer exists" | ||||
assert os.path.exists(repo_path), "Repository should exists" | assert os.path.exists(repo_path), "Repository should exists" | ||||
assert os.path.exists(dump_ori_path), "Original dump path should still exists" | assert os.path.exists(dump_ori_path), "Original dump path should still exists" |