Skip to content

Commit 472894a

Browse files
committed
🏗️ Enhance service release creation by adding product parameter and updating metadata inheritance tests
1 parent 35eabbb commit 472894a

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

services/catalog/tests/unit/with_dbs/test_service_access_rights.py

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,41 @@ def app_with_repo(
6868
class CreateLatetReleaseCallable(Protocol):
6969
"""Callable to create a latest release with specified metadata fields."""
7070

71-
async def __call__(self, metadata_fields: dict[str, Any]) -> dict[str, Any]: ...
71+
async def __call__(
72+
self, metadata_fields: dict[str, Any], product: ProductName
73+
) -> dict[str, Any]: ...
7274

7375

7476
@pytest.fixture
7577
def create_latest_release(
7678
create_fake_service_data: CreateFakeServiceDataCallable,
7779
new_service_metadata_published: ServiceMetaDataPublished,
78-
target_product: ProductName,
7980
services_db_tables_injector: Callable,
8081
) -> CreateLatetReleaseCallable:
81-
"""Creates a latest release with specified metadata fields."""
82+
"""Creates a latest release with specified metadata fields for a product.
83+
84+
Args:
85+
metadata_fields: Dictionary of metadata fields to set
86+
product: Product to create the service for
87+
88+
Returns:
89+
The created service metadata
90+
"""
8291

8392
from packaging.version import Version
8493

8594
new_version = Version(new_service_metadata_published.version)
8695

87-
async def _create(metadata_fields: dict[str, Any]) -> dict[str, Any]:
96+
async def _create(
97+
metadata_fields: dict[str, Any], product: ProductName
98+
) -> dict[str, Any]:
8899
latest_release_service, *latest_release_service_access_rights = (
89100
create_fake_service_data(
90101
new_service_metadata_published.key,
91102
f"{new_version.major}.{new_version.minor}.{new_version.micro-1}",
92103
team_access="x",
93104
everyone_access=None,
94-
product=target_product,
105+
product=product,
95106
)
96107
)
97108

@@ -165,6 +176,7 @@ async def test_metadata_inheritance_variations(
165176
new_service_metadata_published: ServiceMetaDataPublished,
166177
app_with_repo: tuple[FastAPI, ServicesRepository],
167178
create_latest_release: CreateLatetReleaseCallable,
179+
target_product: ProductName,
168180
):
169181
"""Test different variations of metadata inheritance with complete previous release."""
170182
app, services_repo = app_with_repo
@@ -174,7 +186,8 @@ async def test_metadata_inheritance_variations(
174186
{
175187
"icon": "https://foo/previous_icon.svg",
176188
"thumbnail": "https://foo/previous_thumbnail.jpg",
177-
}
189+
},
190+
target_product,
178191
)
179192

180193
# Case 1: All fields missing in new service - only icon and thumbnail should be inherited
@@ -228,6 +241,7 @@ async def test_metadata_inheritance_with_incomplete_previous_release(
228241
new_service_metadata_published: ServiceMetaDataPublished,
229242
app_with_repo: tuple[FastAPI, ServicesRepository],
230243
create_latest_release: CreateLatetReleaseCallable,
244+
target_product: ProductName,
231245
):
232246
"""Test metadata inheritance when previous release has incomplete metadata fields."""
233247
app, services_repo = app_with_repo
@@ -237,7 +251,8 @@ async def test_metadata_inheritance_with_incomplete_previous_release(
237251
{
238252
"icon": "https://foo/previous_icon.svg",
239253
"thumbnail": "https://foo/previous_thumbnail.jpg",
240-
}
254+
},
255+
target_product,
241256
)
242257

243258
new_service = new_service_metadata_published.model_copy(deep=True)
@@ -278,7 +293,8 @@ async def test_service_upgrade_metadata_inheritance_old_service(
278293
"icon": "https://foo/previous_icon.svg",
279294
"description": "Previous description", # This won't be inherited
280295
"thumbnail": "https://foo/previous_thumbnail.jpg",
281-
}
296+
},
297+
target_product,
282298
)
283299

284300
# DEFAULT policies for old service
@@ -330,6 +346,7 @@ async def test_service_upgrade_metadata_inheritance_new_service_multi_product(
330346
mocker: MockerFixture,
331347
new_service_metadata_published: ServiceMetaDataPublished,
332348
app_with_repo: tuple[FastAPI, ServicesRepository],
349+
create_latest_release: CreateLatetReleaseCallable,
333350
):
334351
"""Test inheritance behavior when the service is new and latest version exists in multiple products"""
335352
everyone_gid, user_gid, team_gid = user_groups_ids
@@ -342,37 +359,21 @@ async def test_service_upgrade_metadata_inheritance_new_service_multi_product(
342359
return_value=False,
343360
)
344361

345-
# Create latest-release service
346-
latest_release_service, *latest_release_service_access_rights = (
347-
create_fake_service_data(
348-
new_service_metadata_published.key,
349-
"1.0.10",
350-
team_access="x",
351-
everyone_access=None,
352-
product=target_product,
353-
)
354-
)
362+
# Create latest-release service with metadata for target product
363+
metadata_fields = {
364+
"icon": "https://foo/previous_icon.svg",
365+
"thumbnail": "https://foo/previous_thumbnail.jpg",
366+
}
355367

356-
latest_release_service["icon"] = "https://foo/previous_icon.svg"
357-
latest_release = (latest_release_service, *latest_release_service_access_rights)
358-
359-
# latest-release in other product
360-
_, *latest_release_service_access_rights_in_other_product = (
361-
create_fake_service_data(
362-
new_service_metadata_published.key,
363-
latest_release_service["version"],
364-
team_access="x",
365-
everyone_access=None,
366-
product=other_product, # <-- different product
367-
)
368+
# Create in target product
369+
latest_release_service = await create_latest_release(
370+
metadata_fields, target_product
368371
)
369372

370-
latest_release_in_other_product = (
371-
latest_release_service,
372-
*latest_release_service_access_rights_in_other_product, # <-- different product
373-
)
373+
# Create in other product
374+
await create_latest_release(metadata_fields, other_product)
374375

375-
# Setup multiple versions in database
376+
# Create older versions in target product to test proper version ordering
376377
await services_db_tables_injector(
377378
[
378379
create_fake_service_data(
@@ -389,8 +390,6 @@ async def test_service_upgrade_metadata_inheritance_new_service_multi_product(
389390
everyone_access=None,
390391
product=target_product,
391392
),
392-
latest_release,
393-
latest_release_in_other_product,
394393
]
395394
)
396395

@@ -431,6 +430,8 @@ async def test_service_upgrade_metadata_inheritance_new_service_multi_product(
431430
inherited_metadata = inherited_data["metadata_updates"]
432431
assert "icon" in inherited_metadata
433432
assert inherited_metadata["icon"] == latest_release_service["icon"]
433+
assert "thumbnail" in inherited_metadata
434+
assert inherited_metadata["thumbnail"] == latest_release_service["thumbnail"]
434435

435436
# ALL
436437
service_access_rights += inherited_access_rights

0 commit comments

Comments
 (0)