http: Test serving og legacy static_dir apps

This commit is contained in:
Stein Magnus Jodal 2014-06-22 01:22:22 +02:00
parent 5861071bb1
commit 6596871918

View File

@ -12,8 +12,8 @@ from mopidy.http import actor, handlers
class HttpServerTest(tornado.testing.AsyncHTTPTestCase): class HttpServerTest(tornado.testing.AsyncHTTPTestCase):
def get_app(self): def get_config(self):
config = { return {
'http': { 'http': {
'hostname': '127.0.0.1', 'hostname': '127.0.0.1',
'port': 6680, 'port': 6680,
@ -21,6 +21,8 @@ class HttpServerTest(tornado.testing.AsyncHTTPTestCase):
'zeroconf': '', 'zeroconf': '',
} }
} }
def get_app(self):
core = mock.Mock() core = mock.Mock()
core.get_version = mock.MagicMock(name='get_version') core.get_version = mock.MagicMock(name='get_version')
core.get_version.return_value = mopidy.__version__ core.get_version.return_value = mopidy.__version__
@ -28,7 +30,7 @@ class HttpServerTest(tornado.testing.AsyncHTTPTestCase):
apps = [dict(name='testapp')] apps = [dict(name='testapp')]
statics = [dict(name='teststatic')] statics = [dict(name='teststatic')]
http_frontend = actor.HttpFrontend(config=config, core=core) http_frontend = actor.HttpFrontend(config=self.get_config(), core=core)
http_frontend.apps = [{ http_frontend.apps = [{
'name': 'mopidy', 'name': 'mopidy',
'factory': handlers.make_mopidy_app_factory(apps, statics), 'factory': handlers.make_mopidy_app_factory(apps, statics),
@ -57,6 +59,28 @@ class RootAppTest(HttpServerTest):
self.assertEqual(response.headers['Cache-Control'], 'no-cache') self.assertEqual(response.headers['Cache-Control'], 'no-cache')
class LegacyStaticDirAppTest(HttpServerTest):
def get_config(self):
config = super(LegacyStaticDirAppTest, self).get_config()
config['http']['static_dir'] = os.path.dirname(__file__)
return config
def test_should_return_index(self):
response = self.fetch('/', method='GET', follow_redirects=False)
self.assertEqual(response.code, 404, 'No index.html in this dir')
def test_should_return_static_files(self):
response = self.fetch('/test_server.py', method='GET')
self.assertIn(
'test_should_return_static_files',
tornado.escape.to_unicode(response.body))
self.assertEqual(
response.headers['X-Mopidy-Version'], mopidy.__version__)
self.assertEqual(response.headers['Cache-Control'], 'no-cache')
class MopidyAppTest(HttpServerTest): class MopidyAppTest(HttpServerTest):
def test_should_return_index(self): def test_should_return_index(self):
response = self.fetch('/mopidy/', method='GET') response = self.fetch('/mopidy/', method='GET')