mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-18 06:36:30 +00:00
Add test for denylist (#1914)
* Add test for denylist * Mock API in conftest
This commit is contained in:
parent
930eed4500
commit
f5f5f829ac
@ -4,15 +4,26 @@ from unittest.mock import MagicMock, PropertyMock, patch
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from supervisor.bootstrap import initialize_coresys
|
from supervisor.bootstrap import initialize_coresys
|
||||||
|
from supervisor.docker import DockerAPI
|
||||||
|
|
||||||
# pylint: disable=redefined-outer-name, protected-access
|
# pylint: disable=redefined-outer-name, protected-access
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def docker():
|
def docker():
|
||||||
"""Mock Docker API."""
|
"""Mock DockerAPI."""
|
||||||
with patch("supervisor.coresys.DockerAPI") as mock:
|
images = [MagicMock(tags=["homeassistant/amd64-hassio-supervisor:latest"])]
|
||||||
yield mock
|
|
||||||
|
with patch("docker.DockerClient", return_value=MagicMock()), patch(
|
||||||
|
"supervisor.docker.DockerAPI.images", return_value=MagicMock()
|
||||||
|
), patch("supervisor.docker.DockerAPI.containers", return_value=MagicMock()), patch(
|
||||||
|
"supervisor.docker.DockerAPI.api", return_value=MagicMock()
|
||||||
|
), patch(
|
||||||
|
"supervisor.docker.DockerAPI.images.list", return_value=images
|
||||||
|
):
|
||||||
|
docker_obj = DockerAPI()
|
||||||
|
|
||||||
|
yield docker_obj
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
15
tests/docker/test_denylist.py
Normal file
15
tests/docker/test_denylist.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
"""Test tags in denylist."""
|
||||||
|
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
|
||||||
|
def test_has_images_in_denylist(docker):
|
||||||
|
"""Test tags in denylist exsist."""
|
||||||
|
images = [MagicMock(tags=["containrrr/watchtower:latest"])]
|
||||||
|
with patch("supervisor.docker.DockerAPI.images.list", return_value=images):
|
||||||
|
assert docker.check_denylist_images()
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_images_in_denylist(docker):
|
||||||
|
"""Test tags in denylist does not exsist."""
|
||||||
|
assert not docker.check_denylist_images()
|
Loading…
x
Reference in New Issue
Block a user