示例#1
0
    def test_copy_template(self):
        """
        template.copy() should create missing lang specific templates.
        """
        template = L10nTemplate(
            path.join(TEMPLATE_DIRS[0], 'l10n_blocks_without_langs.html'))
        # cause the template to be read and parsed before mocking open
        template.blocks
        codecs_open = 'l10n_utils.management.commands.l10n_check.codecs.open'
        open_mock = MagicMock(spec=file)
        open_buffer = StringIO()
        open_mock.return_value.__enter__.return_value = open_buffer
        with patch(codecs_open, open_mock):
            template.copy('de')

        # braces doubled for .format()
        good_value = dedent("""\
            {{# Version: {0} #}}

            {{% extends "l10n_blocks_without_langs.html" %}}

            {{% l10n donnie %}}
            Phone's ringing Dude.
            {{% endl10n %}}\n
        """.format(get_todays_version()))
        self.assertEqual(open_buffer.getvalue(), good_value)
示例#2
0
    def test_copy_template(self):
        """
        template.copy() should create missing lang specific templates.
        """
        template = L10nTemplate(path.join(TEMPLATE_DIRS[0],
                                          'l10n_blocks_without_langs.html'))
        # cause the template to be read and parsed before mocking open
        template.blocks
        codecs_open = 'l10n_utils.management.commands.l10n_check.codecs.open'
        open_mock = MagicMock(spec=file)
        open_buffer = StringIO()
        open_mock.return_value.__enter__.return_value = open_buffer
        with patch(codecs_open, open_mock):
            template.copy('de')

        # braces doubled for .format()
        good_value = dedent("""\
            {{# Version: {0} #}}

            {{% extends "l10n_blocks_without_langs.html" %}}

            {{% l10n donnie %}}
            Phone's ringing Dude.
            {{% endl10n %}}\n
        """.format(get_todays_version()))
        self.assertEqual(open_buffer.getvalue(), good_value)
示例#3
0
    def test_update_template(self):
        """
        template.update() should update lang specific templates.
        """
        template = L10nTemplate(
            path.join(TEMPLATE_DIRS[0], 'l10n_blocks_with_langs.html'))
        # cause the template to be read and parsed before mocking open
        template.blocks
        codecs_open = 'l10n_utils.management.commands.l10n_check.codecs.open'
        open_mock = MagicMock(spec=file)
        open_buffer = StringIO()
        # for writing the new file
        open_mock.return_value.__enter__.return_value = open_buffer
        # for reading the old file
        open_mock().read.return_value = codecs.open(
            template.l10n_path('de')).read()

        with patch(codecs_open, open_mock):
            template.update('de')

        # braces doubled for .format()
        good_value = dedent("""\
            {{# Version: {0} #}}

            {{% extends "l10n_blocks_with_langs.html" %}}

            {{% l10n donnie %}}
            Phone's ringing Dude.
            {{% was %}}
            I am the walrus.
            {{% endl10n %}}\n\n
        """.format(get_todays_version()))
        self.assertEqual(open_buffer.getvalue(), good_value)
示例#4
0
    def test_update_template(self):
        """
        template.update() should update lang specific templates.
        """
        template = L10nTemplate(path.join(TEMPLATE_DIRS[0],
                                          'l10n_blocks_with_langs.html'))
        # cause the template to be read and parsed before mocking open
        template.blocks
        codecs_open = 'l10n_utils.management.commands.l10n_check.codecs.open'
        open_mock = MagicMock(spec=file)
        open_buffer = StringIO()
        # for writing the new file
        open_mock.return_value.__enter__.return_value = open_buffer
        # for reading the old file
        open_mock().read.return_value = codecs.open(
            template.l10n_path('de')).read()

        with patch(codecs_open, open_mock):
            template.update('de')

        # braces doubled for .format()
        good_value = dedent("""\
            {{# Version: {0} #}}

            {{% extends "l10n_blocks_with_langs.html" %}}

            {{% l10n donnie %}}
            Phone's ringing Dude.
            {{% was %}}
            I am the walrus.
            {{% endl10n %}}\n\n
        """.format(get_todays_version()))
        self.assertEqual(open_buffer.getvalue(), good_value)