Skip to content

Commit db17147

Browse files
Merge branch 'master' into feat/python-3.11-builds
2 parents cd01f2a + 63ad996 commit db17147

File tree

39 files changed

+496
-549
lines changed

39 files changed

+496
-549
lines changed

arangodb/testcontainers/arangodb/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
ArangoDB container support.
33
"""
44
from os import environ
5-
from testcontainers.core.config import MAX_TRIES
5+
from testcontainers.core.config import TIMEOUT
66
from testcontainers.core.generic import DbContainer
7+
from testcontainers.core.utils import raise_for_deprecated_parameter
78
from testcontainers.core.waiting_utils import wait_for_logs
89
import typing
910

@@ -36,15 +37,15 @@ class ArangoDbContainer(DbContainer):
3637

3738
def __init__(self,
3839
image: str = "arangodb:latest",
39-
port_to_expose: int = 8529,
40+
port: int = 8529,
4041
arango_root_password: str = "passwd",
4142
arango_no_auth: typing.Optional[bool] = None,
4243
arango_random_root_password: typing.Optional[bool] = None,
4344
**kwargs) -> None:
4445
"""
4546
Args:
4647
image: Actual docker image/tag to pull.
47-
port_to_expose: Port the container needs to expose.
48+
port: Port the container needs to expose.
4849
arango_root_password: Start ArangoDB with the given password for root. Defaults to the
4950
environment variable `ARANGO_ROOT_PASSWORD` if `None`.
5051
arango_no_auth: Disable authentication completely. Defaults to the environment variable
@@ -53,9 +54,10 @@ def __init__(self,
5354
the environment variable `ARANGO_NO_AUTH` if `None` or `False` if the environment
5455
variable is not available.
5556
"""
57+
raise_for_deprecated_parameter(kwargs, "port_to_expose", "port")
5658
super().__init__(image=image, **kwargs)
57-
self.port_to_expose = port_to_expose
58-
self.with_exposed_ports(self.port_to_expose)
59+
self.port = port
60+
self.with_exposed_ports(self.port)
5961

6062
# See https://www.arangodb.com/docs/stable/deployment-single-instance-manual-start.html for
6163
# details. We convert to int then to bool because Arango uses the string literal "1" to
@@ -77,8 +79,8 @@ def _configure(self) -> None:
7779
self.with_env("ARANGO_RANDOM_ROOT_PASSWORD", "1")
7880

7981
def get_connection_url(self) -> str:
80-
port = self.get_exposed_port(self.port_to_expose)
82+
port = self.get_exposed_port(self.port)
8183
return f"http://{self.get_container_host_ip()}:{port}"
8284

8385
def _connect(self) -> None:
84-
wait_for_logs(self, predicate="is ready for business", timeout=MAX_TRIES)
86+
wait_for_logs(self, predicate="is ready for business", timeout=TIMEOUT)

arangodb/tests/test_arangodb.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@
99
ARANGODB_IMAGE_NAME = 'arangodb'
1010

1111

12-
def arango_test_ops(arango_client, expeced_version, db_user='root', db_pass=''):
12+
def arango_test_ops(arango_client, expeced_version, username='root', password=''):
1313
"""
1414
Basic ArangoDB operations to test DB really up and running.
1515
"""
1616
students_to_insert_cnt = 3
1717

1818
# Taken from https://github.com/ArangoDB-Community/python-arango/blob/main/README.md
1919
# Connect to "_system" database as root user.
20-
sys_db = arango_client.db("_system", username=db_user, password=db_pass)
20+
sys_db = arango_client.db("_system", username=username, password=password)
2121
assert sys_db.version() == expeced_version
2222

2323
# Create a new database named "test".
2424
sys_db.create_database("test")
2525

2626
# Connect to "test" database as root user.
27-
database = arango_client.db("test", username=db_user, password=db_pass)
27+
database = arango_client.db("test", username=username, password=password)
2828

2929
# Create a new collection named "students".
3030
students = database.create_collection("students")
@@ -50,7 +50,7 @@ def test_docker_run_arango():
5050
"""
5151
image_version = '3.9.1'
5252
image = f'{ARANGODB_IMAGE_NAME}:{image_version}'
53-
arango_db_root_password = 'passwd'
53+
arango_root_password = 'passwd'
5454

5555
with ArangoDbContainer(image) as arango:
5656
client = ArangoClient(hosts=arango.get_connection_url())
@@ -63,7 +63,7 @@ def test_docker_run_arango():
6363
arango_test_ops(
6464
arango_client=client,
6565
expeced_version=image_version,
66-
db_pass=arango_db_root_password)
66+
password=arango_root_password)
6767

6868

6969
def test_docker_run_arango_without_auth():
@@ -79,7 +79,7 @@ def test_docker_run_arango_without_auth():
7979
arango_test_ops(
8080
arango_client=client,
8181
expeced_version=image_version,
82-
db_pass='')
82+
password='')
8383

8484

8585
def test_docker_run_arango_older_version():
@@ -100,7 +100,7 @@ def test_docker_run_arango_older_version():
100100
arango_test_ops(
101101
arango_client=client,
102102
expeced_version=image_version,
103-
db_pass='')
103+
password='')
104104

105105

106106
def test_docker_run_arango_random_root_password():
@@ -109,12 +109,12 @@ def test_docker_run_arango_random_root_password():
109109
"""
110110
image_version = '3.9.1'
111111
image = f'{ARANGODB_IMAGE_NAME}:{image_version}'
112-
arango_db_root_password = 'passwd'
112+
arango_root_password = 'passwd'
113113

114114
with ArangoDbContainer(image, arango_random_root_password=True) as arango:
115115
client = ArangoClient(hosts=arango.get_connection_url())
116116

117117
# Test invalid auth (we don't know the password in random mode)
118118
with pytest.raises(ServerVersionError):
119-
sys_db = client.db("_system", username='root', password=arango_db_root_password)
119+
sys_db = client.db("_system", username='root', password=arango_root_password)
120120
assert sys_db.version() == image_version

azurite/testcontainers/azurite/__init__.py

Lines changed: 44 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,88 +12,80 @@
1212
# under the License.
1313
import os
1414
import socket
15-
from typing import Iterable, Optional
15+
from typing import Optional
1616

1717
from testcontainers.core.container import DockerContainer
18+
from testcontainers.core.utils import raise_for_deprecated_parameter
1819
from testcontainers.core.waiting_utils import wait_container_is_ready
1920

2021

2122
class AzuriteContainer(DockerContainer):
2223
"""
23-
The example below spins up an Azurite container and
24-
shows an example to create a Blob service client with the container. The method
25-
:code:`get_connection_string` can be used to create a client for Blob service, Queue service
26-
and Table service.
24+
The example below spins up an Azurite container and
25+
shows an example to create a Blob service client with the container. The method
26+
:code:`get_connection_string` can be used to create a client for Blob service, Queue service
27+
and Table service.
2728
28-
Example:
29+
Example:
2930
30-
.. doctest::
31+
.. doctest::
3132
32-
>>> from testcontainers.azurite import AzuriteContainer
33-
>>> from azure.storage.blob import BlobServiceClient
33+
>>> from testcontainers.azurite import AzuriteContainer
34+
>>> from azure.storage.blob import BlobServiceClient
3435
35-
>>> with AzuriteContainer() as azurite_container:
36-
... connection_string = azurite_container.get_connection_string()
37-
... client = BlobServiceClient.from_connection_string(
38-
... connection_string,
39-
... api_version="2019-12-12"
40-
... )
41-
"""
42-
43-
_AZURITE_ACCOUNT_NAME = os.environ.get("AZURITE_ACCOUNT_NAME", "devstoreaccount1")
44-
_AZURITE_ACCOUNT_KEY = os.environ.get("AZURITE_ACCOUNT_KEY", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDX"
45-
"J1OUzFT50uSRZ6IFsuFq2UVErCz4I6"
46-
"tq/K1SZFPTOtr/KBHBeksoGMGw==")
47-
48-
_BLOB_SERVICE_PORT = 10_000
49-
_QUEUE_SERVICE_PORT = 10_001
50-
_TABLE_SERVICE_PORT = 10_002
51-
52-
def __init__(self, image: str = "mcr.microsoft.com/azure-storage/azurite:latest",
53-
ports_to_expose: Optional[Iterable[int]] = None, **kwargs) -> None:
36+
>>> with AzuriteContainer() as azurite_container:
37+
... connection_string = azurite_container.get_connection_string()
38+
... client = BlobServiceClient.from_connection_string(
39+
... connection_string,
40+
... api_version="2019-12-12"
41+
... )
42+
"""
43+
def __init__(self, image: str = "mcr.microsoft.com/azure-storage/azurite:latest", *,
44+
blob_service_port: int = 10_000, queue_service_port: int = 10_001,
45+
table_service_port: int = 10_002, account_name: Optional[str] = None,
46+
account_key: Optional[str] = None, **kwargs) \
47+
-> None:
5448
""" Constructs an AzuriteContainer.
5549
5650
Args:
5751
image: Expects an image with tag.
58-
ports_to_expose: List with port numbers to expose.
5952
**kwargs: Keyword arguments passed to super class.
6053
"""
6154
super().__init__(image=image, **kwargs)
55+
self.account_name = account_name or os.environ.get(
56+
"AZURITE_ACCOUNT_NAME", "devstoreaccount1")
57+
self.account_key = account_key or os.environ.get(
58+
"AZURITE_ACCOUNT_KEY", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/"
59+
"K1SZFPTOtr/KBHBeksoGMGw==")
6260

63-
if ports_to_expose is None:
64-
ports_to_expose = [
65-
self._BLOB_SERVICE_PORT,
66-
self._QUEUE_SERVICE_PORT,
67-
self._TABLE_SERVICE_PORT
68-
]
69-
70-
if len(ports_to_expose) == 0:
71-
raise ValueError("Expected a list with port numbers to expose")
61+
raise_for_deprecated_parameter(kwargs, "ports_to_expose", "container.with_exposed_ports")
62+
self.blob_service_port = blob_service_port
63+
self.queue_service_port = queue_service_port
64+
self.table_service_port = table_service_port
7265

73-
self.with_exposed_ports(*ports_to_expose)
74-
self.with_env("AZURITE_ACCOUNTS",
75-
f"{self._AZURITE_ACCOUNT_NAME}:{self._AZURITE_ACCOUNT_KEY}")
66+
self.with_exposed_ports(blob_service_port, queue_service_port, table_service_port)
67+
self.with_env("AZURITE_ACCOUNTS", f"{self.account_name}:{self.account_key}")
7668

7769
def get_connection_string(self) -> str:
7870
host_ip = self.get_container_host_ip()
7971
connection_string = f"DefaultEndpointsProtocol=http;" \
80-
f"AccountName={self._AZURITE_ACCOUNT_NAME};" \
81-
f"AccountKey={self._AZURITE_ACCOUNT_KEY};"
72+
f"AccountName={self.account_name};" \
73+
f"AccountKey={self.account_key};"
8274

83-
if self._BLOB_SERVICE_PORT in self.ports:
75+
if self.blob_service_port in self.ports:
8476
connection_string += f"BlobEndpoint=http://{host_ip}:" \
85-
f"{self.get_exposed_port(self._BLOB_SERVICE_PORT)}" \
86-
f"/{self._AZURITE_ACCOUNT_NAME};"
77+
f"{self.get_exposed_port(self.blob_service_port)}" \
78+
f"/{self.account_name};"
8779

88-
if self._QUEUE_SERVICE_PORT in self.ports:
80+
if self.queue_service_port in self.ports:
8981
connection_string += f"QueueEndpoint=http://{host_ip}:" \
90-
f"{self.get_exposed_port(self._QUEUE_SERVICE_PORT)}" \
91-
f"/{self._AZURITE_ACCOUNT_NAME};"
82+
f"{self.get_exposed_port(self.queue_service_port)}" \
83+
f"/{self.account_name};"
9284

93-
if self._TABLE_SERVICE_PORT in self.ports:
85+
if self.table_service_port in self.ports:
9486
connection_string += f"TableEndpoint=http://{host_ip}:" \
95-
f"{self.get_exposed_port(self._TABLE_SERVICE_PORT)}" \
96-
f"/{self._AZURITE_ACCOUNT_NAME};"
87+
f"{self.get_exposed_port(self.table_service_port)}" \
88+
f"/{self.account_name};"
9789

9890
return connection_string
9991

clickhouse/testcontainers/clickhouse/__init__.py

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from clickhouse_driver.errors import Error
1818

1919
from testcontainers.core.generic import DbContainer
20+
from testcontainers.core.utils import raise_for_deprecated_parameter
2021
from testcontainers.core.waiting_utils import wait_container_is_ready
2122

2223

@@ -39,43 +40,33 @@ class ClickHouseContainer(DbContainer):
3940
... client.execute("select 'working'")
4041
[('working',)]
4142
"""
42-
43-
CLICKHOUSE_USER = os.environ.get("CLICKHOUSE_USER", "test")
44-
CLICKHOUSE_PASSWORD = os.environ.get("CLICKHOUSE_PASSWORD", "test")
45-
CLICKHOUSE_DB = os.environ.get("CLICKHOUSE_DB", "test")
46-
47-
def __init__(
48-
self,
49-
image: str = "clickhouse/clickhouse-server:latest",
50-
port: int = 9000,
51-
user: Optional[str] = None,
52-
password: Optional[str] = None,
53-
dbname: Optional[str] = None
54-
) -> None:
55-
super().__init__(image=image)
56-
57-
self.CLICKHOUSE_USER = user or self.CLICKHOUSE_USER
58-
self.CLICKHOUSE_PASSWORD = password or self.CLICKHOUSE_PASSWORD
59-
self.CLICKHOUSE_DB = dbname or self.CLICKHOUSE_DB
60-
self.port_to_expose = port
61-
self.with_exposed_ports(self.port_to_expose)
43+
def __init__(self, image: str = "clickhouse/clickhouse-server:latest", port: int = 9000,
44+
username: Optional[str] = None, password: Optional[str] = None,
45+
dbname: Optional[str] = None, **kwargs) -> None:
46+
raise_for_deprecated_parameter(kwargs, "user", "username")
47+
super().__init__(image=image, **kwargs)
48+
self.username = username or os.environ.get("CLICKHOUSE_USER", "test")
49+
self.password = password or os.environ.get("CLICKHOUSE_PASSWORD", "test")
50+
self.dbname = dbname or os.environ.get("CLICKHOUSE_DB", "test")
51+
self.port = port
52+
self.with_exposed_ports(self.port)
6253

6354
@wait_container_is_ready(Error, EOFError)
6455
def _connect(self) -> None:
6556
with clickhouse_driver.Client.from_url(self.get_connection_url()) as client:
6657
client.execute("SELECT version()")
6758

6859
def _configure(self) -> None:
69-
self.with_env("CLICKHOUSE_USER", self.CLICKHOUSE_USER)
70-
self.with_env("CLICKHOUSE_PASSWORD", self.CLICKHOUSE_PASSWORD)
71-
self.with_env("CLICKHOUSE_DB", self.CLICKHOUSE_DB)
60+
self.with_env("CLICKHOUSE_USER", self.username)
61+
self.with_env("CLICKHOUSE_PASSWORD", self.password)
62+
self.with_env("CLICKHOUSE_DB", self.dbname)
7263

7364
def get_connection_url(self, host: Optional[str] = None) -> str:
7465
return self._create_connection_url(
7566
dialect="clickhouse",
76-
username=self.CLICKHOUSE_USER,
77-
password=self.CLICKHOUSE_PASSWORD,
78-
db_name=self.CLICKHOUSE_DB,
67+
username=self.username,
68+
password=self.password,
69+
dbname=self.dbname,
7970
host=host,
80-
port=self.port_to_expose,
71+
port=self.port,
8172
)

compose/testcontainers/compose/__init__.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
"""
2-
Docker Compose Support
3-
======================
4-
5-
Allows to spin up services configured via :code:`docker-compose.yml`.
6-
"""
7-
81
import requests
92
import subprocess
103
from typing import Iterable, List, Optional, Tuple, Union
@@ -36,13 +29,13 @@ class DockerCompose:
3629
host = compose.get_service_host("hub", 4444)
3730
port = compose.get_service_port("hub", 4444)
3831
driver = webdriver.Remote(
39-
command_executor=("http://{}:{}/wd/hub".format(host,port)),
32+
command_executor=(f"http://{host}:{port}/wd/hub"),
4033
desired_capabilities=CHROME,
4134
)
4235
driver.get("http://automation-remarks.com")
4336
stdout, stderr = compose.get_logs()
4437
if stderr:
45-
print("Errors\\n:{}".format(stderr))
38+
print(f"Errors\\n:{stderr}")
4639
4740
.. code-block:: yaml
4841

core/testcontainers/core/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
MAX_TRIES = int(environ.get("TC_MAX_TRIES", 120))
44
SLEEP_TIME = int(environ.get("TC_POOLING_INTERVAL", 1))
5+
TIMEOUT = MAX_TRIES * SLEEP_TIME

core/testcontainers/core/docker_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def port(self, container_id: str, port: int) -> int:
6161
"""
6262
port_mappings = self.client.api.port(container_id, port)
6363
if not port_mappings:
64-
raise ConnectionError(f'port mapping for container {container_id} and port {port} is '
64+
raise ConnectionError(f'Port mapping for container {container_id} and port {port} is '
6565
'not available')
6666
return port_mappings[0]["HostPort"]
6767

@@ -71,7 +71,7 @@ def get_container(self, container_id: str) -> Container:
7171
"""
7272
containers = self.client.api.containers(filters={'id': container_id})
7373
if not containers:
74-
raise RuntimeError(f'could not get container with id {container_id}')
74+
raise RuntimeError(f'Could not get container with id {container_id}')
7575
return containers[0]
7676

7777
def bridge_ip(self, container_id: str) -> str:

0 commit comments

Comments
 (0)