MCPcopy Create free account
hub / github.com/Kaggle/docker-python / TestCloudTranslation

Class TestCloudTranslation

tests/test_translation.py:15–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13 return Mock(spec=google.auth.credentials.Credentials)
14
15class TestCloudTranslation(unittest.TestCase):
16 class FakeClient:
17 def __init__(self, credentials=None, client_info=None, client_options=None, **kwargs):
18 self.credentials = credentials
19 self.client_options = client_options
20
21 class FakeConnection():
22 def __init__(self, user_agent):
23 self.user_agent = user_agent
24 if (client_info is not None):
25 self._connection = FakeConnection(client_info.user_agent)
26
27 @patch("google.cloud.translate_v2.Client", new=FakeClient)
28 def test_default_credentials_v2(self):
29 env = EnvironmentVarGuard()
30 env.set('KAGGLE_USER_SECRETS_TOKEN', 'foobar')
31 env.set('KAGGLE_KERNEL_INTEGRATIONS', 'CLOUDAI')
32 with env:
33 init_translation_v2()
34 client = translate_v2.Client()
35 self.assertIsNotNone(client.credentials)
36 self.assertIsInstance(client.credentials, KaggleKernelCredentials)
37
38
39 @patch("google.cloud.translate_v2.Client", new=FakeClient)
40 def test_user_provided_credentials_v2(self):
41 credentials = _make_credentials()
42 env = EnvironmentVarGuard()
43 env.set('KAGGLE_USER_SECRETS_TOKEN', 'foobar')
44 env.set('KAGGLE_KERNEL_INTEGRATIONS', 'CLOUDAI')
45 with env:
46 init_translation_v2()
47 client = translate_v2.Client(credentials=credentials)
48 self.assertIsNotNone(client.credentials)
49 self.assertNotIsInstance(client.credentials, KaggleKernelCredentials)
50
51 @patch("google.cloud.translate_v3.TranslationServiceClient", new=FakeClient)
52 def test_default_credentials_v3(self):
53 env = EnvironmentVarGuard()
54 env.set('KAGGLE_USER_SECRETS_TOKEN', 'foobar')
55 env.set('KAGGLE_KERNEL_INTEGRATIONS', 'CLOUDAI')
56 with env:
57 init_translation_v3()
58 client = translate.TranslationServiceClient()
59 self.assertIsNotNone(client.credentials)
60 self.assertIsInstance(client.credentials, KaggleKernelCredentials)
61
62
63 @patch("google.cloud.translate_v3.TranslationServiceClient", new=FakeClient)
64 def test_user_provided_credentials_v3(self):
65 credentials = _make_credentials()
66 env = EnvironmentVarGuard()
67 env.set('KAGGLE_USER_SECRETS_TOKEN', 'foobar')
68 env.set('KAGGLE_KERNEL_INTEGRATIONS', 'CLOUDAI')
69 with env:
70 init_translation_v3()
71 client = translate.TranslationServiceClient(credentials=credentials)
72 self.assertIsNotNone(client.credentials)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected