diff --git a/modules/testmoduleimport/README.rst b/modules/testmoduleimport/README.rst new file mode 100644 index 00000000..ae5d5708 --- /dev/null +++ b/modules/testmoduleimport/README.rst @@ -0,0 +1,2 @@ +.. autoclass:: testcontainers.testmoduleimport.NewSubModuleContainer +.. title:: testcontainers.testmoduleimport.NewSubModuleContainer diff --git a/modules/testmoduleimport/testcontainers/testmoduleimport/__init__.py b/modules/testmoduleimport/testcontainers/testmoduleimport/__init__.py new file mode 100644 index 00000000..74074699 --- /dev/null +++ b/modules/testmoduleimport/testcontainers/testmoduleimport/__init__.py @@ -0,0 +1 @@ +from .new_sub_module import NewSubModuleContainer # noqa: F401 diff --git a/modules/testmoduleimport/testcontainers/testmoduleimport/new_sub_module.py b/modules/testmoduleimport/testcontainers/testmoduleimport/new_sub_module.py new file mode 100644 index 00000000..f45796f7 --- /dev/null +++ b/modules/testmoduleimport/testcontainers/testmoduleimport/new_sub_module.py @@ -0,0 +1,27 @@ +from testcontainers.generic.server import ServerContainer + + +class NewSubModuleContainer(ServerContainer): + """ + This class is a mock container for testing purposes. It is used to test importing from other modules. + + .. doctest:: + + >>> import httpx + >>> from testcontainers.core.image import DockerImage + >>> from testcontainers.testmoduleimport import NewSubModuleContainer + + >>> with DockerImage(path="./modules/generic/tests/samples/python_server", tag="test-mod:latest") as image: + ... with NewSubModuleContainer(port=9000, image=image) as srv: + ... url = srv._create_connection_url() + ... response = httpx.get(f"{url}", timeout=5) + ... assert response.status_code == 200, "Response status code is not 200" + ... assert srv.print_mock() == "NewSubModuleContainer" + + """ + + def __init__(self, port: int, image: str) -> None: + super().__init__(port, image) + + def print_mock(self) -> str: + return "NewSubModuleContainer" diff --git a/modules/testmoduleimport/tests/test_mock_one.py b/modules/testmoduleimport/tests/test_mock_one.py new file mode 100644 index 00000000..85ac6c31 --- /dev/null +++ b/modules/testmoduleimport/tests/test_mock_one.py @@ -0,0 +1,15 @@ +import httpx + +from testcontainers.core.waiting_utils import wait_for_logs +from testcontainers.core.image import DockerImage +from testcontainers.testmoduleimport import NewSubModuleContainer + + +def test_like_doctest(): + with DockerImage(path="./modules/generic/tests/samples/python_server", tag="test-srv:latest") as image: + with NewSubModuleContainer(port=9000, image=image) as srv: + assert srv.print_mock() == "NewSubModuleContainer" + url = srv._create_connection_url() + response = httpx.get(f"{url}", timeout=5) + assert response.status_code == 200, "Response status code is not 200" + _ = wait_for_logs(srv, "GET / HTTP/1.1") diff --git a/poetry.lock b/poetry.lock index 9e4314a4..aa5fdc29 100644 --- a/poetry.lock +++ b/poetry.lock @@ -4490,10 +4490,11 @@ rabbitmq = ["pika"] redis = ["redis"] registry = ["bcrypt"] selenium = ["selenium"] +testmoduleimport = ["httpx"] vault = [] weaviate = ["weaviate-client"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<4.0" -content-hash = "50e1887a83e3923e66ec25e52d35c3da035025b6e268bd76f772232315c00d47" +content-hash = "e07f8edf8cefba872bbf48dcfa187163cefb00a60122daa62de8891b61fc55de" diff --git a/pyproject.toml b/pyproject.toml index fb7ff059..0b608895 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,7 @@ packages = [ { include = "testcontainers", from = "modules/cockroachdb" }, { include = "testcontainers", from = "modules/elasticsearch" }, { include = "testcontainers", from = "modules/generic" }, + { include = "testcontainers", from = "modules/testmoduleimport"}, { include = "testcontainers", from = "modules/google" }, { include = "testcontainers", from = "modules/influxdb" }, { include = "testcontainers", from = "modules/k3s" }, @@ -114,6 +115,7 @@ clickhouse = ["clickhouse-driver"] cockroachdb = [] elasticsearch = [] generic = ["httpx"] +testmoduleimport = ["httpx"] google = ["google-cloud-pubsub", "google-cloud-datastore"] influxdb = ["influxdb", "influxdb-client"] k3s = ["kubernetes", "pyyaml"]