from unittest import TestCase

from ocyan.plugin.oscar_elasticsearch.search.spooler_compat import spool


class SynchronousSpoolTests(TestCase):
    def test_pass_arguments_fallback_preserves_spool_arguments(self):
        received = []

        @spool(pass_arguments=True)
        def task(*args, **kwargs):
            received.append((args, kwargs))

        task.spool("product-1", category_id="category-1")

        self.assertEqual(received, [(("product-1",), {"category_id": "category-1"})])

    def test_default_fallback_passes_keyword_arguments_as_a_mapping(self):
        received = []

        @spool
        def task(arguments):
            received.append(arguments)

        task.spool(product_id="product-1")

        self.assertEqual(received, [{"product_id": "product-1"}])
