Skip to content

Commit

Permalink
Confluent fastapi tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KrySeyt committed Aug 2, 2024
1 parent 9d92fdc commit f0a8fb9
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/asyncapi/confluent/v3_0_0/test_fastapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from typing import Type

from faststream.asyncapi.generate import get_app_schema
from faststream.asyncapi.version import AsyncAPIVersion
from faststream.confluent.fastapi import KafkaRouter
from faststream.confluent.testing import TestKafkaBroker
from faststream.security import SASLPlaintext
from tests.asyncapi.base.v3_0_0.arguments import FastAPICompatible
from tests.asyncapi.base.v3_0_0.fastapi import FastAPITestCase
from tests.asyncapi.base.v3_0_0.publisher import PublisherTestcase


class TestRouterArguments(FastAPITestCase, FastAPICompatible):
broker_factory = staticmethod(lambda: KafkaRouter(asyncapi_version=AsyncAPIVersion.v3_0))
router_factory = KafkaRouter
broker_wrapper = staticmethod(TestKafkaBroker)

def build_app(self, router):
return router


class TestRouterPublisher(PublisherTestcase):
broker_factory = staticmethod(lambda: KafkaRouter(asyncapi_version=AsyncAPIVersion.v3_0))

def build_app(self, router):
return router


def test_fastapi_security_schema():
security = SASLPlaintext(username="user", password="pass", use_ssl=False)

broker = KafkaRouter("localhost:9092", security=security)

schema = get_app_schema(broker).to_jsonable()

assert schema["servers"]["development"] == {
"protocol": "kafka",
"protocolVersion": "auto",
"security": [{"user-password": []}],
"url": "localhost:9092",
}
assert schema["components"]["securitySchemes"] == {
"user-password": {"type": "userPassword"}
}

0 comments on commit f0a8fb9

Please sign in to comment.