Skip to content

Commit f442d2d

Browse files
committed
improve delta pattern tests
1 parent 8243abe commit f442d2d

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

sde_collections/tests/test_delta_patterns.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -325,29 +325,35 @@ def test_unapply_removes_pattern_relationships(self):
325325
assert not pattern.delta_urls.filter(pk=delta_url.pk).exists()
326326
assert not pattern.curated_urls.filter(pk=curated_url.pk).exists()
327327

328-
# TODO: work on this test logic
329-
# def test_pattern_reapplication_does_not_duplicate_delta_urls(self):
330-
# """
331-
# Ensures that reapplying a pattern does not create duplicate `DeltaUrls` or affect existing `CuratedUrls`.
332-
# """
333-
# collection = CollectionFactory()
334-
# delta_url = DeltaUrlFactory(collection=collection,
335-
# url="https://example.com/page",
336-
# scraped_title="Title Before")
337-
338-
# # Promote to CuratedUrl
339-
# collection.promote_to_curated()
340-
# curated_url = CuratedUrl.objects.get(url=delta_url.url)
341-
342-
# # Apply a pattern
343-
# pattern = DeltaTitlePattern.objects.create(
344-
# collection=collection, match_pattern="https://example.com/*", match_pattern_type=2, title_patte......
345-
# )
346-
# pattern.apply()
347-
348-
# # Ensure no new `DeltaUrl` is created after reapplying the pattern
349-
# pattern.apply()
350-
# assert DeltaUrl.objects.filter(url=curated_url.url).count() == 0
328+
def test_pattern_reapplication_does_not_duplicate_delta_urls(self):
329+
"""
330+
Ensures that reapplying a pattern does not create duplicate `DeltaUrls` or affect existing `CuratedUrls`.
331+
"""
332+
collection = CollectionFactory()
333+
delta_url = DeltaUrlFactory(collection=collection, url="https://example.com/page", scraped_title="Title Before")
334+
335+
# Apply a pattern
336+
pattern = DeltaTitlePattern.objects.create(
337+
collection=collection,
338+
match_pattern="https://example.com/*",
339+
match_pattern_type=2,
340+
title_pattern="{title} - Processed",
341+
)
342+
343+
delta_url.refresh_from_db()
344+
delta_url.generated_title = "Title Before - Processed"
345+
346+
# Promote to CuratedUrl
347+
collection.promote_to_curated()
348+
curated_url = CuratedUrl.objects.get(url=delta_url.url)
349+
350+
# Ensure no new `DeltaUrl` is created after reapplying the pattern
351+
pattern.apply()
352+
assert DeltaUrl.objects.filter(url=curated_url.url).count() == 0
353+
354+
# Ensure no new `DeltaUrl` is created after reapplying the pattern
355+
pattern.apply()
356+
assert DeltaUrl.objects.filter(url=curated_url.url).count() == 0
351357

352358

353359
@pytest.mark.django_db

0 commit comments

Comments
 (0)