Skip to content

Commit

Permalink
Move mocked soco fixture to conftest (#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjlawren authored and pwt committed Mar 2, 2022
1 parent 1dc6281 commit ef70f01
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 64 deletions.
35 changes: 32 additions & 3 deletions tests/conftest.py
Expand Up @@ -3,16 +3,45 @@
Add the --ip command line option, and skip all tests marked the with
'integration' marker unless the option is included
"""
from os import path
import json
import codecs

import json
from os import path
from unittest import mock

import pytest
from soco import SoCo

IP_ADDR = "192.168.1.101"
THISDIR = path.dirname(path.abspath(__file__))


@pytest.fixture()
def moco():
"""A mock soco with fake services and hardcoded is_coordinator.
Allows calls to services to be tracked. Should not cause any network
access
"""
services = (
"AVTransport",
"RenderingControl",
"DeviceProperties",
"ContentDirectory",
"ZoneGroupTopology",
"GroupRenderingControl",
)
patchers = [mock.patch("soco.core.{}".format(service)) for service in services]
for patch in patchers:
patch.start()
with mock.patch(
"soco.SoCo.is_coordinator", new_callable=mock.PropertyMock
) as is_coord:
is_coord = True # noqa: F841
yield SoCo(IP_ADDR)
for patch in reversed(patchers):
patch.stop()


def pytest_addoption(parser):
"""Add the --ip commandline option"""
parser.addoption(
Expand Down
30 changes: 1 addition & 29 deletions tests/test_core.py
Expand Up @@ -2,6 +2,7 @@
import pytest
import requests_mock

from conftest import IP_ADDR
from soco import SoCo
from soco.data_structures import to_didl_string
from soco.exceptions import (
Expand All @@ -13,35 +14,6 @@
from soco.groups import ZoneGroup
from soco.xml import XML

IP_ADDR = "192.168.1.101"


@pytest.fixture()
def moco():
"""A mock soco with fake services and hardcoded is_coordinator.
Allows calls to services to be tracked. Should not cause any network
access
"""
services = (
"AVTransport",
"RenderingControl",
"DeviceProperties",
"ContentDirectory",
"ZoneGroupTopology",
"GroupRenderingControl",
)
patchers = [mock.patch("soco.core.{}".format(service)) for service in services]
for patch in patchers:
patch.start()
with mock.patch(
"soco.SoCo.is_coordinator", new_callable=mock.PropertyMock
) as is_coord:
is_coord = True # noqa: F841
yield SoCo(IP_ADDR)
for patch in reversed(patchers):
patch.stop()


@pytest.fixture()
def moco_only_on_master():
Expand Down
32 changes: 0 additions & 32 deletions tests/test_music_library.py
@@ -1,37 +1,5 @@
from unittest import mock
import pytest

from soco import SoCo
from soco.exceptions import SoCoUPnPException

IP_ADDR = "192.168.1.101"


@pytest.fixture()
def moco():
"""A mock soco with fake services and hardcoded is_coordinator.
Allows calls to services to be tracked. Should not cause any network
access
"""
services = (
"AVTransport",
"RenderingControl",
"DeviceProperties",
"ContentDirectory",
"ZoneGroupTopology",
)
patchers = [mock.patch("soco.core.{}".format(service)) for service in services]
for patch in patchers:
patch.start()
with mock.patch(
"soco.SoCo.is_coordinator", new_callable=mock.PropertyMock
) as is_coord:
is_coord = True # noqa: F841
yield SoCo(IP_ADDR)
for patch in reversed(patchers):
patch.stop()


class TestMusicLibrary:
def test_search_track_no_result(self, moco):
Expand Down

0 comments on commit ef70f01

Please sign in to comment.