import unittest

from mopidy_spotify import Extension, backend as backend_lib


class ExtensionTest(unittest.TestCase):

    def test_get_default_config(self):
        ext = Extension()

        config = ext.get_default_config()

        self.assertIn('[spotify]', config)
        self.assertIn('enabled = true', config)

    def test_get_config_schema(self):
        ext = Extension()

        schema = ext.get_config_schema()

        self.assertIn('username', schema)
        self.assertIn('password', schema)
        self.assertIn('bitrate', schema)
        self.assertIn('timeout', schema)
        self.assertIn('cache_dir', schema)

    def test_get_backend_classes(self):
        ext = Extension()

        backends = ext.get_backend_classes()

        self.assertIn(backend_lib.SpotifyBackend, backends)

import mock, unittest

from mopidy_spotify import Extension, backend as backend_lib


class ExtensionTest(unittest.TestCase):

    def test_get_default_config(self):
        ext = Extension()

        config = ext.get_default_config()

        self.assertIn('[spotify]', config)
        self.assertIn('enabled = true', config)

    def test_get_config_schema(self):
        ext = Extension()

        schema = ext.get_config_schema()

        self.assertIn('username', schema)
        self.assertIn('password', schema)
        self.assertIn('bitrate', schema)
        self.assertIn('timeout', schema)
        self.assertIn('cache_dir', schema)

    def test_setup(self):
        registry = mock.Mock()

        ext = Extension()
        ext.setup(registry)

        registry.add.assert_called_with('backend', backend_lib.SpotifyBackend)

Test extension with mock registry
Test extension with mock registry

- import unittest
+ import mock, unittest
  
  from mopidy_spotify import Extension, backend as backend_lib
  
  
  class ExtensionTest(unittest.TestCase):
  
      def test_get_default_config(self):
          ext = Extension()
  
          config = ext.get_default_config()
  
          self.assertIn('[spotify]', config)
          self.assertIn('enabled = true', config)
  
      def test_get_config_schema(self):
          ext = Extension()
  
          schema = ext.get_config_schema()
  
          self.assertIn('username', schema)
          self.assertIn('password', schema)
          self.assertIn('bitrate', schema)
          self.assertIn('timeout', schema)
          self.assertIn('cache_dir', schema)
  
-     def test_get_backend_classes(self):
+     def test_setup(self):
+         registry = mock.Mock()
+ 
          ext = Extension()
+         ext.setup(registry)
  
-         backends = ext.get_backend_classes()
+         registry.add.assert_called_with('backend', backend_lib.SpotifyBackend)
  
-         self.assertIn(backend_lib.SpotifyBackend, backends)
- 
Test extension with mock registry
## Code Before:
import unittest

from mopidy_spotify import Extension, backend as backend_lib


class ExtensionTest(unittest.TestCase):

    def test_get_default_config(self):
        ext = Extension()

        config = ext.get_default_config()

        self.assertIn('[spotify]', config)
        self.assertIn('enabled = true', config)

    def test_get_config_schema(self):
        ext = Extension()

        schema = ext.get_config_schema()

        self.assertIn('username', schema)
        self.assertIn('password', schema)
        self.assertIn('bitrate', schema)
        self.assertIn('timeout', schema)
        self.assertIn('cache_dir', schema)

    def test_get_backend_classes(self):
        ext = Extension()

        backends = ext.get_backend_classes()

        self.assertIn(backend_lib.SpotifyBackend, backends)

## Instruction:
Test extension with mock registry
## Code After:
import mock, unittest

from mopidy_spotify import Extension, backend as backend_lib


class ExtensionTest(unittest.TestCase):

    def test_get_default_config(self):
        ext = Extension()

        config = ext.get_default_config()

        self.assertIn('[spotify]', config)
        self.assertIn('enabled = true', config)

    def test_get_config_schema(self):
        ext = Extension()

        schema = ext.get_config_schema()

        self.assertIn('username', schema)
        self.assertIn('password', schema)
        self.assertIn('bitrate', schema)
        self.assertIn('timeout', schema)
        self.assertIn('cache_dir', schema)

    def test_setup(self):
        registry = mock.Mock()

        ext = Extension()
        ext.setup(registry)

        registry.add.assert_called_with('backend', backend_lib.SpotifyBackend)
