def test_gp_fallback(self):
        """Test the fallback feature, i.e. when a translated value is not found
        for a language, the fallback language should be used - if there is no
        fallback language then the source value should be returned.

        If the key is not found, the key should be returned.
        """
        acc = common.get_gpserviceaccount()
        client = GPClient(acc)

        # should fallbcak to 'es-mx', 'ur' is not supported
        languages=['ur', 'es-mx', 'fr']
        t = client.gp_translation(bundleId=common.bundleId2,
            languages=languages)
        _ = t.gettext
        value = _('exit')

        common.my_assert_equal(self, u'Adiós', value,
            'incorrect translated value - should have used es-mx fallback')

        # should return key back, key doesn't exist
        languages=['es-mx']
        t = client.gp_translation(bundleId=common.bundleId2,
            languages=languages)
        _ = t.gettext
        key = 'badKey'
        value = _(key)

        common.my_assert_equal(self, key, value,
            'incorrect translated value - key doesn\'t exist')
    def test_gp_fallback(self):
        """Test the fallback feature, i.e. when a translated value is not found
        for a language, the fallback language should be used - if there is no
        fallback language then the source value should be returned.

        If the key is not found, the key should be returned.
        """
        acc = common.get_gpserviceaccount()
        client = GPClient(acc)

        # should fallbcak to 'fr', 'ur' is not supported
        languages = ['ur', 'fr']
        t = client.gp_translation(bundleId=common.bundleId2,
                                  languages=languages)
        _ = t.gettext
        value = _('exit')

        common.my_assert_equal(
            self, u'Au revoir', value,
            'incorrect translated value - should have used fr fallback')

        # should return key back, key doesn't exist
        languages = ['es-mx']
        t = client.gp_translation(bundleId=common.bundleId2,
                                  languages=languages)
        _ = t.gettext
        key = 'badKey'
        value = _(key)

        common.my_assert_equal(
            self, key, value,
            'incorrect translated value - key doesn\'t exist')
    def common_test_caching(self, cacheTimeout=None):
        """Shared code between the various caching tests """
        acc = common.get_gpserviceaccount()

        if cacheTimeout is None:
            client = GPClient(acc)
        else:
            client = GPClient(acc, cacheTimeout=cacheTimeout)

        languages=['fr_CA']
        t = client.gp_translation(bundleId=common.bundleId1,
            languages=languages)
        _ = t.gettext

        # key and translated value used for testing below
        # makes it easier to change
        key = 'greet'
        tValue = 'Bonjour' # translated value

        # check that the translated value is correct
        value = _(key)
        common.my_assert_equal(self, tValue, value,
            'incorrect translated value')

        return (t, _, key, tValue)
    def common_test_caching(self, cacheTimeout=None):
        """Shared code between the various caching tests """
        acc = common.get_gpserviceaccount()

        if cacheTimeout is None:
            client = GPClient(acc)
        else:
            client = GPClient(acc, cacheTimeout=cacheTimeout)

        languages=['fr_CA']
        t = client.gp_translation(bundleId=common.bundleId1,
            languages=languages)
        _ = t.gettext

        # key and translated value used for testing below
        # makes it easier to change
        key = 'greet'
        tValue = 'Salut' # translated value

        # check that the translated value is correct
        value = _(key)
        common.my_assert_equal(self, tValue, value,
            'incorrect translated value')

        return (t, _, key, tValue)
    def test_english_values(self):
        """Verify English values are returned when asked for"""
        acc = common.get_gpserviceaccount()
        client = GPClient(acc)

        languages = ['en']

        t = client.gp_translation(bundleId=common.bundleId1,
                                  languages=languages)
        _ = t.gettext

        value = _('greet')

        common.my_assert_equal(self, 'Hello', value, 'incorrect value')
Exemple #6
0
    def test_basic_auth_translation(self):
        """Test if translation works with basic auth"""
        acc = common.get_gpserviceaccount()
        client = GPClient(acc, auth=GPClient.BASIC_AUTH)
        languages = ['fr']

        t = client.gp_translation(bundleId=common.bundleId2,
                                  languages=languages)
        _ = t.gettext

        value = _('show')

        common.my_assert_equal(self, u'Le Fil', value,
                               'incorrect translated value')
    def test_example_2(self):
        """Test example 2 used in the docs"""
        acc = common.get_gpserviceaccount()
        client = GPClient(acc)

        languages = ['fr']  # languages=[locale.getdefaultlocale()[0]]

        t = client.gp_translation(bundleId=common.bundleId2,
                                  languages=languages)
        _ = t.gettext

        value = _('exit')  # 'exit' key will be localized/translated to French

        common.my_assert_equal(self, u'Au revoir', value,
                               'incorrect translated value')
    def test_example_2(self):
        """Test example 2 used in the docs"""
        acc = common.get_gpserviceaccount()
        client = GPClient(acc)

        languages=['es-mx'] # languages=[locale.getdefaultlocale()[0]]

        t = client.gp_translation(bundleId=common.bundleId2,
            languages=languages)
        _ = t.gettext

        value = _('exit') # 'exit' key will be localized/translated to Spanish

        common.my_assert_equal(self, u'Adiós', value,
            'incorrect translated value')
    def test_english_values(self):
        """Verify English values are returned when asked for"""
        acc = common.get_gpserviceaccount()
        client = GPClient(acc)

        languages=['en']

        t = client.gp_translation(bundleId=common.bundleId1,
            languages=languages)
        _ = t.gettext

        value = _('greet')

        common.my_assert_equal(self, 'Hello', value,
            'incorrect value')
    def test_admin_basic_auth(self):
        """Verify basic auth fails with admin account"""
        acc = common.get_admin_gpserviceaccount()
        client = GPClient(acc, auth=GPClient.BASIC_AUTH)

        languages=['es-mx']

        t = client.gp_translation(bundleId=common.bundleId2,
            languages=languages)
        _ = t.gettext

        value = _('show')

        common.my_assert_equal(self, 'show', value,
            'admin acc can not use basic auth')
    def test_basic_auth_translation(self):
        """Test if translation works with basic auth"""
        acc = common.get_gpserviceaccount()
        client = GPClient(acc, auth=GPClient.BASIC_AUTH)

        languages=['es-mx']

        t = client.gp_translation(bundleId=common.bundleId2,
            languages=languages)
        _ = t.gettext

        value = _('show')

        common.my_assert_equal(self, u'El físico', value,
            'incorrect translated value')
    def test_example_1(self):
        """Test example 1 used in the docs"""
        common.set_vcap_env_vars()

        acc = GPServiceAccount()
        client = GPClient(acc)

        languages=['fr_CA'] # languages=[locale.getdefaultlocale()[0]]

        t = client.gp_translation(bundleId=common.bundleId1,
            languages=languages)
        _ = t.gettext

        value = _('greet') # 'greet' key will be localized/translated to French

        common.my_assert_equal(self, 'Bonjour', value,
            'incorrect translated value')
    def test_example_1(self):
        """Test example 1 used in the docs"""
        #common.set_vcap_env_vars()

        acc = common.get_gpserviceaccount()
        client = GPClient(acc)

        languages = ['fr']  # languages=[locale.getdefaultlocale()[0]]

        t = client.gp_translation(bundleId=common.bundleId1,
                                  languages=languages)
        _ = t.gettext

        value = _(
            'greet')  # 'greet' key will be localized/translated to French

        common.my_assert_equal(self, 'Salut', value,
                               'incorrect translated value')