Merge branch 'Issue-740' into 'master'

Handle load of Service with missing Plugin - Issue 740

Closes #740

See merge request openlp/openlp!288
This commit is contained in:
Tim Bentley 2021-01-19 21:53:24 +00:00
commit 53b061dac6
2 changed files with 26 additions and 5 deletions

View File

@ -147,11 +147,15 @@ class State(LogMixin, metaclass=Singleton):
:return: Have the preconditions been met.
:rtype: bool
"""
try:
if self.modules[name].requires is None:
return self.modules[name].pass_preconditions
else:
mod = self.modules[name].requires
return self.modules[mod].pass_preconditions
except KeyError:
# Module is missing so therefore not found.
return False
def list_plugins(self):
"""

View File

@ -207,3 +207,20 @@ def test_check_preconditions_required_module(state):
# THEN: The correct result should be returned
assert result is False
def test_check_preconditions_missing_module(state):
"""
Test that the check_preconditions() method returns the correct attribute when the module is missing
"""
# GIVEN: A State with two modules
State().modules.update({
'test_pre2': MagicMock(requires='test_pre3', pass_preconditions=True),
'test_pre3': MagicMock(requires=None, pass_preconditions=False)
})
# WHEN: check_preconditions() is called
result = State().check_preconditions('test_pre1')
# THEN: The correct result should be returned
assert result is False