Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/svn/tests/test_loader.py
Show First 20 Lines • Show All 1,002 Lines • ▼ Show 20 Lines | for change in changes: | ||||
if "data" in change: | if "data" in change: | ||||
txdelta = file.apply_textdelta() | txdelta = file.apply_textdelta() | ||||
delta.send_stream(BytesIO(change["data"]), txdelta) | delta.send_stream(BytesIO(change["data"]), txdelta) | ||||
file.close() | file.close() | ||||
root.close() | root.close() | ||||
editor.close() | editor.close() | ||||
def create_repo(tmp_path): | def create_repo(tmp_path, repo_name="tmprepo"): | ||||
repo_path = os.path.join(tmp_path, "tmprepo") | repo_path = os.path.join(tmp_path, repo_name) | ||||
repos.create(repo_path) | repos.create(repo_path) | ||||
repo_url = f"file://{repo_path}" | repo_url = f"file://{repo_path}" | ||||
return repo_url | return repo_url | ||||
@pytest.fixture | @pytest.fixture | ||||
def repo_url(tmpdir_factory): | def repo_url(tmpdir_factory): | ||||
# create a repository | # create a repository | ||||
▲ Show 20 Lines • Show All 861 Lines • ▼ Show 20 Lines | ): | ||||
# first commit | # first commit | ||||
add_commit( | add_commit( | ||||
repo_url, | repo_url, | ||||
"Create repository structure.", | "Create repository structure.", | ||||
[ | [ | ||||
CommitChange(change_type=CommitChangeType.AddOrUpdate, path="branches/",), | CommitChange(change_type=CommitChangeType.AddOrUpdate, path="branches/",), | ||||
CommitChange(change_type=CommitChangeType.AddOrUpdate, path="tags/",), | CommitChange(change_type=CommitChangeType.AddOrUpdate, path="tags/",), | ||||
CommitChange(change_type=CommitChangeType.AddOrUpdate, path="trunk/",), | CommitChange(change_type=CommitChangeType.AddOrUpdate, path="trunk/",), | ||||
CommitChange( | |||||
change_type=CommitChangeType.AddOrUpdate, | |||||
path="trunk/bar.sh", | |||||
properties={"svn:executable": "*"}, | |||||
data=b"#!/bin/bash\necho bar", | |||||
), | |||||
], | ], | ||||
) | ) | ||||
# second commit | # second commit | ||||
add_commit( | add_commit( | ||||
repo_url, | repo_url, | ||||
( | ( | ||||
"Set svn:externals property on trunk/externals path of repository to load." | "Set svn:externals property on trunk/externals path of repository to load." | ||||
"One external targets a remote directory and another one a remote file." | "One external targets a remote directory and another one a remote file." | ||||
), | ), | ||||
[ | [ | ||||
CommitChange( | CommitChange( | ||||
change_type=CommitChangeType.AddOrUpdate, | change_type=CommitChangeType.AddOrUpdate, | ||||
path="trunk/externals/", | path="trunk/externals/", | ||||
properties={ | properties={ | ||||
"svn:externals": ( | "svn:externals": ( | ||||
f"{svn_urljoin(external_repo_url, 'code/hello')} hello\n" | f"{svn_urljoin(external_repo_url, 'code/hello')} hello\n" | ||||
f"{svn_urljoin(external_repo_url, 'foo.sh')} foo.sh" | f"{svn_urljoin(external_repo_url, 'foo.sh')} foo.sh\n" | ||||
f"{svn_urljoin(repo_url, 'trunk/bar.sh')} bar.sh" | |||||
) | ) | ||||
}, | }, | ||||
), | ), | ||||
], | ], | ||||
) | ) | ||||
# first load | # first load | ||||
loader = SvnLoader(swh_storage, repo_url, temp_directory=tmp_path, check_revision=1) | loader = SvnLoader(swh_storage, repo_url, temp_directory=tmp_path, check_revision=1) | ||||
▲ Show 20 Lines • Show All 1,032 Lines • ▼ Show 20 Lines | ): | ||||
loader = SvnLoader( | loader = SvnLoader( | ||||
swh_storage, repo_url, temp_directory=tmp_path, check_revision=1, | swh_storage, repo_url, temp_directory=tmp_path, check_revision=1, | ||||
) | ) | ||||
assert loader.load() == {"status": "eventful"} | assert loader.load() == {"status": "eventful"} | ||||
assert_last_visit_matches( | assert_last_visit_matches( | ||||
loader.storage, repo_url, status="full", type="svn", | loader.storage, repo_url, status="full", type="svn", | ||||
) | ) | ||||
check_snapshot(loader.snapshot, loader.storage) | check_snapshot(loader.snapshot, loader.storage) | ||||
def test_dump_loader_externals_in_loaded_repository(swh_storage, tmp_path, mocker): | |||||
repo_url = create_repo(tmp_path, repo_name="foo") | |||||
externa_url = create_repo(tmp_path, repo_name="foobar") | |||||
# first commit on external | |||||
add_commit( | |||||
externa_url, | |||||
"Create a file in an external repository", | |||||
[ | |||||
CommitChange( | |||||
change_type=CommitChangeType.AddOrUpdate, | |||||
path="trunk/src/foo.sh", | |||||
data=b"#!/bin/bash\necho foo", | |||||
), | |||||
], | |||||
) | |||||
add_commit( | |||||
repo_url, | |||||
( | |||||
"Add a file and set externals on trunk/externals:" | |||||
"one external located in this repository, the other in a remote one" | |||||
), | |||||
[ | |||||
CommitChange( | |||||
change_type=CommitChangeType.AddOrUpdate, | |||||
path="trunk/src/bar.sh", | |||||
data=b"#!/bin/bash\necho bar", | |||||
), | |||||
CommitChange( | |||||
change_type=CommitChangeType.AddOrUpdate, | |||||
path="trunk/externals/", | |||||
properties={ | |||||
"svn:externals": ( | |||||
f"{svn_urljoin(repo_url, 'trunk/src/bar.sh')} bar.sh\n" | |||||
f"{svn_urljoin(externa_url, 'trunk/src/foo.sh')} foo.sh" | |||||
) | |||||
}, | |||||
), | |||||
], | |||||
) | |||||
from swh.loader.svn.svn import client | |||||
mock_client = mocker.MagicMock() | |||||
mocker.patch.object(client, "Client", mock_client) | |||||
loader = SvnLoaderFromRemoteDump(swh_storage, repo_url, temp_directory=tmp_path) | |||||
loader.load() | |||||
export_call_args = mock_client().export.call_args_list | |||||
# first external export should use the base URL of the local repository | |||||
# mounted from the remote dump as it is located in loaded repository | |||||
assert export_call_args[0][0][0] != svn_urljoin( | |||||
loader.svnrepo.origin_url, "trunk/src/bar.sh" | |||||
) | |||||
assert export_call_args[0][0][0] == svn_urljoin( | |||||
loader.svnrepo.remote_url, "trunk/src/bar.sh" | |||||
) | |||||
# second external export should use the remote URL of the external repository | |||||
assert export_call_args[1][0][0] == svn_urljoin(externa_url, "trunk/src/foo.sh") |