Skip to content

Commit 12231de

Browse files
Modify test_client tests to take service_url parameter into acccount
1 parent d45009a commit 12231de

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

bigquery/tests/test_client.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def test_initialize_readonly(self, mock_build, mock_return_cred):
5050

5151
mock_cred = mock.Mock()
5252
mock_http = mock.Mock()
53+
mock_service_url = mock.Mock()
5354
mock_cred.return_value.authorize.return_value = mock_http
5455
mock_bq = mock.Mock()
5556
mock_build.return_value = mock_bq
@@ -59,14 +60,16 @@ def test_initialize_readonly(self, mock_build, mock_return_cred):
5960
mock_return_cred.return_value = mock_cred
6061

6162
bq_client = client.get_client(
62-
project_id, service_account=service_account, private_key=key,
63+
project_id, service_url=mock_service_url,
64+
service_account=service_account, private_key=key,
6365
readonly=True)
6466

6567
mock_return_cred.assert_called_once_with()
6668
mock_cred.assert_called_once_with(service_account, key,
6769
scope=BIGQUERY_SCOPE_READ_ONLY)
6870
self.assertTrue(mock_cred.return_value.authorize.called)
69-
mock_build.assert_called_once_with('bigquery', 'v2', http=mock_http)
71+
mock_build.assert_called_once_with('bigquery', 'v2', http=mock_http,
72+
discoveryServiceUrl=mock_service_url)
7073
self.assertEquals(mock_bq, bq_client.bigquery)
7174
self.assertEquals(project_id, bq_client.project_id)
7275

@@ -80,6 +83,7 @@ def test_initialize_read_write(self, mock_build, mock_return_cred):
8083

8184
mock_cred = mock.Mock()
8285
mock_http = mock.Mock()
86+
mock_service_url = mock.Mock()
8387
mock_cred.return_value.authorize.return_value = mock_http
8488
mock_bq = mock.Mock()
8589
mock_build.return_value = mock_bq
@@ -89,14 +93,16 @@ def test_initialize_read_write(self, mock_build, mock_return_cred):
8993
mock_return_cred.return_value = mock_cred
9094

9195
bq_client = client.get_client(
92-
project_id, service_account=service_account, private_key=key,
96+
project_id, service_url=mock_service_url,
97+
service_account=service_account, private_key=key,
9398
readonly=False)
9499

95100
mock_return_cred.assert_called_once_with()
96101
mock_cred.assert_called_once_with(service_account, key,
97102
scope=BIGQUERY_SCOPE)
98103
self.assertTrue(mock_cred.return_value.authorize.called)
99-
mock_build.assert_called_once_with('bigquery', 'v2', http=mock_http)
104+
mock_build.assert_called_once_with('bigquery', 'v2', http=mock_http,
105+
discoveryServiceUrl=mock_service_url)
100106
self.assertEquals(mock_bq, bq_client.bigquery)
101107
self.assertEquals(project_id, bq_client.project_id)
102108

@@ -112,6 +118,7 @@ def test_initialize_key_file(self, mock_open, mock_build,
112118

113119
mock_cred = mock.Mock()
114120
mock_http = mock.Mock()
121+
mock_service_url = mock.Mock()
115122
mock_cred.return_value.authorize.return_value = mock_http
116123
mock_bq = mock.Mock()
117124
mock_build.return_value = mock_bq
@@ -123,15 +130,17 @@ def test_initialize_key_file(self, mock_open, mock_build,
123130
mock_return_cred.return_value = mock_cred
124131

125132
bq_client = client.get_client(
126-
project_id, service_account=service_account,
133+
project_id, service_url=mock_service_url,
134+
service_account=service_account,
127135
private_key_file=key_file, readonly=False)
128136

129137
mock_open.assert_called_once_with(key_file, 'rb')
130138
mock_return_cred.assert_called_once_with()
131139
mock_cred.assert_called_once_with(service_account, key,
132140
scope=BIGQUERY_SCOPE)
133141
self.assertTrue(mock_cred.return_value.authorize.called)
134-
mock_build.assert_called_once_with('bigquery', 'v2', http=mock_http)
142+
mock_build.assert_called_once_with('bigquery', 'v2', http=mock_http,
143+
discoveryServiceUrl=mock_service_url)
135144
self.assertEquals(mock_bq, bq_client.bigquery)
136145
self.assertEquals(project_id, bq_client.project_id)
137146

@@ -147,6 +156,7 @@ def test_initialize_json_key_file(self, mock_open, mock_build, mock_return_cred)
147156

148157
mock_cred = mock.Mock()
149158
mock_http = mock.Mock()
159+
mock_service_url = mock.Mock()
150160
mock_cred.return_value.authorize.return_value = mock_http
151161
mock_bq = mock.Mock()
152162
mock_build.return_value = mock_bq
@@ -156,13 +166,14 @@ def test_initialize_json_key_file(self, mock_open, mock_build, mock_return_cred)
156166
project_id = 'project'
157167
mock_return_cred.return_value = mock_cred
158168

159-
bq_client = client.get_client(project_id, json_key_file=json_key_file, readonly=False)
169+
bq_client = client.get_client(
170+
project_id, service_url=mock_service_url, json_key_file=json_key_file, readonly=False)
160171

161172
mock_open.assert_called_once_with(json_key_file, 'r')
162173
mock_return_cred.assert_called_once_with()
163174
mock_cred.assert_called_once_with(json_key['client_email'], json_key['private_key'], scope=BIGQUERY_SCOPE)
164175
self.assertTrue(mock_cred.return_value.authorize.called)
165-
mock_build.assert_called_once_with('bigquery', 'v2', http=mock_http)
176+
mock_build.assert_called_once_with('bigquery', 'v2', http=mock_http, discoveryServiceUrl=mock_service_url)
166177
self.assertEquals(mock_bq, bq_client.bigquery)
167178
self.assertEquals(project_id, bq_client.project_id)
168179

0 commit comments

Comments
 (0)