@@ -325,29 +325,35 @@ def test_unapply_removes_pattern_relationships(self):
325
325
assert not pattern .delta_urls .filter (pk = delta_url .pk ).exists ()
326
326
assert not pattern .curated_urls .filter (pk = curated_url .pk ).exists ()
327
327
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
351
357
352
358
353
359
@pytest .mark .django_db
0 commit comments