Exemplo n.º 1
0
 def test_supported_locales_invalid_response(self, req_mock):
     req_mock.get(
         'http://service-text-service:1555/v1/text/info/scope/unnamed-skill',
         text='')
     service = TextService()
     result = service.supported_locales()
     self.assertEqual(result, [])
Exemplo n.º 2
0
 def test_supported_locales_requests_exception(self, req_mock):
     req_mock.get(
         'http://service-text-service:1555/v1/text/info/scope/unnamed-skill',
         exc=exceptions.RequestException)
     service = TextService()
     result = service.supported_locales()
     self.assertEqual(result, [])
Exemplo n.º 3
0
    def test_supported_locales(self, req_mock):
        req_mock.get(
            'http://service-text-service:1555/v1/text/info/scope/unnamed-skill',
            text='{"supportedLanguages": [{"code": "de"}, {"code": "en"}]}')

        service = TextService()
        result = service.supported_locales()
        self.assertEqual(result, ['de', 'en'])
Exemplo n.º 4
0
 def test_get_translation_catalog_exception(self, req_mock):
     from skill_sdk import requests
     from collections import defaultdict
     req_mock.get(
         'http://service-text-service:1555/v1/text/en/unnamed-skill',
         exc=requests.BadHttpResponseCodeException(500))
     service = TextService()
     result = service.get_translation_catalog('en')
     self.assertEqual(result, defaultdict(list))
Exemplo n.º 5
0
    def test_additional_headers(self, config_mock, log_mock, req_mock):
        service = TextService(headers={"Authorization": "Bearer eyJ123"})
        req_mock.get(
            'http://service-text-service:1555/v1/text/info/scope/unnamed-skill',
            request_headers={'Authorization': 'Bearer eyJ123'},
            text='{"supportedLanguages": [{"code": "aa"}, {"code": "bb"}]}')

        self.assertEqual(['aa', 'bb'], service.supported_locales())
        log_mock.assert_any_call(
            "Additional headers: {'Authorization': '*****'}")
Exemplo n.º 6
0
    def test_auth_header(self, config_mock, log_mock, req_mock):
        config_mock['service-text'] = {'auth_header': 'true'}
        req_mock.get(
            'http://service-text-service:1555/v1/text/info/scope/unnamed-skill',
            request_headers={
                'Accept': 'application/json',
                'Content-Type': 'application/json',
                'Authorization': 'Bearer eyJ123'
            })

        with patch('skill_sdk.services.base.request') as r:
            r.json = {
                "context": {
                    "attributes": {
                        'location': 'Berlin'
                    },
                    "intent": "TELEKOM_Demo_Intent",
                    "locale": "de",
                    "tokens": {
                        "cvi": "eyJ123"
                    },
                    "clientAttributes": {}
                }
            }
            TextService().supported_locales()
        log_mock.assert_any_call('Adding CVI token to authorization header.')
Exemplo n.º 7
0
    def test_headers(self, config_mock, log_mock, req_mock):
        config_mock['service-text'] = {'auth_header': 'true'}
        service = TextService()

        req_mock.get(
            'http://service-text-service:1555/v1/text/info/scope/unnamed-skill',
            request_headers={
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            text='{"supportedLanguages": [{"code": "aa"}, {"code": "bb"}]}')

        self.assertEqual(['aa', 'bb'], service.supported_locales())
        log_mock.assert_called_once_with(
            'Authorization header is requested, but no CVI token found in the current request.'
        )
Exemplo n.º 8
0
def _download_full_catalog(
    download_url: Text, scope: Text, token: Text = None, tenant: Text = None
) -> Dict:
    """
    Download a complete translation catalog from text service

    :param download_url:
    :param token:
    :param tenant:
    :return:
    """

    from skill_sdk.services.text import TextService

    logger.info(f"Downloading translations from {download_url}...")

    headers = {"X-Application-Authentication": f"Bearer {token}"} if token else {}
    headers.update({"X-Tenant": tenant}) if tenant else None

    service = TextService(download_url, scope, headers=headers, add_auth_header=False)
    return service.admin_get_full_catalog()