forked from testcontainers/testcontainers-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_db2.py
More file actions
43 lines (37 loc) · 1.49 KB
/
Copy pathtest_db2.py
File metadata and controls
43 lines (37 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from unittest import mock
import pytest
import sqlalchemy
from testcontainers.core.utils import is_arm
from testcontainers.db2 import Db2Container
@pytest.mark.skipif(is_arm(), reason="db2 container not available for ARM")
@pytest.mark.parametrize("version", ["11.5.9.0", "11.5.8.0"])
def test_docker_run_db2(version: str):
with Db2Container(f"icr.io/db2_community/db2:{version}", password="password") as db2:
engine = sqlalchemy.create_engine(db2.get_connection_url())
with engine.begin() as connection:
result = connection.execute(sqlalchemy.text("select service_level from sysibmadm.env_inst_info"))
for row in result:
assert row[0] == f"DB2 v{version}"
# This is a feature in the generic DbContainer class
# but it can't be tested on its own
# so is tested in various database modules:
# - mysql / mariadb
# - postgresql
# - sqlserver
# - mongodb
# - db2
def test_quoted_password():
user = "db2inst1"
dbname = "testdb"
password = "p@$%25+0&%rd :/!=?"
quoted_password = "p%40%24%2525+0%26%25rd %3A%2F%21%3D%3F"
kwargs = {
"username": user,
"password": password,
"dbname": dbname,
}
with Db2Container("icr.io/db2_community/db2:11.5.9.0", **kwargs) as container:
port = container.get_exposed_port(50000)
host = container.get_container_host_ip()
expected_url = f"db2+ibm_db://{user}:{quoted_password}@{host}:{port}/{dbname}"
assert expected_url == container.get_connection_url()