-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move most of the remaining tests to use docker_client or ctr_client f…
…ixture (#535)
- Loading branch information
Showing
9 changed files
with
298 additions
and
250 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 |
---|---|---|
@@ -1,41 +1,45 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from python_on_whales import docker | ||
from python_on_whales import DockerClient | ||
|
||
|
||
@pytest.mark.usefixtures("swarm_mode") | ||
def test_list_configs(): | ||
assert docker.config.list() == [] | ||
def test_list_configs(docker_client: DockerClient): | ||
assert docker_client.config.list() == [] | ||
|
||
|
||
@pytest.mark.usefixtures("swarm_mode") | ||
def test_create_delete_config(tmp_path): | ||
def test_create_delete_config(docker_client: DockerClient, tmp_path: Path): | ||
config_file = tmp_path / "config.conf" | ||
config_file.write_text("hello world") | ||
my_conf = docker.config.create("my_conf", config_file) | ||
my_conf = docker_client.config.create("my_conf", config_file) | ||
with my_conf: | ||
assert my_conf.spec.name == "my_conf" | ||
assert docker.config.list() == [my_conf] | ||
assert docker.config.inspect("my_conf") == my_conf | ||
repr(docker.config.list()) | ||
assert docker_client.config.list() == [my_conf] | ||
assert docker_client.config.inspect("my_conf") == my_conf | ||
repr(docker_client.config.list()) | ||
|
||
|
||
@pytest.mark.usefixtures("swarm_mode") | ||
def test_labels_config(tmp_path): | ||
def test_labels_config(docker_client: DockerClient, tmp_path: Path): | ||
config_file = tmp_path / "config.conf" | ||
config_file.write_text("hello world") | ||
my_conf = docker.config.create("my_conf", config_file, labels=dict(dodo="dada")) | ||
my_conf = docker_client.config.create( | ||
"my_conf", config_file, labels=dict(dodo="dada") | ||
) | ||
with my_conf: | ||
assert my_conf.spec.name == "my_conf" | ||
assert docker.config.list(filters=dict(label="dodo=dada")) == [my_conf] | ||
assert docker.config.list(filters=dict(label="dodo=dadu")) == [] | ||
assert docker_client.config.list(filters=dict(label="dodo=dada")) == [my_conf] | ||
assert docker_client.config.list(filters=dict(label="dodo=dadu")) == [] | ||
|
||
|
||
@pytest.mark.usefixtures("swarm_mode") | ||
def test_remove_empty_config_list(tmp_path): | ||
def test_remove_empty_config_list(docker_client: DockerClient, tmp_path: Path): | ||
config_file = tmp_path / "config.conf" | ||
config_file.write_text("hello world") | ||
with docker.config.create("my_conf", config_file) as my_conf: | ||
assert docker.config.list() == [my_conf] | ||
docker.config.remove([]) | ||
assert docker.config.list() == [my_conf] | ||
with docker_client.config.create("my_conf", config_file) as my_conf: | ||
assert docker_client.config.list() == [my_conf] | ||
docker_client.config.remove([]) | ||
assert docker_client.config.list() == [my_conf] |
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
import pytest | ||
|
||
from python_on_whales import docker | ||
from python_on_whales import DockerClient | ||
from python_on_whales.components.context.models import ContextInspectResult | ||
from python_on_whales.test_utils import get_all_jsons | ||
|
||
|
@@ -14,13 +14,13 @@ def test_load_json(json_file): | |
# we could do more checks here if needed | ||
|
||
|
||
def test_create_context(): | ||
def test_create_context(docker_client: DockerClient): | ||
testname = "testpow" | ||
host = "ssh://[email protected]" | ||
description = "Python on whales testing context" | ||
|
||
all_contexts_before = set(docker.context.list()) | ||
with docker.context.create( | ||
all_contexts_before = set(docker_client.context.list()) | ||
with docker_client.context.create( | ||
testname, docker=dict(host=host), description=description | ||
) as new_context: | ||
assert new_context.name == testname | ||
|
@@ -29,30 +29,32 @@ def test_create_context(): | |
|
||
assert new_context not in all_contexts_before | ||
|
||
assert new_context in docker.context.list() | ||
assert new_context in docker_client.context.list() | ||
|
||
|
||
def test_inpect(): | ||
default_context = docker.context.inspect() | ||
def test_inpect(docker_client: DockerClient): | ||
default_context = docker_client.context.inspect() | ||
assert default_context.name == "default" | ||
assert default_context == docker.context.inspect("default") | ||
a, b = docker.context.inspect(["default", "default"]) | ||
assert default_context == docker_client.context.inspect("default") | ||
a, b = docker_client.context.inspect(["default", "default"]) | ||
assert a == b | ||
|
||
|
||
def test_list_contexts(): | ||
assert docker.context.list() == [docker.context.inspect("default")] | ||
def test_list_contexts(docker_client: DockerClient): | ||
assert docker_client.context.list() == [docker_client.context.inspect("default")] | ||
|
||
|
||
def test_use_context(): | ||
docker.context.use("default") | ||
def test_use_context(docker_client: DockerClient): | ||
docker_client.context.use("default") | ||
|
||
|
||
def test_use_context_returns(): | ||
assert docker.context.use("default") == docker.context.inspect("default") | ||
def test_use_context_returns(docker_client: DockerClient): | ||
assert docker_client.context.use("default") == docker_client.context.inspect( | ||
"default" | ||
) | ||
|
||
|
||
def test_remove_empty_context_list(): | ||
all_contexts = set(docker.context.list()) | ||
docker.context.remove([]) | ||
assert all_contexts == set(docker.context.list()) | ||
def test_remove_empty_context_list(docker_client: DockerClient): | ||
all_contexts = set(docker_client.context.list()) | ||
docker_client.context.remove([]) | ||
assert all_contexts == set(docker_client.context.list()) |
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
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
Oops, something went wrong.