docs:address PR review comments.
This commit is contained in:
parent
05729d3dc0
commit
edc3929daf
@ -576,6 +576,7 @@ part of the extension.
|
|||||||
|
|
||||||
Testing the extension definition
|
Testing the extension definition
|
||||||
--------------------------------
|
--------------------------------
|
||||||
|
|
||||||
Test cases for checking the definition of the extension should ensure that:
|
Test cases for checking the definition of the extension should ensure that:
|
||||||
|
|
||||||
- the extension provides a ``ext.conf`` configuration file containing the
|
- the extension provides a ``ext.conf`` configuration file containing the
|
||||||
@ -589,20 +590,20 @@ An example of what these tests could look like is provided below::
|
|||||||
ext = Extension()
|
ext = Extension()
|
||||||
config = ext.get_default_config()
|
config = ext.get_default_config()
|
||||||
|
|
||||||
self.assertIn('[my_extension]', config)
|
assert '[my_extension]' in config
|
||||||
self.assertIn('enabled = true', config)
|
assert 'enabled = true' in config
|
||||||
self.assertIn('param_1 = value_1', config)
|
assert 'param_1 = value_1' in config
|
||||||
self.assertIn('param_2 = value_2', config)
|
assert 'param_2 = value_2' in config
|
||||||
self.assertIn('param_n = value_n', config)
|
assert 'param_n = value_n' in config
|
||||||
|
|
||||||
def test_get_config_schema(self):
|
def test_get_config_schema(self):
|
||||||
ext = Extension()
|
ext = Extension()
|
||||||
schema = ext.get_config_schema()
|
schema = ext.get_config_schema()
|
||||||
|
|
||||||
self.assertIn('enabled', schema)
|
assert 'enabled' in schema
|
||||||
self.assertIn('param_1', schema)
|
assert 'param_1' in schema
|
||||||
self.assertIn('param_2', schema)
|
assert 'param_2' in schema
|
||||||
self.assertIn('param_n', schema)
|
assert 'param_n' in schema
|
||||||
|
|
||||||
def test_setup(self):
|
def test_setup(self):
|
||||||
registry = mock.Mock()
|
registry = mock.Mock()
|
||||||
@ -616,10 +617,11 @@ An example of what these tests could look like is provided below::
|
|||||||
|
|
||||||
Testing backend actors
|
Testing backend actors
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
Backends can usually be constructed with a small mockup of the configuration
|
Backends can usually be constructed with a small mockup of the configuration
|
||||||
file, and mocking the audio actor::
|
file, and mocking the audio actor::
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture
|
||||||
def config():
|
def config():
|
||||||
return {
|
return {
|
||||||
'http': {
|
'http': {
|
||||||
@ -641,10 +643,17 @@ file, and mocking the audio actor::
|
|||||||
def get_backend(config):
|
def get_backend(config):
|
||||||
return backend.MyBackend(config=config, audio=mock.Mock())
|
return backend.MyBackend(config=config, audio=mock.Mock())
|
||||||
|
|
||||||
|
The following libraries might be useful for mocking any HTTP requests that
|
||||||
|
your extension makes:
|
||||||
|
|
||||||
You'll probably want to patch ``requests`` or any other web API's that you use
|
- `responses <https://pypi.python.org/pypi/responses>`_ - A utility library for
|
||||||
to avoid any unintended HTTP requests from being made by your backend during
|
mocking out the requests Python library.
|
||||||
testing::
|
- `vcrpy <https://pypi.python.org/pypi/vcrpy>`_ - Automatically mock your HTTP
|
||||||
|
interactions to simplify and speed up testing.
|
||||||
|
|
||||||
|
At the very least, you'll probably want to patch ``requests`` or any other web
|
||||||
|
API's that you use to avoid any unintended HTTP requests from being made by
|
||||||
|
your backend during testing::
|
||||||
|
|
||||||
from mock import patch
|
from mock import patch
|
||||||
@mock.patch('requests.get',
|
@mock.patch('requests.get',
|
||||||
@ -654,7 +663,9 @@ testing::
|
|||||||
Backend tests should also ensure that:
|
Backend tests should also ensure that:
|
||||||
|
|
||||||
- the backend provides a unique URI scheme,
|
- the backend provides a unique URI scheme,
|
||||||
- that it sets up the various providers (e.g. library, playback, etc.)::
|
- that it sets up the various providers (e.g. library, playback, etc.)
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
def test_uri_schemes(config):
|
def test_uri_schemes(config):
|
||||||
backend = get_backend(config)
|
backend = get_backend(config)
|
||||||
@ -675,18 +686,21 @@ special setup or processing.
|
|||||||
|
|
||||||
Testing libraries
|
Testing libraries
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
Library test cases should cover the implementations of the standard Mopidy
|
Library test cases should cover the implementations of the standard Mopidy
|
||||||
API (e.g. ``browse``, ``lookup``, ``refresh``, ``get_images``, ``search``,
|
API (e.g. ``browse``, ``lookup``, ``refresh``, ``get_images``, ``search``,
|
||||||
etc.)
|
etc.)
|
||||||
|
|
||||||
Testing playback controllers
|
Testing playback controllers
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
Testing ``change_track`` and ``translate_uri`` is probably the highest
|
Testing ``change_track`` and ``translate_uri`` is probably the highest
|
||||||
priority, since these methods are used to prepare the track and provide its
|
priority, since these methods are used to prepare the track and provide its
|
||||||
audio URL to Mopidy's core for playback.
|
audio URL to Mopidy's core for playback.
|
||||||
|
|
||||||
Testing frontends
|
Testing frontends
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
Because most frontends will interact with the Mopidy core, it will most likely
|
Because most frontends will interact with the Mopidy core, it will most likely
|
||||||
be necessary to have a full core running for testing purposes::
|
be necessary to have a full core running for testing purposes::
|
||||||
|
|
||||||
@ -700,8 +714,9 @@ you are familiar with ``ThreadingActor``, ``ThreadingFuture``, and the
|
|||||||
``proxies`` that allow you to access the attributes and methods of the actor
|
``proxies`` that allow you to access the attributes and methods of the actor
|
||||||
directly.
|
directly.
|
||||||
|
|
||||||
You'll also need a list of ``models.Track`` and a list of URIs in order to
|
You'll also need a list of :class:`~mopidy.models.Track` and a list of URIs in
|
||||||
populate the core with some simple tracks that can be used for testing::
|
order to populate the core with some simple tracks that can be used for
|
||||||
|
testing::
|
||||||
|
|
||||||
class BaseTest(unittest.TestCase):
|
class BaseTest(unittest.TestCase):
|
||||||
tracks = [
|
tracks = [
|
||||||
@ -738,6 +753,7 @@ the end of most method calls in order to get to the actual return values.
|
|||||||
|
|
||||||
Triggering events
|
Triggering events
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
There may be test case scenarios that require simulating certain event triggers
|
There may be test case scenarios that require simulating certain event triggers
|
||||||
that your extension's actors can listen for and respond on. An example for
|
that your extension's actors can listen for and respond on. An example for
|
||||||
patching the listener to store these events, and then play them back for your
|
patching the listener to store these events, and then play them back for your
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user