def test_fetch_file(self): remote_dep = _make_dep(location='remote') local_dep = _make_dep(location='local') project_dep = _make_dep(location='project') p1 = Path('path1') p2 = Path('path2') p3 = Path('path3') context = DependencyContext([], Language({}, 'lang'), Configuration({}, [], None)) context._handle_remote_resolution = MagicMock(return_value=p1) context._handle_local_resolution = MagicMock(return_value=p2) context._handle_project_resolution = MagicMock(return_value=p3) r1 = context._fetch_file(remote_dep, 'remote.name') r2 = context._fetch_file(local_dep, 'local.name') r3 = context._fetch_file(project_dep, 'project.name') context._handle_remote_resolution.assert_called_once_with( 'remote.name') context._handle_local_resolution.assert_called_once_with('local.name') context._handle_project_resolution.assert_called_once_with( 'dep', 'project.name') assert r1 is p1 assert r2 is p2 assert r3 is p3
def test_handle_remote_resolution(self): name = 'file.txt' parent_url = 'http://server/path/to' url = parent_url + '/' + name parent_path = Path('path/to') file = parent_path / name return_value = Path('/resolved/path/to/' + name) context = DependencyContext([], Language({}, 'lang'), Configuration({}, [], None)) resolver = RemoteResolver(parent_url, parent_path) resolver._resolve_remotely = MagicMock(return_value=return_value) context.set_remote_resolver(resolver) rv = context._handle_remote_resolution(name) resolver._resolve_remotely.assert_called_once_with(url, file) assert rv is return_value