from __future__ import unicode_literals

import unittest

import mock

from mopidy_playbackdefaults import PlaybackDefaultsFrontend


class PlaybackDefaultsFrontendTest(unittest.TestCase):

    def test_no_settings(self):
        config = mock.Mock()
        core = mock.Mock()
        core.tracklist.random = 'untouched'
        core.tracklist.repeat = 'untouched'
        core.tracklist.consume = 'untouched'
        core.tracklist.single = 'untouched'

        frontend = 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 = mock.Mock()
        core = mock.Mock()
        core.tracklist.random = 'untouched'
        core.tracklist.repeat = 'untouched'
        core.tracklist.consume = 'untouched'
        core.tracklist.single = 'untouched'

        config['playbackdefaults']['default_random'] = True
        frontend = PlaybackDefaultsFrontend(config, core)
        self.assertTrue(core.tracklist.random)

        config['playbackdefaults']['default_random'] = False
        frontend = 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 = mock.Mock()
        core = mock.Mock()
        core.tracklist.random = 'untouched'
        core.tracklist.repeat = 'untouched'
        core.tracklist.consume = 'untouched'
        core.tracklist.single = 'untouched'

        config['playbackdefaults']['default_repeat'] = True
        frontend = PlaybackDefaultsFrontend(config, core)
        self.assertTrue(core.tracklist.repeat)

        config['playbackdefaults']['default_repeat'] = False
        frontend = 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 = mock.Mock()
        core = mock.Mock()
        core.tracklist.random = 'untouched'
        core.tracklist.repeat = 'untouched'
        core.tracklist.consume = 'untouched'
        core.tracklist.single = 'untouched'

        config['playbackdefaults']['default_consume'] = True
        frontend = PlaybackDefaultsFrontend(config, core)
        self.assertTrue(core.tracklist.consume)

        config['playbackdefaults']['default_consume'] = False
        frontend = 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 = mock.Mock()
        core = mock.Mock()
        core.tracklist.random = 'untouched'
        core.tracklist.repeat = 'untouched'
        core.tracklist.consume = 'untouched'
        core.tracklist.single = 'untouched'

        config['playbackdefaults']['default_single'] = True
        frontend = PlaybackDefaultsFrontend(config, core)
        self.assertTrue(core.tracklist.single)

        config['playbackdefaults']['default_single'] = False
        frontend = 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')

@@ -228,35 +228,135 @@
    config = 
-mock.Mock()
+%7B'playbackdefaults': %7B'default_random': '', 'default_repeat': '', 'default_consume': '', 'default_single': ''%7D%7D
 %0A        cor
@@ -552,35 +552,24 @@
 ed'%0A%0A       
- frontend =
  PlaybackDef
@@ -883,35 +883,135 @@
    config = 
-mock.Mock()
+%7B'playbackdefaults': %7B'default_random': '', 'default_repeat': '', 'default_consume': '', 'default_single': ''%7D%7D
 %0A        cor
@@ -1267,35 +1267,24 @@
 True%0A       
- frontend =
  PlaybackDef
@@ -1423,35 +1423,24 @@
 alse%0A       
- frontend =
  PlaybackDef
@@ -1741,35 +1741,135 @@
    config = 
-mock.Mock()
+%7B'playbackdefaults': %7B'default_random': '', 'default_repeat': '', 'default_consume': '', 'default_single': ''%7D%7D
 %0A        cor
@@ -2125,35 +2125,24 @@
 True%0A       
- frontend =
  PlaybackDef
@@ -2281,35 +2281,24 @@
 alse%0A       
- frontend =
  PlaybackDef
@@ -2600,35 +2600,135 @@
    config = 
-mock.Mock()
+%7B'playbackdefaults': %7B'default_random': '', 'default_repeat': '', 'default_consume': '', 'default_single': ''%7D%7D
 %0A        cor
@@ -2985,35 +2985,24 @@
 True%0A       
- frontend =
  PlaybackDef
@@ -3143,35 +3143,24 @@
 alse%0A       
- frontend =
  PlaybackDef
@@ -3465,27 +3465,127 @@
 onfig = 
-mock.Mock()
+%7B'playbackdefaults': %7B'default_random': '', 'default_repeat': '', 'default_consume': '', 'default_single': ''%7D%7D
 %0A       
@@ -3845,35 +3845,24 @@
 True%0A       
- frontend =
  PlaybackDef
@@ -4002,26 +4002,15 @@
 lse%0A
+
        
- frontend =
  Pla

Fix new unittests