1
+ import os
2
+ from collections import namedtuple
3
+ from unittest import mock
1
4
from unittest .mock import MagicMock , patch
2
5
3
6
import docker
4
7
8
+ from testcontainers .core .config import testcontainers_config as c
5
9
from testcontainers .core .container import DockerContainer
6
10
from testcontainers .core .docker_client import DockerClient
11
+ from testcontainers .core .utils import parse_docker_auth_config
7
12
8
13
9
14
def test_docker_client_from_env ():
@@ -15,6 +20,33 @@ def test_docker_client_from_env():
15
20
mock_docker .from_env .assert_called_with (** test_kwargs )
16
21
17
22
23
+ def test_docker_client_login_no_login ():
24
+ with patch .dict (os .environ , {}, clear = True ):
25
+ mock_docker = MagicMock (spec = docker )
26
+ with patch ("testcontainers.core.docker_client.docker" , mock_docker ):
27
+ DockerClient ()
28
+
29
+ mock_docker .from_env .return_value .login .assert_not_called ()
30
+
31
+
32
+ def test_docker_client_login ():
33
+ mock_docker = MagicMock (spec = docker )
34
+ mock_parse_docker_auth_config = MagicMock (spec = parse_docker_auth_config )
35
+ mock_utils = MagicMock ()
36
+ mock_utils .parse_docker_auth_config = mock_parse_docker_auth_config
37
+ TestAuth = namedtuple ("Auth" , "value" )
38
+ mock_parse_docker_auth_config .return_value = [TestAuth ("test" )]
39
+
40
+ with (
41
+ mock .patch .object (c , "_docker_auth_config" , "test" ),
42
+ patch ("testcontainers.core.docker_client.docker" , mock_docker ),
43
+ patch ("testcontainers.core.docker_client.parse_docker_auth_config" , mock_parse_docker_auth_config ),
44
+ ):
45
+ DockerClient ()
46
+
47
+ mock_docker .from_env .return_value .login .assert_called_with (** {"value" : "test" })
48
+
49
+
18
50
def test_container_docker_client_kw ():
19
51
test_kwargs = {"test_kw" : "test_value" }
20
52
mock_docker = MagicMock (spec = docker )
0 commit comments