diff --git a/README.rst b/README.rst
index 8b8f7d4..858bae1 100644
--- a/README.rst
+++ b/README.rst
@@ -18,7 +18,7 @@ Mopidy-PlaybackDefaults
:target: https://coveralls.io/r/DavisNT/mopidy-playbackdefaults
:alt: Coveralls test coverage
-Mopidy extension for configurable default playback settings.
+`Mopidy `_ extension for configurable default playback settings.
Installation
@@ -58,12 +58,19 @@ Project resources
- `Source code `_
- `Issue tracker `_
-- `Development branch tarball `_
+- `Development branch tarball `_
Changelog
=========
+v0.1.1
+----------------------------------------
+
+- Changed branching model to `git-flow `_.
+- Changed extension type from ``http:app`` to ``frontend``.
+- Improved unit tests.
+
v0.1.0
----------------------------------------
diff --git a/mopidy_playbackdefaults/__init__.py b/mopidy_playbackdefaults/__init__.py
index e5f844a..c8ef014 100644
--- a/mopidy_playbackdefaults/__init__.py
+++ b/mopidy_playbackdefaults/__init__.py
@@ -4,10 +4,12 @@
from mopidy import config, ext
-__version__ = '0.1.0'
+import pykka
+__version__ = '0.1.1'
-class PDExtension(ext.Extension):
+
+class PlaybackDefaultsExtension(ext.Extension):
dist_name = 'Mopidy-PlaybackDefaults'
ext_name = 'playbackdefaults'
@@ -18,7 +20,7 @@ def get_default_config(self):
return config.read(conf_file)
def get_config_schema(self):
- schema = super(PDExtension, self).get_config_schema()
+ schema = super(PlaybackDefaultsExtension, self).get_config_schema()
schema['default_random'] = config.Boolean(optional=True)
schema['default_repeat'] = config.Boolean(optional=True)
schema['default_consume'] = config.Boolean(optional=True)
@@ -26,17 +28,18 @@ def get_config_schema(self):
return schema
def setup(self, registry):
- registry.add(
- 'http:app', {'name': self.ext_name, 'factory': self.factory})
-
- def factory(self, config, core):
- if type(config[PDExtension.ext_name]['default_random']) is bool:
- core.tracklist.random = config[PDExtension.ext_name]['default_random']
- if type(config[PDExtension.ext_name]['default_repeat']) is bool:
- core.tracklist.repeat = config[PDExtension.ext_name]['default_repeat']
- if type(config[PDExtension.ext_name]['default_consume']) is bool:
- core.tracklist.consume = config[PDExtension.ext_name]['default_consume']
- if type(config[PDExtension.ext_name]['default_single']) is bool:
- core.tracklist.single = config[PDExtension.ext_name]['default_single']
-
- return []
+ registry.add('frontend', PlaybackDefaultsFrontend)
+
+
+class PlaybackDefaultsFrontend(pykka.ThreadingActor):
+ def __init__(self, config, core):
+ super(PlaybackDefaultsFrontend, self).__init__()
+
+ if type(config[PlaybackDefaultsExtension.ext_name]['default_random']) is bool:
+ core.tracklist.random = config[PlaybackDefaultsExtension.ext_name]['default_random']
+ if type(config[PlaybackDefaultsExtension.ext_name]['default_repeat']) is bool:
+ core.tracklist.repeat = config[PlaybackDefaultsExtension.ext_name]['default_repeat']
+ if type(config[PlaybackDefaultsExtension.ext_name]['default_consume']) is bool:
+ core.tracklist.consume = config[PlaybackDefaultsExtension.ext_name]['default_consume']
+ if type(config[PlaybackDefaultsExtension.ext_name]['default_single']) is bool:
+ core.tracklist.single = config[PlaybackDefaultsExtension.ext_name]['default_single']
diff --git a/setup.py b/setup.py
index c0cbfde..9e69977 100644
--- a/setup.py
+++ b/setup.py
@@ -35,7 +35,7 @@ def get_version(filename):
],
entry_points={
'mopidy.ext': [
- 'playbackdefaults = mopidy_playbackdefaults:PDExtension',
+ 'playbackdefaults = mopidy_playbackdefaults:PlaybackDefaultsExtension',
],
},
classifiers=[
diff --git a/tests/test_extension.py b/tests/test_extension.py
index a3ab1c7..d428c03 100644
--- a/tests/test_extension.py
+++ b/tests/test_extension.py
@@ -4,13 +4,13 @@
import mock
-from mopidy_playbackdefaults import PDExtension
+from mopidy_playbackdefaults import PlaybackDefaultsExtension, PlaybackDefaultsFrontend
-class PDExtensionTest(unittest.TestCase):
+class PlaybackDefaultsExtensionTest(unittest.TestCase):
def test_get_default_config(self):
- ext = PDExtension()
+ ext = PlaybackDefaultsExtension()
config = ext.get_default_config()
@@ -22,7 +22,7 @@ def test_get_default_config(self):
self.assertIn('default_single =', config)
def test_get_config_schema(self):
- ext = PDExtension()
+ ext = PlaybackDefaultsExtension()
schema = ext.get_config_schema()
@@ -35,10 +35,7 @@ def test_get_config_schema(self):
def test_setup(self):
registry = mock.Mock()
- ext = PDExtension()
+ ext = PlaybackDefaultsExtension()
ext.setup(registry)
- registry.add.assert_called_once_with('http:app', {
- 'name': 'playbackdefaults',
- 'factory': registry.add.call_args[0][1]['factory'],
- })
+ registry.add.assert_called_once_with('frontend', PlaybackDefaultsFrontend)
diff --git a/tests/test_frontend.py b/tests/test_frontend.py
new file mode 100644
index 0000000..7a15187
--- /dev/null
+++ b/tests/test_frontend.py
@@ -0,0 +1,105 @@
+from __future__ import unicode_literals
+
+import unittest
+
+import mock
+
+from mopidy_playbackdefaults import PlaybackDefaultsFrontend
+
+
+class PlaybackDefaultsFrontendTest(unittest.TestCase):
+
+ def test_no_settings(self):
+ config = {'playbackdefaults': {'default_random': '', 'default_repeat': '', 'default_consume': '', 'default_single': ''}}
+ core = mock.Mock()
+ core.tracklist.random = 'untouched'
+ core.tracklist.repeat = 'untouched'
+ core.tracklist.consume = 'untouched'
+ core.tracklist.single = 'untouched'
+
+ PlaybackDefaultsFrontend(config, core)
+
+ self.assertEqual(core.tracklist.random, 'untouched')
+ self.assertEqual(core.tracklist.repeat, 'untouched')
+ self.assertEqual(core.tracklist.consume, 'untouched')
+ self.assertEqual(core.tracklist.single, 'untouched')
+
+ def test_random(self):
+ config = {'playbackdefaults': {'default_random': '', 'default_repeat': '', 'default_consume': '', 'default_single': ''}}
+ core = mock.Mock()
+ core.tracklist.random = 'untouched'
+ core.tracklist.repeat = 'untouched'
+ core.tracklist.consume = 'untouched'
+ core.tracklist.single = 'untouched'
+
+ config['playbackdefaults']['default_random'] = True
+ PlaybackDefaultsFrontend(config, core)
+ self.assertTrue(core.tracklist.random)
+
+ config['playbackdefaults']['default_random'] = False
+ PlaybackDefaultsFrontend(config, core)
+ self.assertFalse(core.tracklist.random)
+
+ self.assertEqual(core.tracklist.repeat, 'untouched')
+ self.assertEqual(core.tracklist.consume, 'untouched')
+ self.assertEqual(core.tracklist.single, 'untouched')
+
+ def test_repeat(self):
+ config = {'playbackdefaults': {'default_random': '', 'default_repeat': '', 'default_consume': '', 'default_single': ''}}
+ core = mock.Mock()
+ core.tracklist.random = 'untouched'
+ core.tracklist.repeat = 'untouched'
+ core.tracklist.consume = 'untouched'
+ core.tracklist.single = 'untouched'
+
+ config['playbackdefaults']['default_repeat'] = True
+ PlaybackDefaultsFrontend(config, core)
+ self.assertTrue(core.tracklist.repeat)
+
+ config['playbackdefaults']['default_repeat'] = False
+ PlaybackDefaultsFrontend(config, core)
+ self.assertFalse(core.tracklist.repeat)
+
+ self.assertEqual(core.tracklist.random, 'untouched')
+ self.assertEqual(core.tracklist.consume, 'untouched')
+ self.assertEqual(core.tracklist.single, 'untouched')
+
+ def test_consume(self):
+ config = {'playbackdefaults': {'default_random': '', 'default_repeat': '', 'default_consume': '', 'default_single': ''}}
+ core = mock.Mock()
+ core.tracklist.random = 'untouched'
+ core.tracklist.repeat = 'untouched'
+ core.tracklist.consume = 'untouched'
+ core.tracklist.single = 'untouched'
+
+ config['playbackdefaults']['default_consume'] = True
+ PlaybackDefaultsFrontend(config, core)
+ self.assertTrue(core.tracklist.consume)
+
+ config['playbackdefaults']['default_consume'] = False
+ PlaybackDefaultsFrontend(config, core)
+ self.assertFalse(core.tracklist.consume)
+
+ self.assertEqual(core.tracklist.random, 'untouched')
+ self.assertEqual(core.tracklist.repeat, 'untouched')
+ self.assertEqual(core.tracklist.single, 'untouched')
+
+ def test_single(self):
+ config = {'playbackdefaults': {'default_random': '', 'default_repeat': '', 'default_consume': '', 'default_single': ''}}
+ core = mock.Mock()
+ core.tracklist.random = 'untouched'
+ core.tracklist.repeat = 'untouched'
+ core.tracklist.consume = 'untouched'
+ core.tracklist.single = 'untouched'
+
+ config['playbackdefaults']['default_single'] = True
+ PlaybackDefaultsFrontend(config, core)
+ self.assertTrue(core.tracklist.single)
+
+ config['playbackdefaults']['default_single'] = False
+ PlaybackDefaultsFrontend(config, core)
+ self.assertFalse(core.tracklist.single)
+
+ self.assertEqual(core.tracklist.random, 'untouched')
+ self.assertEqual(core.tracklist.repeat, 'untouched')
+ self.assertEqual(core.tracklist.consume, 'untouched')