forked from openlp/openlp
Add test
This commit is contained in:
parent
d6d3cd1394
commit
1e6f00c2eb
@ -33,7 +33,7 @@ from unittest import TestCase
|
|||||||
|
|
||||||
from openlp.core.ui import SlideController
|
from openlp.core.ui import SlideController
|
||||||
|
|
||||||
from tests.interfaces import MagicMock, patch
|
from tests.interfaces import MagicMock
|
||||||
|
|
||||||
|
|
||||||
class TestSlideController(TestCase):
|
class TestSlideController(TestCase):
|
||||||
|
@ -32,7 +32,7 @@ This module contains tests for the lib submodule of the Remotes plugin.
|
|||||||
import os
|
import os
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from openlp.core.common import Settings
|
from openlp.core.common import Settings, Registry
|
||||||
from openlp.plugins.remotes.lib.httpserver import HttpRouter
|
from openlp.plugins.remotes.lib.httpserver import HttpRouter
|
||||||
from tests.functional import MagicMock, patch, mock_open
|
from tests.functional import MagicMock, patch, mock_open
|
||||||
from tests.helpers.testmixin import TestMixin
|
from tests.helpers.testmixin import TestMixin
|
||||||
@ -92,15 +92,15 @@ class TestRouter(TestCase, TestMixin):
|
|||||||
Test the router control functionality
|
Test the router control functionality
|
||||||
"""
|
"""
|
||||||
# GIVEN: A testing set of Routes
|
# GIVEN: A testing set of Routes
|
||||||
router = HttpRouter()
|
#router = HttpRouter()
|
||||||
mocked_function = MagicMock()
|
mocked_function = MagicMock()
|
||||||
test_route = [
|
test_route = [
|
||||||
(r'^/stage/api/poll$', {'function': mocked_function, 'secure': False}),
|
(r'^/stage/api/poll$', {'function': mocked_function, 'secure': False}),
|
||||||
]
|
]
|
||||||
router.routes = test_route
|
self.router.routes = test_route
|
||||||
|
|
||||||
# WHEN: called with a poll route
|
# WHEN: called with a poll route
|
||||||
function, args = router.process_http_request('/stage/api/poll', None)
|
function, args = self.router.process_http_request('/stage/api/poll', None)
|
||||||
|
|
||||||
# THEN: the function should have been called only once
|
# THEN: the function should have been called only once
|
||||||
self.assertEqual(mocked_function, function['function'], 'The mocked function should match defined value.')
|
self.assertEqual(mocked_function, function['function'], 'The mocked function should match defined value.')
|
||||||
@ -126,6 +126,25 @@ class TestRouter(TestCase, TestMixin):
|
|||||||
# THEN: all types should match
|
# THEN: all types should match
|
||||||
self.assertEqual(content_type, header[1], 'Mismatch of content type')
|
self.assertEqual(content_type, header[1], 'Mismatch of content type')
|
||||||
|
|
||||||
|
def main_poll_test(self):
|
||||||
|
"""
|
||||||
|
Test the main poll logic
|
||||||
|
"""
|
||||||
|
# GIVEN: a defined router with two slides
|
||||||
|
Registry().register('live_controller', MagicMock)
|
||||||
|
router = HttpRouter()
|
||||||
|
router.send_response = MagicMock()
|
||||||
|
router.send_header = MagicMock()
|
||||||
|
router.end_headers = MagicMock()
|
||||||
|
router.live_controller.slide_count = 2
|
||||||
|
|
||||||
|
# WHEN: main poll called
|
||||||
|
results = router.main_poll()
|
||||||
|
|
||||||
|
# THEN: the correct response should be returned
|
||||||
|
self.assertEqual(results.decode('utf-8'), '{"results": {"slide_count": 2}}',
|
||||||
|
'The resulting json strings should match')
|
||||||
|
|
||||||
def serve_file_without_params_test(self):
|
def serve_file_without_params_test(self):
|
||||||
"""
|
"""
|
||||||
Test the serve_file method without params
|
Test the serve_file method without params
|
||||||
|
Loading…
Reference in New Issue
Block a user