forked from testcontainers/testcontainers-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_new_docker_api.py
More file actions
49 lines (35 loc) · 1.42 KB
/
test_new_docker_api.py
File metadata and controls
49 lines (35 loc) · 1.42 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
44
45
46
47
48
49
import os
import re
from pathlib import Path
from testcontainers import mysql
from testcontainers.core.generic import GenericContainer
from importlib import reload
def setup_module(m):
os.environ["MYSQL_USER"] = "demo"
os.environ["MYSQL_DATABASE"] = "custom_db"
def test_docker_custom_image():
container = GenericContainer("mysql:5.7.17")
container.with_exposed_ports(3306)
container.with_env("MYSQL_ROOT_PASSWORD", "root")
with container:
port = container.get_exposed_port(3306)
assert int(port) > 0
def test_docker_env_variables():
reload(mysql)
db = mysql.MySqlContainer()
db.with_bind_ports(3306, 32785)
with db:
url = db.get_connection_url()
pattern = r'mysql\+pymysql:\/\/demo:test@[\w,.]+:(3306|32785)\/custom_db'
assert re.match(pattern, url)
def test_docker_kargs():
code_dir = Path(__file__).parent
container_first = GenericContainer("nginx:latest")
container_first.with_volume_mapping(code_dir, '/code')
container_second = GenericContainer("nginx:latest")
with container_first:
container_second.with_kargs(volumes_from=[container_first._container.short_id])
with container_second:
files_first = container_first.exec('ls /code').output.decode('utf-8').strip()
files_second = container_second.exec('ls /code').output.decode('utf-8').strip()
assert files_first == files_second