2016-06-13 19:51:46 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
2019-04-13 13:00:22 +00:00
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
|
|
# Copyright (c) 2008-2019 OpenLP Developers #
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
|
|
# 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, either version 3 of the License, or #
|
|
|
|
# (at your option) any later version. #
|
|
|
|
# #
|
|
|
|
# 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, see <https://www.gnu.org/licenses/>. #
|
|
|
|
##########################################################################
|
2016-06-13 19:51:46 +00:00
|
|
|
"""
|
|
|
|
Functional tests to test the Http Server Class.
|
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
2017-08-12 20:08:12 +00:00
|
|
|
from unittest.mock import MagicMock, patch
|
2016-06-13 19:51:46 +00:00
|
|
|
|
2016-06-28 21:39:16 +00:00
|
|
|
from openlp.core.api.http.server import HttpServer
|
2017-12-28 08:27:44 +00:00
|
|
|
from openlp.core.common.registry import Registry
|
2016-06-13 19:51:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestHttpServer(TestCase):
|
|
|
|
"""
|
|
|
|
A test suite to test starting the http server
|
|
|
|
"""
|
2017-03-05 17:00:21 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Create the UI
|
|
|
|
"""
|
|
|
|
Registry().create()
|
|
|
|
Registry().register('service_list', MagicMock())
|
|
|
|
|
2016-06-28 21:39:16 +00:00
|
|
|
@patch('openlp.core.api.http.server.HttpWorker')
|
2018-01-04 06:01:35 +00:00
|
|
|
@patch('openlp.core.api.http.server.run_thread')
|
|
|
|
def test_server_start(self, mocked_run_thread, MockHttpWorker):
|
2016-06-13 19:51:46 +00:00
|
|
|
"""
|
2017-12-02 09:31:13 +00:00
|
|
|
Test the starting of the Waitress Server with the disable flag set off
|
2016-06-13 19:51:46 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: A new httpserver
|
|
|
|
# WHEN: I start the server
|
2018-01-07 05:24:55 +00:00
|
|
|
Registry().set_flag('no_web_server', False)
|
2017-10-07 07:05:07 +00:00
|
|
|
HttpServer()
|
2016-06-13 19:51:46 +00:00
|
|
|
|
|
|
|
# THEN: the api environment should have been created
|
2018-01-04 06:01:35 +00:00
|
|
|
assert mocked_run_thread.call_count == 1, 'The qthread should have been called once'
|
|
|
|
assert MockHttpWorker.call_count == 1, 'The http thread should have been called once'
|
2017-12-02 09:31:13 +00:00
|
|
|
|
|
|
|
@patch('openlp.core.api.http.server.HttpWorker')
|
2018-01-04 06:01:35 +00:00
|
|
|
@patch('openlp.core.api.http.server.run_thread')
|
|
|
|
def test_server_start_not_required(self, mocked_run_thread, MockHttpWorker):
|
2017-12-02 09:31:13 +00:00
|
|
|
"""
|
|
|
|
Test the starting of the Waitress Server with the disable flag set off
|
|
|
|
"""
|
|
|
|
# GIVEN: A new httpserver
|
|
|
|
# WHEN: I start the server
|
2018-01-07 05:24:55 +00:00
|
|
|
Registry().set_flag('no_web_server', True)
|
2017-12-02 09:31:13 +00:00
|
|
|
HttpServer()
|
|
|
|
|
|
|
|
# THEN: the api environment should have been created
|
2018-01-04 06:01:35 +00:00
|
|
|
assert mocked_run_thread.call_count == 0, 'The qthread should not have have been called'
|
|
|
|
assert MockHttpWorker.call_count == 0, 'The http thread should not have been called'
|