|
25 | 25 |
|
26 | 26 | from renku.core import errors |
27 | 27 | from renku.infrastructure.repository import Repository |
28 | | -from tests.utils import format_result_exception, modified_environ |
| 28 | +from tests.utils import clone_compressed_repository, format_result_exception, modified_environ |
29 | 29 |
|
30 | 30 |
|
31 | 31 | @contextlib.contextmanager |
@@ -272,6 +272,57 @@ def _parse(href): |
272 | 272 | pass |
273 | 273 |
|
274 | 274 |
|
| 275 | +@pytest.fixture |
| 276 | +def old_local_remote_project(request, svc_client, tmp_path, mock_redis, identity_headers, real_sync): |
| 277 | + """Fixture for testing service with project tarfiles containing old projects.""" |
| 278 | + from renku.domain_model import git |
| 279 | + from renku.ui.service.cache import cache as redis_cache |
| 280 | + from renku.ui.service.gateways.repository_cache import LocalRepositoryCache |
| 281 | + from renku.ui.service.serializers.headers import RequiredIdentityHeaders |
| 282 | + |
| 283 | + name = request.param |
| 284 | + remote_repo_path = tmp_path / name |
| 285 | + remote_repo = clone_compressed_repository(base_path=tmp_path, name=name) |
| 286 | + remote_repo_path = remote_repo_path / "repository" |
| 287 | + remote_repo_checkout_path = tmp_path / "remote_repo_checkout" |
| 288 | + remote_repo_checkout_path.mkdir() |
| 289 | + |
| 290 | + remote_repo_checkout = Repository.clone_from(url=remote_repo_path, path=remote_repo_checkout_path) |
| 291 | + |
| 292 | + # NOTE: Mock GitURL parsing for local URL |
| 293 | + def _parse(href): |
| 294 | + return git.GitURL(href=href, regex="", owner="dummy", name="project", slug="project", path=remote_repo_path) |
| 295 | + |
| 296 | + original_giturl_parse = git.GitURL.parse |
| 297 | + git.GitURL.parse = _parse |
| 298 | + |
| 299 | + home = tmp_path / "user_home" |
| 300 | + home.mkdir() |
| 301 | + |
| 302 | + user_data = RequiredIdentityHeaders().load(identity_headers) |
| 303 | + user = redis_cache.ensure_user(user_data) |
| 304 | + remote_url = f"file://{remote_repo_path}" |
| 305 | + |
| 306 | + project = LocalRepositoryCache().get(redis_cache, remote_url, branch=None, user=user, shallow=False) |
| 307 | + |
| 308 | + project_id = project.project_id |
| 309 | + |
| 310 | + try: |
| 311 | + yield svc_client, identity_headers, project_id, remote_repo, remote_repo_checkout, remote_url |
| 312 | + finally: |
| 313 | + git.GitURL.parse = original_giturl_parse |
| 314 | + |
| 315 | + try: |
| 316 | + shutil.rmtree(remote_repo_path) |
| 317 | + except OSError: |
| 318 | + pass |
| 319 | + |
| 320 | + try: |
| 321 | + shutil.rmtree(remote_repo_checkout_path) |
| 322 | + except OSError: |
| 323 | + pass |
| 324 | + |
| 325 | + |
275 | 326 | @pytest.fixture |
276 | 327 | def quick_cache_synchronization(mocker): |
277 | 328 | """Forces cache to synchronize on every request.""" |
|
0 commit comments