forked from saltstack/pytest-salt-factories
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's no longer necessary to pass a docker client instance
Fixes saltstack#111 Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
- Loading branch information
Showing
4 changed files
with
145 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
It's no longer necessary to pass a docker client instance as ``docker_client`` when using containers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
tests/functional/factories/daemons/test_container_factory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize("skip_on_pull_failure", [True, False]) | ||
def test_skip_on_pull_failure(pytester, skip_on_pull_failure): | ||
pytester.makepyfile( | ||
""" | ||
import pytest | ||
@pytest.fixture | ||
def container(salt_factories): | ||
factory = salt_factories.get_container( | ||
"skip_on_pull_failure-{0}", | ||
"non-existing/docker-container", | ||
pull_before_start=True, | ||
skip_on_pull_failure={0} | ||
) | ||
with factory.started() as factory: | ||
yield factory | ||
def test_container(container): | ||
assert container.is_running() | ||
""".format( | ||
skip_on_pull_failure | ||
) | ||
) | ||
res = pytester.runpytest() | ||
if skip_on_pull_failure: | ||
res.assert_outcomes(skipped=1) | ||
else: | ||
res.assert_outcomes(errors=1) | ||
|
||
|
||
@pytest.mark.parametrize("skip_if_docker_client_not_connectable", [True, False]) | ||
def test_skip_if_docker_client_not_connectable( | ||
pytester, subtests, skip_if_docker_client_not_connectable | ||
): | ||
pytester.makepyfile( | ||
""" | ||
import pytest | ||
@pytest.fixture | ||
def container(salt_factories): | ||
factory = salt_factories.get_container( | ||
"skip_if_docker_client_not_connectable-{0}", | ||
"non-existing/docker-container", | ||
skip_if_docker_client_not_connectable={0} | ||
) | ||
with factory.started() as factory: | ||
yield factory | ||
def test_container(container): | ||
assert container.is_running() | ||
""".format( | ||
skip_if_docker_client_not_connectable | ||
) | ||
) | ||
with subtests.test("dockerpy not installed"): | ||
with mock.patch("saltfactories.daemons.container.HAS_DOCKER", False): | ||
res = pytester.runpytest_inprocess() | ||
if skip_if_docker_client_not_connectable: | ||
res.assert_outcomes(skipped=1) | ||
else: | ||
res.assert_outcomes(errors=1) | ||
with subtests.test("requests not installed"): | ||
with mock.patch("saltfactories.daemons.container.HAS_REQUESTS", False): | ||
res = pytester.runpytest_inprocess() | ||
if skip_if_docker_client_not_connectable: | ||
res.assert_outcomes(skipped=1) | ||
else: | ||
res.assert_outcomes(errors=1) | ||
with subtests.test("Container.client_connectable() is False"): | ||
with mock.patch( | ||
"saltfactories.daemons.container.Container.client_connectable", | ||
return_value="Not Connectable!", | ||
): | ||
res = pytester.runpytest_inprocess() | ||
if skip_if_docker_client_not_connectable: | ||
res.assert_outcomes(skipped=1) | ||
else: | ||
res.assert_outcomes(errors=1) |