Ejemplo n.º 1
0
 def setUpClass(cls):
     cls.localized_pod = testing.create_test_pod('extract_localized/localized_pod')
     cls.localized_pod.catalogs.compile()
     cls.localized_pod.catalogs.extract(localized=True)
     cls.unlocalized_pod = testing.create_test_pod('extract_localized/unlocalized_pod')
     cls.unlocalized_pod.catalogs.compile()
     cls.unlocalized_pod.catalogs.extract(localized=True)
Ejemplo n.º 2
0
 def setUpClass(cls):
     cls.localized_pod = testing.create_test_pod(
         'extract_localized/localized_pod')
     cls.localized_pod.catalogs.compile()
     cls.localized_pod.catalogs.extract(localized=True)
     cls.unlocalized_pod = testing.create_test_pod(
         'extract_localized/unlocalized_pod')
     cls.unlocalized_pod.catalogs.compile()
     cls.unlocalized_pod.catalogs.extract(localized=True)
Ejemplo n.º 3
0
    def test_extract_localized_for_single_locale(self):
        localized_pod = testing.create_test_pod(
            'extract_localized/localized_pod')
        localized_pod.catalogs.compile()
        localized_pod.catalogs.extract(localized=True, locales=['it'])

        unlocalized_pod = testing.create_test_pod(
            'extract_localized/unlocalized_pod')
        unlocalized_pod.catalogs.compile()
        unlocalized_pod.catalogs.extract(localized=True, locales=['it'])

        # These strings are all relevant to both IT & SV, but should only be
        # extracted for IT
        italian_messages = (
            u'Multi-locale doc part body in localized doc in localized collection in localized pöd',
            u'Multi-locale doc part body in localized doc in unlocalized collection in localized pöd',
            u'Multi-locale doc part body in localized doc in localized collection in unlocalized pöd',
            u'Multi-locale doc part body in localized doc in unlocalized collection in unlocalized pöd',
            u'Multi-locale doc part front matter in localized doc in localized collection in localized pöd',
            u'Multi-locale doc part front matter in localized doc in unlocalized collection in localized pöd',
            u'Multi-locale doc part front matter in localized doc in localized collection in unlocalized pöd',
            u'Multi-locale doc part front matter in localized doc in unlocalized collection in unlocalized pöd',
            u'Multi-locale yaml doc part in localized doc in localized collection in localized pöd',
            u'Multi-locale yaml doc part in localized doc in unlocalized collection in localized pöd',
            u'Multi-locale yaml doc part in localized doc in localized collection in unlocalized pöd',
        )
        for message in italian_messages:
            if u'unlocalized pöd' in message:
                self.assertExtractedFor(unlocalized_pod, message, 'it')
            else:
                self.assertExtractedFor(localized_pod, message, 'it')

        # These are only relevant to FR, DE or no locales, so shouldn't be
        # extracted
        non_italian_messages = (
            u'Unlocalized doc body in localized collection in localized pöd',
            u'Unlocalized doc body in localized collection in unlocalized pöd',
            u'Unlocalized doc body in unlocalized collection in localized pöd',
            u'Unlocalized doc body in unlocalized collection in unlocalized pöd',
            u'Unlocalized doc front matter in localized collection in localized pöd',
            u'Unlocalized doc front matter in localized collection in unlocalized pöd',
            u'Unlocalized doc front matter in unlocalized collection in localized pöd',
            u'Unlocalized doc front matter in unlocalized collection in unlocalized pöd',
            u'Unlocalized yaml doc in localized collection in localized pöd',
            u'Unlocalized yaml doc in localized collection in unlocalized pöd',
            u'Unlocalized yaml doc in unlocalized collection in localized pöd',
            u'Unlocalized yaml doc in unlocalized collection in unlocalized pöd',
            u'Unlocalized pödspec',
        )

        for message in non_italian_messages:
            if u'unlocalized pöd' in message:
                self.assertExtractedFor(unlocalized_pod, message, [])
            else:
                self.assertExtractedFor(localized_pod, message, [])
Ejemplo n.º 4
0
    def test_extract_localized_for_single_locale(self):
        localized_pod = testing.create_test_pod(
            'extract_localized/localized_pod')
        localized_pod.catalogs.compile()
        localized_pod.catalogs.extract(localized=True, locales=['it'])

        unlocalized_pod = testing.create_test_pod(
            'extract_localized/unlocalized_pod')
        unlocalized_pod.catalogs.compile()
        unlocalized_pod.catalogs.extract(localized=True, locales=['it'])

        # These strings are all relevant to both IT & SV, but should only be
        # extracted for IT
        italian_messages = (
            u'Multi-locale doc part body in localized doc in localized collection in localized pöd',
            u'Multi-locale doc part body in localized doc in unlocalized collection in localized pöd',
            u'Multi-locale doc part body in localized doc in localized collection in unlocalized pöd',
            u'Multi-locale doc part body in localized doc in unlocalized collection in unlocalized pöd',
            u'Multi-locale doc part front matter in localized doc in localized collection in localized pöd',
            u'Multi-locale doc part front matter in localized doc in unlocalized collection in localized pöd',
            u'Multi-locale doc part front matter in localized doc in localized collection in unlocalized pöd',
            u'Multi-locale doc part front matter in localized doc in unlocalized collection in unlocalized pöd',
            u'Multi-locale yaml doc part in localized doc in localized collection in localized pöd',
            u'Multi-locale yaml doc part in localized doc in unlocalized collection in localized pöd',
            u'Multi-locale yaml doc part in localized doc in localized collection in unlocalized pöd',
        )
        for message in italian_messages:
            if u'unlocalized pöd' in message:
                self.assertExtractedFor(unlocalized_pod, message, 'it')
            else:
                self.assertExtractedFor(localized_pod, message, 'it')

        # These are only relevant to FR, DE or no locales, so shouldn't be
        # extracted
        non_italian_messages = (
            u'Unlocalized doc body in localized collection in localized pöd',
            u'Unlocalized doc body in localized collection in unlocalized pöd',
            u'Unlocalized doc body in unlocalized collection in localized pöd',
            u'Unlocalized doc body in unlocalized collection in unlocalized pöd',
            u'Unlocalized doc front matter in localized collection in localized pöd',
            u'Unlocalized doc front matter in localized collection in unlocalized pöd',
            u'Unlocalized doc front matter in unlocalized collection in localized pöd',
            u'Unlocalized doc front matter in unlocalized collection in unlocalized pöd',
            u'Unlocalized yaml doc in localized collection in localized pöd',
            u'Unlocalized yaml doc in localized collection in unlocalized pöd',
            u'Unlocalized yaml doc in unlocalized collection in localized pöd',
            u'Unlocalized yaml doc in unlocalized collection in unlocalized pöd',
            u'Unlocalized pödspec',
        )

        for message in non_italian_messages:
            if u'unlocalized pöd' in message:
                self.assertExtractedFor(unlocalized_pod, message, [])
            else:
                self.assertExtractedFor(localized_pod, message, [])
Ejemplo n.º 5
0
 def test_version_enforcement(self):
     with mock.patch('grow.pods.pods.Pod.grow_version',
                     new_callable=mock.PropertyMock) as mock_version:
         gt_version = '>{0}'.format(semantic_version.Version(config.VERSION))
         mock_version.return_value = gt_version
         with self.assertRaises(updater.LatestVersionCheckError):
             _ = testing.create_test_pod()
Ejemplo n.º 6
0
 def test_version_enforcement(self):
     with mock.patch('grow.pods.pods.Pod.grow_version', new_callable=mock.PropertyMock) as mock_version:
         this_version = get_this_version()
         gt_version = '>{0}'.format(semantic_version.Version(this_version))
         mock_version.return_value = gt_version
         with self.assertRaises(LatestVersionCheckError):
             pod = testing.create_test_pod()
Ejemplo n.º 7
0
 def test_version_enforcement(self):
     with mock.patch('grow.pods.pods.Pod.grow_version',
                     new_callable=mock.PropertyMock) as mock_version:
         this_version = get_this_version()
         gt_version = '>{0}'.format(semantic_version.Version(this_version))
         mock_version.return_value = gt_version
         with self.assertRaises(LatestVersionCheckError):
             pod = testing.create_test_pod()
Ejemplo n.º 8
0
 def test_locale_aliases(self):
   # Verify case insensitivty for locale aliases.
   pod = testing.create_test_pod()
   locale = locales.Locale('de')
   locale.set_alias(pod)
   self.assertEqual('de_alias', locale.alias)
   locale = locales.Locale('DE')
   locale.set_alias(pod)
   self.assertEqual('de_alias', locale.alias)
Ejemplo n.º 9
0
 def test_locale_aliases(self):
     # Verify case insensitivty for locale aliases.
     pod = testing.create_test_pod()
     locale = locales.Locale('de')
     locale.set_alias(pod)
     self.assertEqual('de_alias', locale.alias)
     locale = locales.Locale('DE')
     locale.set_alias(pod)
     self.assertEqual('de_alias', locale.alias)
Ejemplo n.º 10
0
    def test_excludes_obsolete_by_default(self):
        pod = testing.create_test_pod('extract_localized/localized_pod')
        pod.catalogs.compile()
        pod.catalogs.extract(localized=True, locales=['fr'])

        self.assertExtractedFor(pod, u'Existing message in localized pöd', [])
        # we don't use gettext syntax for obsolete translations
        for locale in self.ALL_LOCALES:
            self.assertFalse(pod.catalogs.get(locale).obsolete)
Ejemplo n.º 11
0
    def test_excludes_obsolete_by_default(self):
        pod = testing.create_test_pod('extract_localized/localized_pod')
        pod.catalogs.compile()
        pod.catalogs.extract(localized=True, locales=['fr'])

        self.assertExtractedFor(pod, u'Existing message in localized pöd', [])
        # we don't use gettext syntax for obsolete translations
        for locale in self.ALL_LOCALES:
            self.assertFalse(pod.catalogs.get(locale).obsolete)
Ejemplo n.º 12
0
 def test_plaintext_yaml(self):
     """Plaintext parsing of yaml without the constructors."""
     pod = testing.create_test_pod()
     content = pod.read_file('/data/constructors.yaml')
     result = yaml.load(content, Loader=yaml_utils.PlainTextYamlLoader)
     self.assertEqual(
         result['doc'], {'tag': u'!g.doc', 'value': u'/content/pages/home.yaml'})
     self.assertEqual(result['unfathomable'], {
         'tag': u'!g.yaml',
         'value': u'/data/deep.yaml?not.really.there'
     })
Ejemplo n.º 13
0
 def test_parse_yaml(self):
     pod = testing.create_test_pod()
     content = pod.read_file('/data/constructors.yaml')
     result = utils.parse_yaml(content, pod=pod)
     doc = pod.get_doc('/content/pages/home.yaml')
     self.assertEqual(doc, result['doc'])
     expected_docs = [
         pod.get_doc('/content/pages/home.yaml'),
         pod.get_doc('/content/pages/about.yaml'),
         pod.get_doc('/content/pages/home.yaml'),
     ]
     self.assertEqual(expected_docs, result['docs'])
Ejemplo n.º 14
0
 def test_parse_yaml(self):
     pod = testing.create_test_pod()
     content = pod.read_file('/data/constructors.yaml')
     result = utils.parse_yaml(content, pod=pod)
     doc = pod.get_doc('/content/pages/home.yaml')
     self.assertEqual(doc, result['doc'])
     expected_docs = [
         pod.get_doc('/content/pages/home.yaml'),
         pod.get_doc('/content/pages/about.yaml'),
         pod.get_doc('/content/pages/home.yaml'),
     ]
     self.assertEqual(expected_docs, result['docs'])
Ejemplo n.º 15
0
 def test_plaintext_yaml(self):
     """Plaintext parsing of yaml without the constructors."""
     pod = testing.create_test_pod()
     content = pod.read_file('/data/constructors.yaml')
     result = yaml.load(content, Loader=yaml_utils.PlainTextYamlLoader)
     self.assertEqual(result['doc'], {
         'tag': u'!g.doc',
         'value': u'/content/pages/home.yaml'
     })
     self.assertEqual(result['unfathomable'], {
         'tag': u'!g.yaml',
         'value': u'/data/deep.yaml?not.really.there'
     })
Ejemplo n.º 16
0
    def test_parse_deep_yaml_strings(self):
        """Parsing using yaml that contains strings constructor."""
        pod = testing.create_test_pod()
        content = pod.read_file('/data/constructors.yaml')

        # Base strings.
        result = utils.parse_yaml(content, pod=pod)
        self.assertEqual('Sun', result['deep_strings']['sun'])
        self.assertEqual('Mars', result['deep_strings']['mars'])

        # Localized strings.
        result = utils.parse_yaml(content, pod=pod, locale='es')
        self.assertEqual('Sol', result['deep_strings']['sun'])
        self.assertEqual('Marte', result['deep_strings']['mars'])
Ejemplo n.º 17
0
    def test_parse_yaml_localized(self):
        """Parsing yaml with a locale correctly loads the localized values."""
        pod = testing.create_test_pod()
        content = pod.read_file('/data/constructors.yaml')

        # Base unlocalized works.
        result = utils.parse_yaml(content, pod=pod)
        expected = 'base_value'
        self.assertEqual(expected, result['localized'])

        # Other locals correctly localize.
        result = utils.parse_yaml(content, pod=pod, locale='es')
        expected = 'es_value'
        self.assertEqual(expected, result['localized'])
Ejemplo n.º 18
0
    def test_include_obsolete_option(self):
        pod = testing.create_test_pod('extract_localized/localized_pod')
        pod.catalogs.compile()
        pod.catalogs.extract(localized=True, locales=['fr'], include_obsolete=True)

        message = u'Existing message in localized pöd'
        translation = u'Existing FR translation in localized pöd'
        catalog = pod.catalogs.get('fr')

        self.assertExtractedFor(pod, message, ['fr'])
        self.assertEqual(catalog[message].string, translation)

        # we don't use gettext syntax for obsolete translations
        for locale in self.ALL_LOCALES:
            self.assertFalse(pod.catalogs.get(locale).obsolete)
Ejemplo n.º 19
0
    def test_include_obsolete_option(self):
        pod = testing.create_test_pod('extract_localized/localized_pod')
        pod.catalogs.compile()
        pod.catalogs.extract(localized=True, locales=[
                             'fr'], include_obsolete=True)

        message = u'Existing message in localized pöd'
        translation = u'Existing FR translation in localized pöd'
        catalog = pod.catalogs.get('fr')

        self.assertExtractedFor(pod, message, ['fr'])
        self.assertEqual(catalog[message].string, translation)

        # we don't use gettext syntax for obsolete translations
        for locale in self.ALL_LOCALES:
            self.assertFalse(pod.catalogs.get(locale).obsolete)
Ejemplo n.º 20
0
    def test_parse_yaml(self):
        pod = testing.create_test_pod()
        content = pod.read_file('/data/constructors.yaml')
        result = utils.parse_yaml(content, pod=pod)
        doc = pod.get_doc('/content/pages/home.yaml')
        self.assertEqual(doc, result['doc'])
        expected_docs = [
            pod.get_doc('/content/pages/home.yaml'),
            pod.get_doc('/content/pages/about.yaml'),
            pod.get_doc('/content/pages/home.yaml'),
        ]
        self.assertEqual(expected_docs, result['docs'])

        # Test that deep linking to yaml files works.
        expected_deep_yaml = {
            'test': 'deep',
            'deep': 'deeper',
        }
        self.assertEqual(expected_deep_yaml, result['deep'])
        self.assertEqual(None, result['unfathomable'])
Ejemplo n.º 21
0
    def test_extract_localized_for_multiple_locales(self):
        localized_pod = testing.create_test_pod('extract_localized/localized_pod')
        localized_pod.catalogs.compile()
        localized_pod.catalogs.extract(localized=True, locales=['it', 'sv', 'de'])

        unlocalized_pod = testing.create_test_pod('extract_localized/unlocalized_pod')
        unlocalized_pod.catalogs.compile()
        unlocalized_pod.catalogs.extract(localized=True, locales=['it', 'sv', 'de'])

        # These strings are all relevant to both IT & SV
        it_sv_messages = (
            u'Multi-locale doc part body in localized doc in localized collection in localized pöd',
            u'Multi-locale doc part body in localized doc in unlocalized collection in localized pöd',
            u'Multi-locale doc part body in localized doc in localized collection in unlocalized pöd',
            u'Multi-locale doc part body in localized doc in unlocalized collection in unlocalized pöd',
            u'Multi-locale doc part front matter in localized doc in localized collection in localized pöd',
            u'Multi-locale doc part front matter in localized doc in unlocalized collection in localized pöd',
            u'Multi-locale doc part front matter in localized doc in localized collection in unlocalized pöd',
            u'Multi-locale doc part front matter in localized doc in unlocalized collection in unlocalized pöd',
            u'Multi-locale yaml doc part in localized doc in localized collection in localized pöd',
            u'Multi-locale yaml doc part in localized doc in unlocalized collection in localized pöd',
            u'Multi-locale yaml doc part in localized doc in localized collection in unlocalized pöd',
        )
        for message in it_sv_messages:
            if u'unlocalized pöd' in message:
                self.assertExtractedFor(unlocalized_pod, message, ['it', 'sv'])
            else:
                self.assertExtractedFor(localized_pod, message, ['it', 'sv'])

        # These are only relevant to DE
        de_messages = (
            u'Unlocalized doc body in unlocalized collection in localized pöd',
            u'Unlocalized doc front matter in unlocalized collection in localized pöd',
            u'Unlocalized yaml doc in unlocalized collection in localized pöd',
        )

        for message in de_messages:
            if u'unlocalized pöd' in message:
                self.assertExtractedFor(unlocalized_pod, message, ['de'])
            else:
                self.assertExtractedFor(localized_pod, message, ['de'])

        # These are only relevant to FR or no locales, so shouldn't be extracted
        fr_messages = (
            u'Unlocalized doc body in localized collection in localized pöd',
            u'Unlocalized doc body in localized collection in unlocalized pöd',
            u'Unlocalized doc body in unlocalized collection in unlocalized pöd',
            u'Unlocalized doc front matter in localized collection in localized pöd',
            u'Unlocalized doc front matter in localized collection in unlocalized pöd',
            u'Unlocalized doc front matter in unlocalized collection in unlocalized pöd',
            u'Unlocalized yaml doc in localized collection in localized pöd',
            u'Unlocalized yaml doc in localized collection in unlocalized pöd',
            u'Unlocalized yaml doc in unlocalized collection in unlocalized pöd',
            u'Unlocalized pödspec',
        )

        for message in fr_messages:
            if u'unlocalized pöd' in message:
                self.assertExtractedFor(unlocalized_pod, message, [])
            else:
                self.assertExtractedFor(localized_pod, message, [])
Ejemplo n.º 22
0
    def test_extract_localized_for_multiple_locales(self):
        localized_pod = testing.create_test_pod(
            'extract_localized/localized_pod')
        localized_pod.catalogs.compile()
        localized_pod.catalogs.extract(localized=True,
                                       locales=['it', 'sv', 'de'])

        unlocalized_pod = testing.create_test_pod(
            'extract_localized/unlocalized_pod')
        unlocalized_pod.catalogs.compile()
        unlocalized_pod.catalogs.extract(localized=True,
                                         locales=['it', 'sv', 'de'])

        # These strings are all relevant to both IT & SV
        it_sv_messages = (
            u'Multi-locale doc part body in localized doc in localized collection in localized pöd',
            u'Multi-locale doc part body in localized doc in unlocalized collection in localized pöd',
            u'Multi-locale doc part body in localized doc in localized collection in unlocalized pöd',
            u'Multi-locale doc part body in localized doc in unlocalized collection in unlocalized pöd',
            u'Multi-locale doc part front matter in localized doc in localized collection in localized pöd',
            u'Multi-locale doc part front matter in localized doc in unlocalized collection in localized pöd',
            u'Multi-locale doc part front matter in localized doc in localized collection in unlocalized pöd',
            u'Multi-locale doc part front matter in localized doc in unlocalized collection in unlocalized pöd',
            u'Multi-locale yaml doc part in localized doc in localized collection in localized pöd',
            u'Multi-locale yaml doc part in localized doc in unlocalized collection in localized pöd',
            u'Multi-locale yaml doc part in localized doc in localized collection in unlocalized pöd',
        )
        for message in it_sv_messages:
            if u'unlocalized pöd' in message:
                self.assertExtractedFor(unlocalized_pod, message, ['it', 'sv'])
            else:
                self.assertExtractedFor(localized_pod, message, ['it', 'sv'])

        # These are only relevant to DE
        de_messages = (
            u'Unlocalized doc body in unlocalized collection in localized pöd',
            u'Unlocalized doc front matter in unlocalized collection in localized pöd',
            u'Unlocalized yaml doc in unlocalized collection in localized pöd',
        )

        for message in de_messages:
            if u'unlocalized pöd' in message:
                self.assertExtractedFor(unlocalized_pod, message, ['de'])
            else:
                self.assertExtractedFor(localized_pod, message, ['de'])

        # These are only relevant to FR or no locales, so shouldn't be extracted
        fr_messages = (
            u'Unlocalized doc body in localized collection in localized pöd',
            u'Unlocalized doc body in localized collection in unlocalized pöd',
            u'Unlocalized doc body in unlocalized collection in unlocalized pöd',
            u'Unlocalized doc front matter in localized collection in localized pöd',
            u'Unlocalized doc front matter in localized collection in unlocalized pöd',
            u'Unlocalized doc front matter in unlocalized collection in unlocalized pöd',
            u'Unlocalized yaml doc in localized collection in localized pöd',
            u'Unlocalized yaml doc in localized collection in unlocalized pöd',
            u'Unlocalized yaml doc in unlocalized collection in unlocalized pöd',
            u'Unlocalized pödspec',
        )

        for message in fr_messages:
            if u'unlocalized pöd' in message:
                self.assertExtractedFor(unlocalized_pod, message, [])
            else:
                self.assertExtractedFor(localized_pod, message, [])