Exemplo n.º 1
0
    def test_convert_with_existing(self):
        self.pod.write_file(
            '/content/test.md',
            textwrap.dedent("""
                ---
                name: Julie Yang
                ---
                Content reigns supreme.
                ---
                $locale: ja
                ---
                Supreme the content reigns.
                """).lstrip())
        self.pod.write_file(
            '/content/[email protected]',
            textwrap.dedent("""
                Supreme the content reigns.
                """).lstrip())

        doc = content_locale_split.ConversionDocument(self.pod,
                                                      '/content/test.md',
                                                      'en_us')

        with self.assertRaises(content_locale_split.LocaleExistsError):
            doc.convert()
Exemplo n.º 2
0
    def test_convert_with_gather_trailing(self):
        self.pod.write_file(
            '/content/test.md',
            textwrap.dedent("""
                ---
                name: Julie Yang
                grr:
                  foo: tas
                  foo@es: sep
                  foo@fr: gli
                  foo@ja: min
                ---
                Content reigns supreme.
                ---
                $locale: ja
                ---
                Supreme the content reigns.
                ---
                $locale: fr
                ---
                Reigning content.
                """).lstrip())

        expected = {
            '/content/test.md':
            textwrap.dedent("""
                ---
                name: Julie Yang
                grr:
                  foo: tas
                  foo@es: sep
                ---
                Content reigns supreme.
                """).lstrip(),
            '/content/[email protected]':
            textwrap.dedent("""
                ---
                grr:
                  foo: min
                ---
                Supreme the content reigns.
                """).lstrip(),
            '/content/[email protected]':
            textwrap.dedent("""
                ---
                grr:
                  foo: gli
                ---
                Reigning content.
                """).lstrip(),
        }
        doc = content_locale_split.ConversionDocument(self.pod,
                                                      '/content/test.md',
                                                      'en_us')
        doc.convert()

        for key, value in expected.iteritems():
            self.assertEquals(value, self.pod.read_file(key))
Exemplo n.º 3
0
    def test_convert_with_gather(self):
        self.pod.write_file(
            '/content/test.md',
            textwrap.dedent("""
                ---
                name: Julie Yang
                bar@: tri
                bar@es: pep
                bar@fr: pip
                bar@ja: tes
                ---
                Content reigns supreme.
                ---
                $locale: ja
                ---
                Supreme the content reigns.
                ---
                $locale: fr
                ---
                Reigning content.
                """).lstrip())

        expected = {
            '/content/test.md':
            textwrap.dedent("""
                ---
                name: Julie Yang
                bar@: tri
                bar@es: pep
                ---
                Content reigns supreme.
                """).lstrip(),
            '/content/[email protected]':
            textwrap.dedent("""
                ---
                bar@: tes
                ---
                Supreme the content reigns.
                """).lstrip(),
            '/content/[email protected]':
            textwrap.dedent("""
                ---
                bar@: pip
                ---
                Reigning content.
                """).lstrip(),
        }
        doc = content_locale_split.ConversionDocument(self.pod,
                                                      '/content/test.md',
                                                      'en_us')
        doc.convert()

        for key, value in expected.iteritems():
            self.assertEquals(value, self.pod.read_file(key))
Exemplo n.º 4
0
    def test_convert_with_missing_locale(self):
        self.pod.write_file(
            '/content/test.yaml',
            textwrap.dedent("""
                name: Julie Yang
                ---
                foo:bar
                """).lstrip())

        doc = content_locale_split.ConversionDocument(self.pod,
                                                      '/content/test.yaml',
                                                      'en_us')

        with self.assertRaises(content_locale_split.LocaleMissingError):
            doc.convert()
Exemplo n.º 5
0
    def test_convert_with_empty_front_section(self):
        self.pod.write_file(
            '/content/test.yaml',
            textwrap.dedent("""
                ---
                name: Julie Yang
                """).lstrip())

        expected = {
            '/content/test.yaml':
            textwrap.dedent("""
                name: Julie Yang
                """).lstrip(),
        }

        doc = content_locale_split.ConversionDocument(self.pod,
                                                      '/content/test.yaml',
                                                      'en_us')
        doc.convert()
        for key, value in expected.iteritems():
            self.assertEquals(value, self.pod.read_file(key))
Exemplo n.º 6
0
    def test_convert_with_extended(self):
        self.pod.write_file(
            '/content/test.yaml',
            textwrap.dedent("""
                name: Julie Yang
                ---
                $locales:
                - ja
                - fr
                foo: bar
                ---
                $locale: fr
                bar: faz
                """).lstrip())

        expected = {
            '/content/test.yaml':
            textwrap.dedent("""
                name: Julie Yang
                """).lstrip(),
            '/content/[email protected]':
            textwrap.dedent("""
                foo: bar
                """).lstrip(),
            '/content/[email protected]':
            textwrap.dedent("""
                bar: faz
                foo: bar
                """).lstrip(),
        }
        doc = content_locale_split.ConversionDocument(self.pod,
                                                      '/content/test.yaml',
                                                      'en_us')
        doc.convert()

        for key, value in expected.iteritems():
            self.assertEquals(value, self.pod.read_file(key))
Exemplo n.º 7
0
    def test_split(self):
        # Two part document.
        self.pod.write_file(
            '/content/something.md',
            textwrap.dedent("""
            ---
            name: Julie Yang
            foo@: bar
            ---
            Content reigns supreme.
            ---
            $locale: ja
            foo@: baz
            ---
            Supreme the content reigns.
            """).lstrip())

        expected = [
            (textwrap.dedent("""
                    name: Julie Yang
                    foo@: bar
                    """).strip(), 'Content reigns supreme.'),
            (textwrap.dedent("""
                    $locale: ja
                    foo@: baz
                    """).strip(), 'Supreme the content reigns.'),
        ]
        doc = content_locale_split.ConversionDocument(self.pod,
                                                      '/content/something.md',
                                                      'en_us')
        self.assertEquals(expected, list(doc.split()))

        # Empty front matter document.
        self.pod.write_file(
            '/content/something.md',
            textwrap.dedent("""
            ---
            ---
            Content reigns supreme.
            """).lstrip())

        expected = [
            (None, 'Content reigns supreme.'),
        ]
        doc = content_locale_split.ConversionDocument(self.pod,
                                                      '/content/something.md',
                                                      'en_us')
        self.assertEquals(expected, list(doc.split()))

        # Missing front matter document.
        self.pod.write_file(
            '/content/something.md',
            textwrap.dedent("""
            Content reigns supreme.
            """).lstrip())

        expected = [
            (None, 'Content reigns supreme.'),
        ]
        doc = content_locale_split.ConversionDocument(self.pod,
                                                      '/content/something.md',
                                                      'en_us')
        self.assertEquals(expected, list(doc.split()))

        # Yaml document.
        self.pod.write_file(
            '/content/something.yaml',
            textwrap.dedent("""
            name: Julie Yang
            foo: bar
            ---
            $locale: ja
            foo: baz
            """).lstrip())

        expected = [
            (textwrap.dedent("""
                    name: Julie Yang
                    foo: bar
                    """).strip(), None),
            (textwrap.dedent("""
                    $locale: ja
                    foo: baz
                    """).strip(), None),
        ]
        doc = content_locale_split.ConversionDocument(
            self.pod, '/content/something.yaml', 'en_us')
        self.assertEquals(expected, list(doc.split()))
Exemplo n.º 8
0
    def test_convert_with_gather_array(self):
        self.pod.write_file(
            '/content/test.md',
            textwrap.dedent("""
                ---
                name: Julie Yang
                bar:
                - title: bar
                  title@fr: rab
                  foo: fed
                - title: bam
                  title@fr: mab
                  foo: dew
                - title: baz
                  foo: tee
                ---
                Content reigns supreme.
                ---
                $locale: ja
                ---
                Supreme the content reigns.
                ---
                $locale: fr
                ---
                Reigning content.
                """).lstrip())

        expected = {
            '/content/test.md':
            textwrap.dedent("""
                ---
                name: Julie Yang
                bar:
                - title: bar
                  foo: fed
                - title: bam
                  foo: dew
                - title: baz
                  foo: tee
                ---
                Content reigns supreme.
                """).lstrip(),
            '/content/[email protected]':
            textwrap.dedent("""
                Supreme the content reigns.
                """).lstrip(),
            '/content/[email protected]':
            textwrap.dedent("""
                ---
                bar:
                - title: rab
                  foo: fed
                - title: mab
                  foo: dew
                - title: baz
                  foo: tee
                ---
                Reigning content.
                """).lstrip(),
        }
        doc = content_locale_split.ConversionDocument(self.pod,
                                                      '/content/test.md',
                                                      'en_us')
        doc.convert()

        for key, value in expected.iteritems():
            self.assertEquals(value, self.pod.read_file(key))
Exemplo n.º 9
0
    def test_default_locale_in_doc(self):
        self.pod.write_file(
            '/content/test.md',
            textwrap.dedent("""
            ---
            name: Julie Yang
            foo@: bar
            $locales:
            - en_us
            - en_au
            - en_uk
            ---
            Content reigns supreme.
            ---
            $locale: ja
            foo@: baz
            ---
            Supreme the content reigns.
            ---
            $locales:
            - fr
            - ch
            foo@: bam
            foo@ch: zam
            ---
            Reigning content.
            """).lstrip())

        expected = {
            '/content/test.md':
            textwrap.dedent("""
                ---
                name: Julie Yang
                foo@: bar
                $locales:
                - en_au
                - en_uk
                ---
                Content reigns supreme.
                """).lstrip(),
            '/content/[email protected]':
            textwrap.dedent("""
                ---
                foo@: baz
                ---
                Supreme the content reigns.
                """).lstrip(),
            '/content/[email protected]':
            textwrap.dedent("""
                ---
                foo@: bam
                ---
                Reigning content.
                """).lstrip(),
            '/content/[email protected]':
            textwrap.dedent("""
                ---
                foo@: zam
                ---
                Reigning content.
                """).lstrip(),
        }
        doc = content_locale_split.ConversionDocument(self.pod,
                                                      '/content/test.md',
                                                      'en_us')
        doc.convert()
        for key, value in expected.iteritems():
            self.assertEquals(value, self.pod.read_file(key))