def setUp(self):
     self.get_thumbnail_folder_patcher = \
         patch('openlp.plugins.presentations.lib.presentationcontroller.PresentationDocument.get_thumbnail_folder')
     self.get_thumbnail_folder_patcher.start()
     mocked_plugin = MagicMock()
     mocked_plugin.settings_section = 'presentations'
     self.presentation = PresentationController(mocked_plugin)
     self.document = PresentationDocument(self.presentation, '')
    def test_initialise_presentation_document(self):
        """
        Test the PresentationDocument __init__ method when initialising the PresentationDocument Class
        """
        # GIVEN: A mocked setup method and mocked controller
        self.mock_setup.reset()

        # WHEN: Creating an instance of PresentationDocument
        PresentationDocument(self.mock_controller, 'Name')

        # THEN: PresentationDocument._setup should have been called with the argument 'Name'
        self.mock_setup.assert_called_once_with('Name')
    def test_load_presentation(self):
        """
        Test the PresentationDocument.load_presentation method.
        """

        # GIVEN: An instance of PresentationDocument
        instance = PresentationDocument(self.mock_controller, 'Name')

        # WHEN: Calling load_presentation()
        result = instance.load_presentation()

        # THEN: load_presentation should return false
        self.assertFalse(result, "PresentationDocument.load_presentation should return false.")
    def test_presentation_document_setup(self):
        """
        Test the PresentationDocument _setup method when initialising the PresentationDocument Class
        """
        self._setup_patcher.stop()

        # GIVEN: A mocked controller, patched check_directory_exists and get_thumbnail_folder methods

        # WHEN: Creating an instance of PresentationDocument
        PresentationDocument(self.mock_controller, 'Name')

        # THEN: check_directory_exists should have been called with 'returned/path/'
        self.mock_check_directory_exists.assert_called_once_with('returned/path/')

        self._setup_patcher.start()
    def test_get_file_name(self):
        """
        Test the PresentationDocument.get_file_name method.
        """

        # GIVEN: A mocked os.path.split which returns a list, an instance of PresentationDocument and
        #       arbitary file_path.
        self.mock_os.path.split.return_value = ['directory', 'file.ext']
        instance = PresentationDocument(self.mock_controller, 'Name')
        instance.file_path = 'filepath'

        # WHEN: Calling get_file_name
        result = instance.get_file_name()

        # THEN: get_file_name should return 'file.ext'
        self.assertEqual(result, 'file.ext')