def test_encoding_declaration_removal(self):
        """
        Test that the encoding declaration is removed
        """
        # GIVEN: A reset mocked out re and an instance of foil_presenter
        self.mocked_re.reset()
        foil_presenter_instance = FoilPresenter(self.mocked_manager, self.mocked_song_import)

        # WHEN: xml_to_song is called with a string with an xml encoding declaration
        foil_presenter_instance.xml_to_song('<?xml version="1.0" encoding="UTF-8"?>\n<foilpresenterfolie>')

        # THEN: the xml encoding declaration should have been stripped
        self.mocked_re.compile.sub.called_with('\n<foilpresenterfolie>')
    def test_no_encoding_declaration(self):
        """
        Check that the xml sting is left intact when no encoding declaration is made
        """
        # GIVEN: A reset mocked out re and an instance of foil_presenter
        self.mocked_re.reset()
        foil_presenter_instance = FoilPresenter(self.mocked_manager, self.mocked_song_import)

        # WHEN: xml_to_song is called with a string without an xml encoding declaration
        foil_presenter_instance.xml_to_song('<foilpresenterfolie>')

        # THEN: the string should have been left intact
        self.mocked_re.compile.sub.called_with('<foilpresenterfolie>')
    def no_encoding_declaration_test(self):
        """
        Check that the xml sting is left intact when no encoding declaration is made
        """
        # GIVEN: A reset mocked out re and an instance of foil_presenter
        self.mocked_re.reset()
        foil_presenter_instance = FoilPresenter(self.mocked_manager, self.mocked_song_import)

        # WHEN: xml_to_song is called with a string without an xml encoding declaration
        foil_presenter_instance.xml_to_song('<foilpresenterfolie>')

        # THEN: the string should have been left intact
        self.mocked_re.compile.sub.called_with('<foilpresenterfolie>')
    def encoding_declaration_removal_test(self):
        """
        Test that the encoding declaration is removed
        """
        # GIVEN: A reset mocked out re and an instance of foil_presenter
        self.mocked_re.reset()
        foil_presenter_instance = FoilPresenter(self.mocked_manager, self.mocked_song_import)

        # WHEN: xml_to_song is called with a string with an xml encoding declaration
        foil_presenter_instance.xml_to_song('<?xml version="1.0" encoding="UTF-8"?>\n<foilpresenterfolie>')

        # THEN: the xml encoding declaration should have been stripped
        self.mocked_re.compile.sub.called_with('\n<foilpresenterfolie>')
    def test_no_xml(self):
        """
        Test calling xml_to_song with out the xml argument
        """
        # GIVEN: A mocked out "manager" and "SongImport" as well as an foil_presenter instance
        mocked_manager = MagicMock()
        mocked_song_import = MagicMock()
        foil_presenter_instance = FoilPresenter(mocked_manager, mocked_song_import)

        # WHEN: xml_to_song is called without valid an argument
        for arg in [None, False, 0, '']:
            result = foil_presenter_instance.xml_to_song(arg)

            # Then: xml_to_song should return False
            assert result is None, 'xml_to_song should return None when called with %s' % arg
    def no_xml_test(self):
        """
        Test calling xml_to_song with out the xml argument
        """
        # GIVEN: A mocked out "manager" and "SongImport" as well as an foil_presenter instance
        mocked_manager = MagicMock()
        mocked_song_import = MagicMock()
        foil_presenter_instance = FoilPresenter(mocked_manager, mocked_song_import)

        # WHEN: xml_to_song is called without valid an argument
        for arg in [None, False, 0, '']:
            result = foil_presenter_instance.xml_to_song(arg)

            # Then: xml_to_song should return False
            self.assertEqual(result, None, 'xml_to_song should return None when called with %s' % arg)
    def test_process_lyrics_no_verses(self):
        """
        Test that _process_lyrics handles song files that have no verses.
        """
        # GIVEN: A mocked foilpresenterfolie with no attribute strophe, a mocked song and a
        #       foil presenter instance
        self.process_lyrics_patcher.stop()
        self.mocked_song_xml.reset()
        mock_foilpresenterfolie = MagicMock()
        del mock_foilpresenterfolie.strophen.strophe
        mocked_song = MagicMock()
        foil_presenter_instance = FoilPresenter(self.mocked_manager, self.mocked_song_import)

        # WHEN: _process_lyrics is called
        result = foil_presenter_instance._process_lyrics(mock_foilpresenterfolie, mocked_song)

        # THEN: _process_lyrics should return None and the song_import log_error method should have been called once
        assert result is None
        self.mocked_song_import.log_error.assert_called_once_with('Element Text', 'Translated String')
        self.process_lyrics_patcher.start()
    def process_lyrics_no_verses_test(self):
        """
        Test that _process_lyrics handles song files that have no verses.
        """
        # GIVEN: A mocked foilpresenterfolie with no attribute strophe, a mocked song and a
        #       foil presenter instance
        self.process_lyrics_patcher.stop()
        self.mocked_song_xml.reset()
        mock_foilpresenterfolie = MagicMock()
        del mock_foilpresenterfolie.strophen.strophe
        mocked_song = MagicMock()
        foil_presenter_instance = FoilPresenter(self.mocked_manager, self.mocked_song_import)

        # WHEN: _process_lyrics is called
        result = foil_presenter_instance._process_lyrics(mock_foilpresenterfolie, mocked_song)

        # THEN: _process_lyrics should return None and the song_import log_error method should have been called once
        self.assertIsNone(result)
        self.mocked_song_import.log_error.assert_called_once_with('Element Text', 'Translated String')
        self.process_lyrics_patcher.start()
    def test_create_foil_presenter(self):
        """
        Test creating an instance of the foil_presenter class
        """
        # GIVEN: A mocked out "manager" and "SongImport" instance
        mocked_manager = MagicMock()
        mocked_song_import = MagicMock()

        # WHEN: An foil_presenter instance is created
        foil_presenter_instance = FoilPresenter(mocked_manager, mocked_song_import)

        # THEN: The instance should not be None
        assert foil_presenter_instance is not None, 'foil_presenter instance should not be none'