from unittest import TestCase

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


class UnavailableSpoolTests(TestCase):
    def test_pass_arguments_fallback_does_not_run_deferred_work(self):
        received = []

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

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

        self.assertEqual(received, [])

    def test_direct_call_remains_available_without_uwsgi(self):
        received = []

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

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

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