1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from devtools_testutils.aio import recorded_by_proxy_async
from preparer import TextTranslationPreparer
from testcase import TextTranslationTest
class TestGetLanguagesAsync(TextTranslationTest):
@TextTranslationPreparer()
@recorded_by_proxy_async
async def test_all_scopes(self, **kwargs):
endpoint = kwargs.get("text_translation_endpoint")
client = self.create_async_getlanguage_client(endpoint)
async with client:
response = await client.get_supported_languages()
assert len(response.translation) > 0
assert len(response.transliteration) > 0
assert len(response.dictionary) > 0
@TextTranslationPreparer()
@recorded_by_proxy_async
async def test_translation_scope(self, **kwargs):
endpoint = kwargs.get("text_translation_endpoint")
client = self.create_async_getlanguage_client(endpoint)
async with client:
response = await client.get_supported_languages(scope="translation")
assert len(response.translation) > 0
translations = response.translation["af"]
assert translations.dir is not None
assert translations.name is not None
assert translations.native_name is not None
@TextTranslationPreparer()
@recorded_by_proxy_async
async def test_transliteration_scope(self, **kwargs):
endpoint = kwargs.get("text_translation_endpoint")
client = self.create_async_getlanguage_client(endpoint)
async with client:
response = await client.get_supported_languages(scope="transliteration")
assert len(response.transliteration) > 0
transliterations = response.transliteration["be"]
assert transliterations.name is not None
assert transliterations.native_name is not None
assert transliterations.scripts is not None
assert len(transliterations.scripts) > 0
assert transliterations.scripts[0].name is not None
assert transliterations.scripts[0].native_name is not None
assert transliterations.scripts[0].code is not None
assert transliterations.scripts[0].dir is not None
assert transliterations.scripts[0].to_scripts is not None
assert len(transliterations.scripts[0].to_scripts) > 0
assert transliterations.scripts[0].to_scripts[0].name is not None
assert transliterations.scripts[0].to_scripts[0].native_name is not None
assert transliterations.scripts[0].to_scripts[0].code is not None
assert transliterations.scripts[0].to_scripts[0].dir is not None
@TextTranslationPreparer()
@recorded_by_proxy_async
async def test_transliteration_multiple_scripts(self, **kwargs):
endpoint = kwargs.get("text_translation_endpoint")
client = self.create_async_getlanguage_client(endpoint)
async with client:
response = await client.get_supported_languages(scope="transliteration")
assert len(response.transliteration) > 0
transliterations = response.transliteration["zh-Hant"]
assert transliterations.name is not None
assert transliterations.native_name is not None
assert transliterations.scripts is not None
assert len(transliterations.scripts) > 1
assert len(transliterations.scripts[0].to_scripts) > 1
assert len(transliterations.scripts[1].to_scripts) > 1
@TextTranslationPreparer()
@recorded_by_proxy_async
async def test_dictionary_scope(self, **kwargs):
endpoint = kwargs.get("text_translation_endpoint")
client = self.create_async_getlanguage_client(endpoint)
async with client:
response = await client.get_supported_languages(scope="dictionary")
assert len(response.dictionary) > 0
dictionaries = response.dictionary["de"]
assert dictionaries.name is not None
assert dictionaries.native_name is not None
assert len(dictionaries.translations) > 0
assert dictionaries.translations[0].code is not None
assert dictionaries.translations[0].dir is not None
assert dictionaries.translations[0].name is not None
assert dictionaries.translations[0].native_name is not None
@TextTranslationPreparer()
@recorded_by_proxy_async
async def test_dictionary_multiple_translations(self, **kwargs):
endpoint = kwargs.get("text_translation_endpoint")
client = self.create_async_getlanguage_client(endpoint)
async with client:
response = await client.get_supported_languages(scope="dictionary")
assert len(response.dictionary) > 0
dictionaries = response.dictionary["en"]
assert dictionaries.name is not None
assert dictionaries.native_name is not None
assert len(dictionaries.translations) > 1
assert dictionaries.translations[0].code is not None
assert dictionaries.translations[0].dir is not None
assert dictionaries.translations[0].name is not None
assert dictionaries.translations[0].native_name is not None
@TextTranslationPreparer()
@recorded_by_proxy_async
async def test_with_culture(self, **kwargs):
endpoint = kwargs.get("text_translation_endpoint")
client = self.create_async_getlanguage_client(endpoint)
async with client:
response = await client.get_supported_languages(accept_language="es")
assert len(response.translation.items()) > 0
assert len(response.transliteration.items()) > 0
assert len(response.dictionary.items()) > 0
translations = response.translation["en"]
assert translations.dir is not None
assert translations.name is not None
assert translations.native_name is not None
|