diff --git a/openlp/core/state.py b/openlp/core/state.py index fefc83692..3f15ab884 100644 --- a/openlp/core/state.py +++ b/openlp/core/state.py @@ -147,11 +147,15 @@ class State(LogMixin, metaclass=Singleton): :return: Have the preconditions been met. :rtype: bool """ - 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 + 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): """ diff --git a/tests/functional/openlp_core/test_state.py b/tests/functional/openlp_core/test_state.py index 06ea17660..0c43c1451 100644 --- a/tests/functional/openlp_core/test_state.py +++ b/tests/functional/openlp_core/test_state.py @@ -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