MCPcopy Create free account
hub / github.com/vercel/vercel / TestQueueClients

Class TestQueueClients

python/vercel-workers/tests/test_client_and_callback.py:616–777  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

614
615
616class TestQueueClients(unittest.TestCase):
617 def setUp(self) -> None:
618 _FakeHttpxClient.captured_bodies.clear()
619 _FakeHttpxClient.captured_headers.clear()
620 _FakeHttpxClient.captured_urls.clear()
621 _FakeAsyncHttpxClient.captured_bodies.clear()
622 _FakeAsyncHttpxClient.captured_headers.clear()
623 _FakeAsyncHttpxClient.captured_urls.clear()
624
625 def test_queue_client_uses_constructor_configuration(self) -> None:
626 client = queue_client_impl.QueueClient(
627 region="sfo1",
628 token="tok",
629 deployment_id="dpl_123",
630 headers={"X-Client": "client"},
631 )
632
633 with (
634 patch.dict(queue_service.os.environ, {}, clear=True),
635 patch.object(queue_service.httpx, "Client", _FakeHttpxClient),
636 ):
637 client.send(
638 "orders",
639 {"ok": True},
640 idempotency_key="key-1",
641 headers={"X-Call": "call"},
642 )
643
644 self.assertEqual(
645 _FakeHttpxClient.captured_urls[-1],
646 "https://sfo1.vercel-queue.com/api/v3/topic/orders",
647 )
648 self.assertEqual(json.loads(_FakeHttpxClient.captured_bodies[-1]), {"ok": True})
649 headers = _FakeHttpxClient.captured_headers[-1]
650 self.assertEqual(headers["Authorization"], "Bearer tok")
651 self.assertEqual(headers["Vqs-Deployment-Id"], "dpl_123")
652 self.assertEqual(headers["Vqs-Idempotency-Key"], "key-1")
653 self.assertEqual(headers["X-Client"], "client")
654 self.assertEqual(headers["X-Call"], "call")
655
656 def test_queue_client_preserves_dev_proxy_base_url(self) -> None:
657 client = queue_client_impl.QueueClient(region="sfo1", token="tok", deployment_id=None)
658
659 with (
660 patch.dict(
661 queue_service.os.environ,
662 {"VERCEL_QUEUE_BASE_URL": "http://localhost:3000/_svc/_queues"},
663 clear=True,
664 ),
665 patch.object(queue_service.httpx, "Client", _FakeHttpxClient),
666 ):
667 client.send("orders", {"ok": True})
668
669 self.assertEqual(
670 _FakeHttpxClient.captured_urls[-1],
671 "http://localhost:3000/_svc/_queues/api/v3/topic/orders",
672 )
673

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected