fix test: patch _torrent_backfill_async directly, not generate_torrent_async

This commit is contained in:
russell@unturf.com 2026-04-07 10:47:33 -04:00
parent 932a0dde6e
commit 0203172dcd

View file

@ -5036,18 +5036,17 @@ class TestTorrentSettings(_AuthenticatedBase):
self.assertIn(".torrent", res.text)
def test_enable_torrent_triggers_backfill_for_products_with_files(self):
"""Enabling torrent fires generate_torrent_async for products that have a
product file but no magnet link yet."""
"""Enabling torrent calls _torrent_backfill_async to seed existing products."""
import mock
shop = self._create_shop_helper()
product = self._create_product_helper(shop)
# Simulate a product file (set file metadata then commit so backfill query sees it)
product.set_file_metadata("product", "mp3", "track.mp3")
shop_id = shop.id
self._flush_and_commit()
# Patch generate_torrent_async where _torrent_backfill_async imports it
with mock.patch("make_post_sell.lib.torrent.generate_torrent_async") as mock_lib:
# Patch the backfill dispatcher — we just need to verify it was called.
# The internal threading/generation logic is tested in TestTorrentLib.
with mock.patch("make_post_sell.views.shop._torrent_backfill_async") as mock_backfill:
self.testapp.post(
f"/s/{shop_id}/settings",
{
@ -5057,8 +5056,7 @@ class TestTorrentSettings(_AuthenticatedBase):
},
status=302,
)
# generate_torrent_async must have been called for our product
self.assertGreaterEqual(mock_lib.call_count, 1)
self.assertGreaterEqual(mock_backfill.call_count, 1)
class TestRestApiV1(_AuthenticatedBase):