Skip to content

Commit

Permalink
fix(Kafka backend): use enum values when represent kafka backend as d…
Browse files Browse the repository at this point in the history
…ict. Close kpn#130 (kpn#131)
  • Loading branch information
marcosschroh committed Jun 18, 2024
1 parent dcd492d commit 976ef5f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions kstreams/backends/kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Kafka(BaseModel):

class Config:
arbitrary_types_allowed = True
use_enum_values = True

@root_validator
def protocols_validation(cls, values):
Expand Down
18 changes: 18 additions & 0 deletions tests/test_backend_kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,21 @@ def test_sasl_ssl_fail_missing_ssl_context():
sasl_plain_password=password,
)
assert "ssl_context" in str(e.value.args[0])


def test_backend_to_dict():
kafka_backend = Kafka(
security_protocol=SecurityProtocol.SASL_PLAINTEXT,
sasl_plain_username="username",
sasl_plain_password="pwd",
)
assert kafka_backend.security_protocol == SecurityProtocol.SASL_PLAINTEXT
assert kafka_backend.dict() == {
"bootstrap_servers": ["localhost:9092"],
"security_protocol": "SASL_PLAINTEXT",
"ssl_context": None,
"sasl_mechanism": "PLAIN",
"sasl_plain_username": "username",
"sasl_plain_password": "pwd",
"sasl_oauth_token_provider": None,
}

0 comments on commit 976ef5f

Please sign in to comment.