Migrate reflection_test

This commit is contained in:
Thomas Adamcik 2011-07-20 20:09:58 +02:00
parent 730368dbeb
commit b445af7cfb
3 changed files with 68 additions and 79 deletions

View File

@ -1,6 +1,7 @@
import unittest import unittest
import mock import mock
from mopidy import settings
from mopidy.backends import dummy as backend from mopidy.backends import dummy as backend
from mopidy.frontends import mpd from mopidy.frontends import mpd
from mopidy.frontends.mpd import dispatcher from mopidy.frontends.mpd import dispatcher
@ -32,6 +33,7 @@ class BaseTestCase(unittest.TestCase):
def tearDown(self): def tearDown(self):
self.backend.stop().get() self.backend.stop().get()
self.mixer.stop().get() self.mixer.stop().get()
settings.runtime.clear()
def sendRequest(self, request, clear=False): def sendRequest(self, request, clear=False):
self.connection.response = [] self.connection.response = []

View File

@ -0,0 +1,66 @@
from mopidy import settings
from tests.frontends.mpd import protocol
class ReflectionHandlerTest(protocol.BaseTestCase):
def test_commands_returns_list_of_all_commands(self):
self.sendRequest(u'commands')
# Check if some random commands are included
self.assertInResponse(u'command: commands')
self.assertInResponse(u'command: play')
self.assertInResponse(u'command: status')
# Check if commands you do not have access to are not present
self.assertNotInResponse(u'command: kill')
# Check if the blacklisted commands are not present
self.assertNotInResponse(u'command: command_list_begin')
self.assertNotInResponse(u'command: command_list_ok_begin')
self.assertNotInResponse(u'command: command_list_end')
self.assertNotInResponse(u'command: idle')
self.assertNotInResponse(u'command: noidle')
self.assertNotInResponse(u'command: sticker')
self.assertInResponse(u'OK')
def test_commands_show_less_if_auth_required_and_not_authed(self):
settings.MPD_SERVER_PASSWORD = u'secret'
self.sendRequest(u'commands')
# Not requiring auth
self.assertInResponse(u'command: close')
self.assertInResponse(u'command: commands')
self.assertInResponse(u'command: notcommands')
self.assertInResponse(u'command: password')
self.assertInResponse(u'command: ping')
# Requiring auth
self.assertNotInResponse(u'command: play')
self.assertNotInResponse(u'command: status')
def test_decoders(self):
self.sendRequest(u'decoders')
self.assertInResponse(u'ACK [0@0] {} Not implemented')
def test_notcommands_returns_only_kill_and_ok(self):
response = self.sendRequest(u'notcommands')
self.assertEqual(2, len(response))
self.assertInResponse(u'command: kill')
self.assertInResponse(u'OK')
def test_notcommands_returns_more_if_auth_required_and_not_authed(self):
settings.MPD_SERVER_PASSWORD = u'secret'
self.sendRequest(u'notcommands')
# Not requiring auth
self.assertNotInResponse(u'command: close')
self.assertNotInResponse(u'command: commands')
self.assertNotInResponse(u'command: notcommands')
self.assertNotInResponse(u'command: password')
self.assertNotInResponse(u'command: ping')
# Requiring auth
self.assertInResponse(u'command: play')
self.assertInResponse(u'command: status')
def test_tagtypes(self):
self.sendRequest(u'tagtypes')
self.assertInResponse(u'OK')
def test_urlhandlers(self):
self.sendRequest(u'urlhandlers')
self.assertInResponse(u'OK')
self.assertInResponse(u'handler: dummy')

View File

@ -1,79 +0,0 @@
import unittest
from mopidy import settings
from mopidy.backends.dummy import DummyBackend
from mopidy.frontends.mpd.dispatcher import MpdDispatcher
from mopidy.mixers.dummy import DummyMixer
class ReflectionHandlerTest(unittest.TestCase):
def setUp(self):
self.backend = DummyBackend.start().proxy()
self.mixer = DummyMixer.start().proxy()
self.dispatcher = MpdDispatcher()
def tearDown(self):
settings.runtime.clear()
self.backend.stop().get()
self.mixer.stop().get()
def test_commands_returns_list_of_all_commands(self):
result = self.dispatcher.handle_request(u'commands')
# Check if some random commands are included
self.assert_(u'command: commands' in result)
self.assert_(u'command: play' in result)
self.assert_(u'command: status' in result)
# Check if commands you do not have access to are not present
self.assert_(u'command: kill' not in result)
# Check if the blacklisted commands are not present
self.assert_(u'command: command_list_begin' not in result)
self.assert_(u'command: command_list_ok_begin' not in result)
self.assert_(u'command: command_list_end' not in result)
self.assert_(u'command: idle' not in result)
self.assert_(u'command: noidle' not in result)
self.assert_(u'command: sticker' not in result)
self.assert_(u'OK' in result)
def test_commands_show_less_if_auth_required_and_not_authed(self):
settings.MPD_SERVER_PASSWORD = u'secret'
result = self.dispatcher.handle_request(u'commands')
# Not requiring auth
self.assert_(u'command: close' in result, result)
self.assert_(u'command: commands' in result, result)
self.assert_(u'command: notcommands' in result, result)
self.assert_(u'command: password' in result, result)
self.assert_(u'command: ping' in result, result)
# Requiring auth
self.assert_(u'command: play' not in result, result)
self.assert_(u'command: status' not in result, result)
def test_decoders(self):
result = self.dispatcher.handle_request(u'decoders')
self.assert_(u'ACK [0@0] {} Not implemented' in result)
def test_notcommands_returns_only_kill_and_ok(self):
result = self.dispatcher.handle_request(u'notcommands')
self.assertEqual(2, len(result))
self.assert_(u'command: kill' in result)
self.assert_(u'OK' in result)
def test_notcommands_returns_more_if_auth_required_and_not_authed(self):
settings.MPD_SERVER_PASSWORD = u'secret'
result = self.dispatcher.handle_request(u'notcommands')
# Not requiring auth
self.assert_(u'command: close' not in result, result)
self.assert_(u'command: commands' not in result, result)
self.assert_(u'command: notcommands' not in result, result)
self.assert_(u'command: password' not in result, result)
self.assert_(u'command: ping' not in result, result)
# Requiring auth
self.assert_(u'command: play' in result, result)
self.assert_(u'command: status' in result, result)
def test_tagtypes(self):
result = self.dispatcher.handle_request(u'tagtypes')
self.assert_(u'OK' in result)
def test_urlhandlers(self):
result = self.dispatcher.handle_request(u'urlhandlers')
self.assert_(u'OK' in result)
self.assert_(u'handler: dummy' in result)