Skip to content

Commit

Permalink
Merge branch 'release-0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisNT committed Mar 28, 2016
2 parents 62f1214 + 8e17e10 commit 3535309
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 29 deletions.
11 changes: 9 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://www.mopidy.com/>`_ extension for configurable default playback settings.


Installation
Expand Down Expand Up @@ -58,12 +58,19 @@ Project resources

- `Source code <https://github.com/DavisNT/mopidy-playbackdefaults>`_
- `Issue tracker <https://github.com/DavisNT/mopidy-playbackdefaults/issues>`_
- `Development branch tarball <https://github.com/DavisNT/mopidy-playbackdefaults/archive/master.tar.gz#egg=Mopidy-PlaybackDefaults-dev>`_
- `Development branch tarball <https://github.com/DavisNT/mopidy-playbackdefaults/archive/develop.tar.gz#egg=Mopidy-PlaybackDefaults-dev>`_


Changelog
=========

v0.1.1
----------------------------------------

- Changed branching model to `git-flow <http://nvie.com/posts/a-successful-git-branching-model/>`_.
- Changed extension type from ``http:app`` to ``frontend``.
- Improved unit tests.

v0.1.0
----------------------------------------

Expand Down
37 changes: 20 additions & 17 deletions mopidy_playbackdefaults/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -18,25 +20,26 @@ 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)
schema['default_single'] = config.Boolean(optional=True)
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']
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_version(filename):
],
entry_points={
'mopidy.ext': [
'playbackdefaults = mopidy_playbackdefaults:PDExtension',
'playbackdefaults = mopidy_playbackdefaults:PlaybackDefaultsExtension',
],
},
classifiers=[
Expand Down
15 changes: 6 additions & 9 deletions tests/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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)
105 changes: 105 additions & 0 deletions tests/test_frontend.py
Original file line number Diff line number Diff line change
@@ -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')

0 comments on commit 3535309

Please sign in to comment.