2013-09-19 21:02:28 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# Copyright (c) 2008-2013 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
|
|
|
|
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
|
|
|
|
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
|
|
|
|
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
|
|
|
|
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
|
|
|
|
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
|
|
|
|
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
2013-03-29 08:25:33 +00:00
|
|
|
"""
|
|
|
|
This module contains tests for the lib submodule of the Remotes plugin.
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
from unittest import TestCase
|
|
|
|
from tempfile import mkstemp
|
2013-09-19 21:02:28 +00:00
|
|
|
|
|
|
|
from PyQt4 import QtGui
|
2013-03-29 08:25:33 +00:00
|
|
|
|
|
|
|
from openlp.core.lib import Settings
|
2013-09-14 21:00:58 +00:00
|
|
|
from openlp.plugins.remotes.lib.httpserver import HttpRouter
|
2013-09-19 21:02:28 +00:00
|
|
|
from tests.functional import MagicMock
|
2013-03-29 08:25:33 +00:00
|
|
|
|
|
|
|
__default_settings__ = {
|
2013-08-31 18:17:38 +00:00
|
|
|
'remotes/twelve hour': True,
|
|
|
|
'remotes/port': 4316,
|
|
|
|
'remotes/https port': 4317,
|
|
|
|
'remotes/https enabled': False,
|
|
|
|
'remotes/user id': 'openlp',
|
|
|
|
'remotes/password': 'password',
|
|
|
|
'remotes/authentication enabled': False,
|
|
|
|
'remotes/ip address': '0.0.0.0'
|
2013-03-29 08:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-29 09:06:43 +00:00
|
|
|
class TestRouter(TestCase):
|
2013-03-29 08:25:33 +00:00
|
|
|
"""
|
|
|
|
Test the functions in the :mod:`lib` module.
|
|
|
|
"""
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Create the UI
|
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
fd, self.ini_file = mkstemp('.ini')
|
2013-03-29 08:25:33 +00:00
|
|
|
Settings().set_filename(self.ini_file)
|
|
|
|
self.application = QtGui.QApplication.instance()
|
|
|
|
Settings().extend_default_settings(__default_settings__)
|
2013-03-29 09:06:43 +00:00
|
|
|
self.router = HttpRouter()
|
2013-03-29 08:25:33 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""
|
|
|
|
Delete all the C++ objects at the end so that we don't have a segfault
|
|
|
|
"""
|
|
|
|
del self.application
|
|
|
|
os.unlink(self.ini_file)
|
|
|
|
|
2013-09-14 21:00:58 +00:00
|
|
|
def password_encrypter_test(self):
|
2013-03-29 09:32:46 +00:00
|
|
|
"""
|
2013-09-14 21:00:58 +00:00
|
|
|
Test hash userid and password function
|
2013-03-29 09:32:46 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: A default configuration
|
2013-09-14 21:00:58 +00:00
|
|
|
Settings().setValue('remotes/user id', 'openlp')
|
|
|
|
Settings().setValue('remotes/password', 'password')
|
2013-03-29 09:32:46 +00:00
|
|
|
|
|
|
|
# WHEN: called with the defined userid
|
2013-09-14 21:00:58 +00:00
|
|
|
router = HttpRouter()
|
|
|
|
router.initialise()
|
|
|
|
test_value = 'b3BlbmxwOnBhc3N3b3Jk'
|
|
|
|
print(router.auth)
|
2013-03-29 09:32:46 +00:00
|
|
|
|
|
|
|
# THEN: the function should return the correct password
|
2013-09-14 21:00:58 +00:00
|
|
|
self.assertEqual(router.auth, test_value,
|
2013-08-31 18:17:38 +00:00
|
|
|
'The result for make_sha_hash should return the correct encrypted password')
|
2013-03-29 09:32:46 +00:00
|
|
|
|
2013-03-29 08:25:33 +00:00
|
|
|
def process_http_request_test(self):
|
|
|
|
"""
|
2013-03-29 09:06:43 +00:00
|
|
|
Test the router control functionality
|
2013-03-29 08:25:33 +00:00
|
|
|
"""
|
2013-03-29 09:06:43 +00:00
|
|
|
# GIVEN: A testing set of Routes
|
2013-09-14 21:00:58 +00:00
|
|
|
router = HttpRouter()
|
2013-03-29 09:06:43 +00:00
|
|
|
mocked_function = MagicMock()
|
|
|
|
test_route = [
|
2013-09-14 21:00:58 +00:00
|
|
|
(r'^/stage/api/poll$', {'function': mocked_function, 'secure': False}),
|
2013-03-29 09:06:43 +00:00
|
|
|
]
|
2013-09-14 21:00:58 +00:00
|
|
|
router.routes = test_route
|
2013-03-29 09:06:43 +00:00
|
|
|
|
|
|
|
# WHEN: called with a poll route
|
2013-09-14 21:00:58 +00:00
|
|
|
function, args = router.process_http_request('/stage/api/poll', None)
|
2013-03-29 08:25:33 +00:00
|
|
|
|
2013-03-29 09:06:43 +00:00
|
|
|
# THEN: the function should have been called only once
|
2013-09-14 21:00:58 +00:00
|
|
|
assert function['function'] == mocked_function, \
|
|
|
|
'The mocked function should match defined value.'
|
|
|
|
assert function['secure'] == False, \
|
|
|
|
'The mocked function should not require any security.'
|