4
4
5
5
from kaggle_gcp import KaggleKernelCredentials , init_automl
6
6
from test .support import EnvironmentVarGuard
7
- from google .cloud import storage , automl_v1beta1 as automl
8
- from packaging .version import parse
7
+ from google .cloud import storage , automl_v1beta1 , automl
9
8
10
9
def _make_credentials ():
11
10
import google .auth .credentials
12
11
return Mock (spec = google .auth .credentials .Credentials )
13
12
14
13
class TestAutoMl (unittest .TestCase ):
15
14
16
- def test_version (self ):
17
- self .assertIsNotNone (automl .auto_ml_client ._GAPIC_LIBRARY_VERSION )
18
- self .assertGreaterEqual (parse (automl .auto_ml_client ._GAPIC_LIBRARY_VERSION ), parse ("0.5.0" ))
19
-
20
15
class FakeClient :
21
16
def __init__ (self , credentials = None , client_info = None , ** kwargs ):
22
17
self .credentials = credentials
@@ -27,7 +22,7 @@ def __init__(self, user_agent):
27
22
if (client_info is not None ):
28
23
self ._connection = FakeConnection (client_info .user_agent )
29
24
30
- @patch ("google.cloud.automl_v1beta1 .AutoMlClient" , new = FakeClient )
25
+ @patch ("google.cloud.automl .AutoMlClient" , new = FakeClient )
31
26
def test_user_provided_credentials (self ):
32
27
credentials = _make_credentials ()
33
28
env = EnvironmentVarGuard ()
@@ -42,10 +37,10 @@ def test_user_provided_credentials(self):
42
37
def test_tables_gcs_client (self ):
43
38
# The GcsClient can't currently be monkeypatched for default
44
39
# credentials because it requires a project which can't be set.
45
- # Verify that creating an automl .GcsClient given an actual
40
+ # Verify that creating an automl_v1beta1 .GcsClient given an actual
46
41
# storage.Client sets the client properly.
47
42
gcs_client = storage .Client (project = "xyz" , credentials = _make_credentials ())
48
- tables_gcs_client = automl .GcsClient (client = gcs_client )
43
+ tables_gcs_client = automl_v1beta1 .GcsClient (client = gcs_client )
49
44
self .assertIs (tables_gcs_client .client , gcs_client )
50
45
51
46
@patch ("google.cloud.automl_v1beta1.gapic.auto_ml_client.AutoMlClient" , new = FakeClient )
@@ -56,10 +51,10 @@ def test_tables_client_credentials(self):
56
51
env .set ('KAGGLE_KERNEL_INTEGRATIONS' , 'AUTOML' )
57
52
with env :
58
53
init_automl ()
59
- tables_client = automl .TablesClient (credentials = credentials )
54
+ tables_client = automl_v1beta1 .TablesClient (credentials = credentials )
60
55
self .assertEqual (tables_client .auto_ml_client .credentials , credentials )
61
56
62
- @patch ("google.cloud.automl_v1beta1 .AutoMlClient" , new = FakeClient )
57
+ @patch ("google.cloud.automl .AutoMlClient" , new = FakeClient )
63
58
def test_default_credentials_automl_client (self ):
64
59
env = EnvironmentVarGuard ()
65
60
env .set ('KAGGLE_USER_SECRETS_TOKEN' , 'foobar' )
@@ -71,18 +66,31 @@ def test_default_credentials_automl_client(self):
71
66
self .assertIsInstance (automl_client .credentials , KaggleKernelCredentials )
72
67
self .assertTrue (automl_client ._connection .user_agent .startswith ("kaggle-gcp-client/1.0" ))
73
68
69
+ @patch ("google.cloud.automl_v1beta1.AutoMlClient" , new = FakeClient )
70
+ def test_default_credentials_automl_v1beta1_client (self ):
71
+ env = EnvironmentVarGuard ()
72
+ env .set ('KAGGLE_USER_SECRETS_TOKEN' , 'foobar' )
73
+ env .set ('KAGGLE_KERNEL_INTEGRATIONS' , 'AUTOML' )
74
+ with env :
75
+ init_automl ()
76
+ automl_client = automl_v1beta1 .AutoMlClient ()
77
+ self .assertIsNotNone (automl_client .credentials )
78
+ self .assertIsInstance (automl_client .credentials , KaggleKernelCredentials )
79
+ self .assertTrue (automl_client ._connection .user_agent .startswith ("kaggle-gcp-client/1.0" ))
80
+
74
81
@patch ("google.cloud.automl_v1beta1.TablesClient" , new = FakeClient )
75
82
def test_default_credentials_tables_client (self ):
76
83
env = EnvironmentVarGuard ()
77
84
env .set ('KAGGLE_USER_SECRETS_TOKEN' , 'foobar' )
78
85
env .set ('KAGGLE_KERNEL_INTEGRATIONS' , 'AUTOML' )
79
86
with env :
80
87
init_automl ()
81
- tables_client = automl .TablesClient ()
88
+ tables_client = automl_v1beta1 .TablesClient ()
82
89
self .assertIsNotNone (tables_client .credentials )
83
90
self .assertIsInstance (tables_client .credentials , KaggleKernelCredentials )
91
+ self .assertTrue (tables_client ._connection .user_agent .startswith ("kaggle-gcp-client/1.0" ))
84
92
85
- @patch ("google.cloud.automl_v1beta1 .PredictionServiceClient" , new = FakeClient )
93
+ @patch ("google.cloud.automl .PredictionServiceClient" , new = FakeClient )
86
94
def test_default_credentials_prediction_client (self ):
87
95
env = EnvironmentVarGuard ()
88
96
env .set ('KAGGLE_USER_SECRETS_TOKEN' , 'foobar' )
@@ -91,6 +99,18 @@ def test_default_credentials_prediction_client(self):
91
99
prediction_client = automl .PredictionServiceClient ()
92
100
self .assertIsNotNone (prediction_client .credentials )
93
101
self .assertIsInstance (prediction_client .credentials , KaggleKernelCredentials )
102
+ self .assertTrue (prediction_client ._connection .user_agent .startswith ("kaggle-gcp-client/1.0" ))
103
+
104
+ @patch ("google.cloud.automl_v1beta1.PredictionServiceClient" , new = FakeClient )
105
+ def test_default_credentials_prediction_v1beta1_client (self ):
106
+ env = EnvironmentVarGuard ()
107
+ env .set ('KAGGLE_USER_SECRETS_TOKEN' , 'foobar' )
108
+ env .set ('KAGGLE_KERNEL_INTEGRATIONS' , 'AUTOML' )
109
+ with env :
110
+ prediction_client = automl_v1beta1 .PredictionServiceClient ()
111
+ self .assertIsNotNone (prediction_client .credentials )
112
+ self .assertIsInstance (prediction_client .credentials , KaggleKernelCredentials )
113
+ self .assertTrue (prediction_client ._connection .user_agent .startswith ("kaggle-gcp-client/1.0" ))
94
114
95
115
def test_monkeypatching_idempotent (self ):
96
116
env = EnvironmentVarGuard ()
0 commit comments