Skip to content

Commit 99a3252

Browse files
Merge pull request #222 from tillahoffmann/arango-fix
Fix None/True/False handling in Arango.
2 parents c0dc701 + 3f720fa commit 99a3252

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

testcontainers/arangodb.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from testcontainers.core.config import MAX_TRIES
66
from testcontainers.core.generic import DbContainer
77
from testcontainers.core.waiting_utils import wait_for_logs
8+
import typing
89

910

1011
class ArangoDbContainer(DbContainer):
@@ -22,52 +23,56 @@ class ArangoDbContainer(DbContainer):
2223
client = ArangoClient(hosts=arango.get_connection_url())
2324
2425
# Connect
25-
sys_db = arango_client.db(username='root', password='')
26+
sys_db = arango_client.db(username="root", password="")
2627
2728
# Create a new database named "test".
2829
sys_db.create_database("test")
2930
"""
3031
def __init__(self,
31-
image="arangodb:latest",
32-
port_to_expose=8529,
33-
arango_root_password='passwd',
34-
arango_no_auth=False,
35-
arango_random_root_password=False,
32+
image: str = "arangodb:latest",
33+
port_to_expose: int = 8529,
34+
arango_root_password: str = "passwd",
35+
arango_no_auth: typing.Optional[bool] = None,
36+
arango_random_root_password: typing.Optional[bool] = None,
3637
**kwargs):
3738
"""
3839
Args:
39-
image (str, optional): Actual docker image/tag to pull. Defaults to "arangodb:latest".
40-
port_to_expose (int, optional): Port the container needs to expose. Defaults to 8529.
41-
arango_root_password (str, optional): Start ArangoDB with the
42-
given password for root. Defaults to 'passwd'.
43-
arango_no_auth (bool, optional): Disable authentication completely.
44-
Defaults to False.
45-
arango_random_root_password (bool, optional): Let ArangoDB generate a
46-
random root password. Defaults to False.
40+
image: Actual docker image/tag to pull.
41+
port_to_expose: Port the container needs to expose.
42+
arango_root_password: Start ArangoDB with the given password for root. Defaults to the
43+
environment variable `ARANGO_ROOT_PASSWORD` if `None`.
44+
arango_no_auth: Disable authentication completely. Defaults to the environment variable
45+
`ARANGO_NO_AUTH` if `None` or `False` if the environment variable is not available.
46+
arango_random_root_password: Let ArangoDB generate a random root password. Defaults to
47+
the environment variable `ARANGO_NO_AUTH` if `None` or `False` if the environment
48+
variable is not available.
4749
"""
48-
super().__init__(image=image)
50+
super().__init__(image=image, **kwargs)
4951
self.port_to_expose = port_to_expose
5052
self.with_exposed_ports(self.port_to_expose)
5153

52-
# https://www.arangodb.com/docs/stable/deployment-single-instance-manual-start.html
53-
self.arango_no_auth = arango_no_auth or \
54-
environ.get("ARANGO_NO_AUTH")
55-
self.arango_root_password = arango_root_password or \
56-
environ.get('ARANGO_ROOT_PASSWORD')
57-
self.arango_random_root_password = arango_random_root_password or \
58-
environ.get('ARANGO_RANDOM_ROOT_PASSWORD')
54+
# See https://www.arangodb.com/docs/stable/deployment-single-instance-manual-start.html for
55+
# details. We convert to int then to bool because Arango uses the string literal "1" to
56+
# indicate flags.
57+
self.arango_no_auth = bool(int(environ.get("ARANGO_NO_AUTH", 0) if arango_no_auth is None
58+
else arango_no_auth))
59+
self.arango_root_password = environ.get("ARANGO_ROOT_PASSWORD") if arango_root_password is \
60+
None else arango_root_password
61+
self.arango_random_root_password = bool(int(
62+
environ.get("ARANGO_RANDOM_ROOT_PASSWORD", 0) if arango_random_root_password is None
63+
else arango_random_root_password
64+
))
5965

6066
def _configure(self):
61-
self.with_env(
62-
"ARANGO_NO_AUTH", self.arango_no_auth)
63-
self.with_env(
64-
"ARANGO_ROOT_PASSWORD", self.arango_root_password)
65-
self.with_env(
66-
"ARANGO_RANDOM_ROOT_PASSWORD", self.arango_random_root_password)
67+
self.with_env("ARANGO_ROOT_PASSWORD", self.arango_root_password)
68+
if self.arango_no_auth:
69+
self.with_env("ARANGO_NO_AUTH", "1")
70+
if self.arango_random_root_password:
71+
self.with_env("ARANGO_RANDOM_ROOT_PASSWORD", "1")
6772

6873
def get_connection_url(self):
6974
# for now, single host over HTTP
70-
scheme = 'http'
75+
scheme = "http"
7176
port = self.get_exposed_port(self.port_to_expose)
7277
url = f"{scheme}://{self.get_container_host_ip()}:{port}"
7378

0 commit comments

Comments
 (0)