forked from openlp/openlp
Merge branch 'proj_manager_tests' into 'master'
ProjectorManager tests See merge request openlp/openlp!381
This commit is contained in:
commit
2143d89d1d
@ -22,6 +22,8 @@
|
||||
Interface tests to test the themeManager class and related methods.
|
||||
"""
|
||||
import pytest
|
||||
import logging
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from openlp.core.projectors.db import ProjectorDB
|
||||
@ -41,6 +43,13 @@ def projector_manager(settings):
|
||||
del proj_manager
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def projector_manager_nodb(settings):
|
||||
proj_manager = ProjectorManager(projectordb=None)
|
||||
yield proj_manager
|
||||
del proj_manager
|
||||
|
||||
|
||||
def test_bootstrap_initialise(projector_manager):
|
||||
"""
|
||||
Test initialize calls correct startup functions
|
||||
@ -52,6 +61,20 @@ def test_bootstrap_initialise(projector_manager):
|
||||
'Initialization should have created a ProjectorDB() instance'
|
||||
|
||||
|
||||
def test_bootstrap_initialise_nodb(projector_manager_nodb, caplog):
|
||||
"""
|
||||
Test log entry creating new projector DB
|
||||
"""
|
||||
caplog.set_level(logging.DEBUG)
|
||||
|
||||
# WHEN: ProjectorManager created with no DB set
|
||||
caplog.clear()
|
||||
projector_manager_nodb.bootstrap_initialise()
|
||||
# THEN: Log should indicate new DB being created
|
||||
assert caplog.record_tuples[3] == ('openlp.core.projectors.manager', 10, 'Creating new ProjectorDB() instance'), \
|
||||
"ProjectorManager should have indicated a new DB being created"
|
||||
|
||||
|
||||
def test_bootstrap_post_set_up(projector_manager):
|
||||
"""
|
||||
Test post-initialize calls proper setups
|
||||
@ -70,3 +93,22 @@ def test_bootstrap_post_set_up(projector_manager):
|
||||
'Initialization should have created a Projector Edit Form'
|
||||
assert projector_manager.projectordb is projector_manager.projector_form.projectordb, \
|
||||
'ProjectorEditForm should be using same ProjectorDB() instance as ProjectorManager'
|
||||
|
||||
|
||||
def test_bootstrap_post_set_up_autostart_projector(projector_manager_nodb, caplog):
|
||||
"""
|
||||
Test post-initialize calling log and QTimer on autostart
|
||||
"""
|
||||
# GIVEN: Setup mocks
|
||||
with patch('openlp.core.projectors.manager.QtCore.QTimer.singleShot') as mock_timer:
|
||||
caplog.set_level(logging.DEBUG)
|
||||
# WHEN: Initializations called
|
||||
projector_manager_nodb.bootstrap_initialise()
|
||||
projector_manager_nodb.autostart = True
|
||||
projector_manager_nodb.bootstrap_post_set_up()
|
||||
|
||||
# THEN: verify log entries and timer calls
|
||||
mock_timer.assert_called_once_with(1500, projector_manager_nodb._load_projectors)
|
||||
assert caplog.record_tuples[-1] == ('openlp.core.projectors.manager', 10,
|
||||
'Delaying 1.5 seconds before loading all projectors'), \
|
||||
"Last log entry should be autoloading entry"
|
||||
|
Loading…
Reference in New Issue
Block a user