|
1 | 1 | """Tests for the repository.""" |
2 | 2 |
|
| 3 | +import uuid |
3 | 4 | from datetime import datetime |
4 | 5 |
|
5 | 6 | import pytest |
6 | 7 | from ulid import ULID |
7 | 8 |
|
8 | 9 | from renku_data_services.authz.models import Visibility |
9 | | -from renku_data_services.base_models.core import NamespacePath, NamespaceSlug, ProjectPath, ProjectSlug |
10 | | -from renku_data_services.data_connectors.models import CloudStorageCore, DataConnector |
| 10 | +from renku_data_services.base_models.core import ( |
| 11 | + AuthenticatedAPIUser, |
| 12 | + NamespacePath, |
| 13 | + NamespaceSlug, |
| 14 | + ProjectPath, |
| 15 | + ProjectSlug, |
| 16 | +) |
| 17 | +from renku_data_services.data_api.dependencies import DependencyManager |
| 18 | +from renku_data_services.data_connectors.models import CloudStorageCore, DataConnector, UnsavedDataConnector |
11 | 19 | from renku_data_services.migrations.core import run_migrations_for_app |
12 | | -from renku_data_services.namespace.models import ProjectNamespace, UserNamespace |
| 20 | +from renku_data_services.namespace.models import ProjectNamespace, UnsavedGroup, UserNamespace |
| 21 | +from renku_data_services.project.models import UnsavedProject |
13 | 22 | from renku_data_services.search.db import SearchUpdatesRepo |
14 | 23 | from renku_data_services.search.models import DeleteDoc |
15 | 24 | from renku_data_services.solr.entity_documents import DataConnector as DataConnectorDoc |
|
30 | 39 | ) |
31 | 40 |
|
32 | 41 |
|
| 42 | +@pytest.mark.asyncio |
| 43 | +async def test_dc_in_group_project(app_manager_instance: DependencyManager) -> None: |
| 44 | + run_migrations_for_app("common") |
| 45 | + |
| 46 | + user_repo = app_manager_instance.kc_user_repo |
| 47 | + group_repo = app_manager_instance.group_repo |
| 48 | + proj_repo = app_manager_instance.project_repo |
| 49 | + dc_repo = app_manager_instance.data_connector_repo |
| 50 | + repo = SearchUpdatesRepo(app_manager_instance.config.db.async_session_maker) |
| 51 | + |
| 52 | + user = AuthenticatedAPIUser(id=str(uuid.uuid4()), access_token="abc", first_name="Huhu") |
| 53 | + u = await user_repo.get_or_create_user(user, user.id) |
| 54 | + assert u |
| 55 | + |
| 56 | + group = await group_repo.insert_group(user, UnsavedGroup(slug="grr1", name="Group Grr")) |
| 57 | + |
| 58 | + proj1 = await proj_repo.insert_project( |
| 59 | + user, |
| 60 | + UnsavedProject( |
| 61 | + namespace=group.slug, |
| 62 | + name=f"proj of group {group.name}", |
| 63 | + slug="proj-group-1", |
| 64 | + visibility=Visibility.PUBLIC, |
| 65 | + created_by=user.id, |
| 66 | + ), |
| 67 | + ) |
| 68 | + dc_in_proj = await dc_repo.insert_namespaced_data_connector( |
| 69 | + user, |
| 70 | + UnsavedDataConnector( |
| 71 | + name="dc in group project", |
| 72 | + slug="dc2", |
| 73 | + visibility=Visibility.PUBLIC, |
| 74 | + created_by=user.id, |
| 75 | + namespace=proj1.path, |
| 76 | + storage=CloudStorageCore( |
| 77 | + storage_type="csc", configuration={}, source_path="", target_path="", readonly=True |
| 78 | + ), |
| 79 | + ), |
| 80 | + ) |
| 81 | + dc_in_group = await dc_repo.insert_namespaced_data_connector( |
| 82 | + user, |
| 83 | + UnsavedDataConnector( |
| 84 | + name="dc in group", |
| 85 | + slug="dc1", |
| 86 | + visibility=Visibility.PUBLIC, |
| 87 | + created_by=user.id, |
| 88 | + namespace=group.path, |
| 89 | + storage=CloudStorageCore( |
| 90 | + storage_type="csc", configuration={}, source_path="", target_path="", readonly=True |
| 91 | + ), |
| 92 | + ), |
| 93 | + ) |
| 94 | + |
| 95 | + updates = await repo.select_next(10) |
| 96 | + assert len(updates) == 5 |
| 97 | + e1 = next(e for e in updates if e.entity_type == "User") |
| 98 | + assert e1.entity_id == user.id |
| 99 | + e2 = next(e for e in updates if e.entity_type == "Project") |
| 100 | + assert e2.entity_id == proj1.id |
| 101 | + e3 = next(e for e in updates if e.entity_type == "Group") |
| 102 | + assert e3.entity_id == group.id |
| 103 | + e45 = {e.entity_id for e in updates if e.entity_type == "DataConnector"} |
| 104 | + assert e45 == {str(dc_in_proj.id), str(dc_in_group.id)} |
| 105 | + |
| 106 | + |
33 | 107 | @pytest.mark.asyncio |
34 | 108 | async def test_data_connector_within_project(app_manager_instance): |
35 | 109 | run_migrations_for_app("common") |
|
0 commit comments