Skip to content

Commit

Permalink
formatting/linting, __all__, _redpanda, references
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderankin committed Mar 31, 2024
1 parent 62a5d74 commit 0b030be
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion modules/kafka/README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.. autoclass:: testcontainers.kafka.KafkaContainer
.. title:: testcontainers.kafka.KafkaContainer
.. autoclass:: testcontainers.redpanda.RedpandaContainer
.. autoclass:: testcontainers.kafka.RedpandaContainer
7 changes: 6 additions & 1 deletion modules/kafka/testcontainers/kafka/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
from testcontainers.core.container import DockerContainer
from testcontainers.core.utils import raise_for_deprecated_parameter
from testcontainers.core.waiting_utils import wait_for_logs
from testcontainers.kafka.redpanda import RedpandaContainer
from testcontainers.kafka._redpanda import RedpandaContainer

__all__ = [
"KafkaContainer",
"RedpandaContainer",
]


class KafkaContainer(DockerContainer):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RedpandaContainer(DockerContainer):
.. doctest::
>>> from testcontainers.redpanda import RedpandaContainer
>>> from testcontainers.kafka import RedpandaContainer
>>> with RedpandaContainer() as redpanda:
... connection = redpanda.get_bootstrap_server()
Expand All @@ -29,7 +29,7 @@ def __init__(
**kwargs,
) -> None:
kwargs["entrypoint"] = "sh"
super(RedpandaContainer, self).__init__(image, **kwargs)
super().__init__(image, **kwargs)
self.redpanda_port = 9092
self.schema_registry_port = 8081
self.with_exposed_ports(self.redpanda_port, self.schema_registry_port)
Expand Down
26 changes: 12 additions & 14 deletions modules/kafka/tests/test_redpanda.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import requests
import json
import pytest
from requests import post, get
from json import dumps

from kafka import KafkaConsumer, KafkaProducer, TopicPartition, KafkaAdminClient
from kafka.admin import NewTopic

from testcontainers.kafka import RedpandaContainer


Expand All @@ -10,10 +13,9 @@ def test_redpanda_producer_consumer():
produce_and_consume_message(container)


def test_redpanda_confluent_latest():
with RedpandaContainer(
image="docker.redpanda.com/redpandadata/redpanda:latest"
) as container:
@pytest.mark.parametrize("version", ["v23.1.13", "v23.3.10"])
def test_redpanda_confluent_version(version):
with RedpandaContainer(image=f"docker.redpanda.com/redpandadata/redpanda:{version}") as container:
produce_and_consume_message(container)


Expand All @@ -23,14 +25,12 @@ def test_schema_registry():
subject_name = "test-subject-value"
url = f"{address}/subjects"

payload = {"schema": json.dumps({"type": "string"})}
payload = {"schema": dumps({"type": "string"})}
headers = {"Content-Type": "application/vnd.schemaregistry.v1+json"}
create_result = requests.post(
f"{url}/{subject_name}/versions", data=json.dumps(payload), headers=headers
)
create_result = post(f"{url}/{subject_name}/versions", data=dumps(payload), headers=headers)
assert create_result.status_code == 200

result = requests.get(url)
result = get(url)
assert result.status_code == 200
assert subject_name in result.json()

Expand All @@ -51,6 +51,4 @@ def produce_and_consume_message(container):
tp = TopicPartition(topic, 0)
consumer.assign([tp])
consumer.seek_to_beginning()
assert (
consumer.end_offsets([tp])[tp] == 1
), "Expected exactly one test message to be present on test topic !"
assert consumer.end_offsets([tp])[tp] == 1, "Expected exactly one test message to be present on test topic !"

0 comments on commit 0b030be

Please sign in to comment.