Skip to content

Commit

Permalink
RabbitMQ asyncapi test connection
Browse files Browse the repository at this point in the history
  • Loading branch information
KrySeyt committed Aug 2, 2024
1 parent 08fe652 commit 22d54f8
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 2 deletions.
143 changes: 143 additions & 0 deletions tests/asyncapi/rabbit/v3_0_0/test_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
from faststream import FastStream
from faststream.asyncapi.generate import get_app_schema
from faststream.asyncapi.schema import Tag
from faststream.asyncapi.version import AsyncAPIVersion
from faststream.rabbit import RabbitBroker


def test_base():
schema = get_app_schema(
FastStream(
RabbitBroker(
"amqps://localhost",
port=5673,
protocol_version="0.9.0",
description="Test description",
tags=(Tag(name="some-tag", description="experimental"),),
),
asyncapi_version=AsyncAPIVersion.v3_0,
)
).to_jsonable()

assert schema == {
"asyncapi": "3.0.0",
"channels": {},
"operations": {},
"components": {"messages": {}, "schemas": {}},
"defaultContentType": "application/json",
"info": {"description": "", "title": "FastStream", "version": "0.1.0"},
"servers": {
"development": {
"description": "Test description",
"protocol": "amqps",
"protocolVersion": "0.9.0",
"tags": [{"description": "experimental", "name": "some-tag"}],
"host": "guest:guest@localhost:5673", # pragma: allowlist secret
"pathname": "/",
}
},
}


def test_kwargs():
broker = RabbitBroker(
"amqp://guest:guest@localhost:5672/?heartbeat=300", # pragma: allowlist secret
host="127.0.0.1",
)

assert (
broker.url
== "amqp://guest:[email protected]:5672/?heartbeat=300" # pragma: allowlist secret
)


def test_custom():
broker = RabbitBroker(
"amqps://localhost",
asyncapi_url="amqp://guest:[email protected]:5672/vh", # pragma: allowlist secret
)

broker.publisher("test")
schema = get_app_schema(FastStream(broker, asyncapi_version=AsyncAPIVersion.v3_0)).to_jsonable()

assert (
schema
== {
"asyncapi": "3.0.0",
"channels": {
"test:_:Publisher": {
'address': 'test:_:Publisher',
"bindings": {
"amqp": {
"bindingVersion": "0.2.0",
"exchange": {"type": "default", "vhost": "/vh"},
"is": "routingKey",
"queue": {
"autoDelete": False,
"durable": False,
"exclusive": False,
"name": "test",
"vhost": "/vh",
},
}
},
"servers": [
{
'$ref': '#/servers/development',
}
],
'messages': {
'Message': {
'$ref': '#/components/messages/test:_:Publisher:Message',
},
}
}
},
'operations': {
'test:_:Publisher': {
'action': 'send',
'bindings': {
'amqp': {
'ack': True,
'bindingVersion': '0.2.0',
'cc': 'test',
'deliveryMode': 1,
'mandatory': True,
},
},
'channel': {
'$ref': '#/channels/test:_:Publisher',
},
'messages': [
{
'$ref': '#/channels/test:_:Publisher/messages/Message',
},
],
},
},
"components": {
"messages": {
"test:_:Publisher:Message": {
"correlationId": {
"location": "$message.header#/correlation_id"
},
"payload": {
'$ref': '#/components/schemas/test:_:Publisher:Message:Payload'
},
"title": "test:_:Publisher:Message",
}
},
"schemas": {'test:_:Publisher:Message:Payload': {}},
},
"defaultContentType": "application/json",
"info": {"description": "", "title": "FastStream", "version": "0.1.0"},
"servers": {
"development": {
"protocol": "amqp",
"protocolVersion": "0.9.1",
"host": "guest:[email protected]:5672", # pragma: allowlist secret
"pathname": "/vh", # pragma: allowlist secret
}
},
}
)
2 changes: 0 additions & 2 deletions tests/asyncapi/redis/v3_0_0/test_fastapi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Type

from faststream.asyncapi.version import AsyncAPIVersion
from faststream.redis import TestRedisBroker
from faststream.redis.fastapi import RedisRouter
Expand Down

0 comments on commit 22d54f8

Please sign in to comment.