Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Panaetius committed Jan 22, 2024
1 parent 2277181 commit d606e98
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 1 deletion.
21 changes: 21 additions & 0 deletions tests/cli/test_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ def test_migrate_project(isolated_runner, old_project, with_injection):
assert project_context.project.name


@pytest.mark.migration
@pytest.mark.parametrize(
"old_project",
[
"v9-migration-docker-version-change.git",
"v9-migration-docker-mult-changes.git",
],
indirect=["old_project"],
)
def test_migrate_old_project_with_docker_change(isolated_runner, old_project, with_injection):
"""Test migrating projects with changes to the Dockerfile."""
result = isolated_runner.invoke(cli, ["migrate", "--strict"])
assert 0 == result.exit_code, format_result_exception(result)
assert not old_project.repository.is_dirty()
assert "Updated dockerfile" in result.output

with project_context.with_path(old_project.path), with_injection():
assert project_context.project
assert project_context.project.name


@pytest.mark.migration
@pytest.mark.serial
def test_migration_check(isolated_runner, project):
Expand Down
Binary file not shown.
Binary file not shown.
53 changes: 52 additions & 1 deletion tests/service/fixtures/service_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from renku.core import errors
from renku.infrastructure.repository import Repository
from tests.utils import format_result_exception, modified_environ
from tests.utils import clone_compressed_repository, format_result_exception, modified_environ


@contextlib.contextmanager
Expand Down Expand Up @@ -272,6 +272,57 @@ def _parse(href):
pass


@pytest.fixture
def old_local_remote_project(request, svc_client, tmp_path, mock_redis, identity_headers, real_sync):
"""Fixture for testing service with project tarfiles containing old projects."""
from renku.domain_model import git
from renku.ui.service.cache import cache as redis_cache
from renku.ui.service.gateways.repository_cache import LocalRepositoryCache
from renku.ui.service.serializers.headers import RequiredIdentityHeaders

name = request.param
remote_repo_path = tmp_path / name
remote_repo = clone_compressed_repository(base_path=tmp_path, name=name)
remote_repo_path = remote_repo_path / "repository"
remote_repo_checkout_path = tmp_path / "remote_repo_checkout"
remote_repo_checkout_path.mkdir()

remote_repo_checkout = Repository.clone_from(url=remote_repo_path, path=remote_repo_checkout_path)

# NOTE: Mock GitURL parsing for local URL
def _parse(href):
return git.GitURL(href=href, regex="", owner="dummy", name="project", slug="project", path=remote_repo_path)

original_giturl_parse = git.GitURL.parse
git.GitURL.parse = _parse

home = tmp_path / "user_home"
home.mkdir()

user_data = RequiredIdentityHeaders().load(identity_headers)
user = redis_cache.ensure_user(user_data)
remote_url = f"file://{remote_repo_path}"

project = LocalRepositoryCache().get(redis_cache, remote_url, branch=None, user=user, shallow=False)

project_id = project.project_id

try:
yield svc_client, identity_headers, project_id, remote_repo, remote_repo_checkout, remote_url
finally:
git.GitURL.parse = original_giturl_parse

try:
shutil.rmtree(remote_repo_path)
except OSError:
pass

try:
shutil.rmtree(remote_repo_checkout_path)
except OSError:
pass


@pytest.fixture
def quick_cache_synchronization(mocker):
"""Forces cache to synchronize on every request."""
Expand Down
19 changes: 19 additions & 0 deletions tests/service/views/test_cache_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,25 @@ def test_execute_migrations(svc_client_setup):
assert not response.json["result"]["errors"]


@pytest.mark.service
@pytest.mark.parametrize(
"old_local_remote_project",
[
"v9-migration-docker-version-change.git",
"v9-migration-docker-mult-changes.git",
],
indirect=["old_local_remote_project"],
)
def test_migrate_old_project(old_local_remote_project):
"""Test migrating old projects with docker file changes."""
svc_client, identity_headers, project_id, remote_repo, remote_repo_checkout, remote_url = old_local_remote_project

response = svc_client.post("/cache.migrate", data=json.dumps(dict(git_url=remote_url)), headers=identity_headers)
assert response
assert 200 == response.status_code
assert response.json.get("result", {}).get("docker_migrated", False)


@pytest.mark.service
@pytest.mark.integration
def test_execute_migrations_job(svc_client_setup):
Expand Down

0 comments on commit d606e98

Please sign in to comment.