| 13 | return Mock(spec=google.auth.credentials.Credentials) |
| 14 | |
| 15 | class 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) |
nothing calls this directly
no outgoing calls
no test coverage detected