Skip to content

Commit eb38c84

Browse files
author
Jon Wayne Parrott
authored
Raise ValueError if credentials are not from google-auth (#2828)
1 parent 0b6afe0 commit eb38c84

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

packages/google-cloud-dns/tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ localdeps =
77
pip install --quiet --upgrade {toxinidir}/../core
88
deps =
99
{toxinidir}/../core
10+
mock
1011
pytest
1112
covercmd =
1213
py.test --quiet \

packages/google-cloud-dns/unit_tests/test_client.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414

1515
import unittest
1616

17+
import mock
18+
19+
20+
def _make_credentials():
21+
import google.auth.credentials
22+
return mock.Mock(spec=google.auth.credentials.Credentials)
23+
1724

1825
class TestClient(unittest.TestCase):
1926

@@ -30,7 +37,7 @@ def _make_one(self, *args, **kw):
3037

3138
def test_ctor(self):
3239
from google.cloud.dns.connection import Connection
33-
creds = object()
40+
creds = _make_credentials()
3441
http = object()
3542
client = self._make_one(project=self.PROJECT, credentials=creds,
3643
http=http)
@@ -58,7 +65,7 @@ def test_quotas_defaults(self):
5865
}
5966
CONVERTED = {key: int(value)
6067
for key, value in DATA['quota'].items()}
61-
creds = object()
68+
creds = _make_credentials()
6269
client = self._make_one(self.PROJECT, creds)
6370
conn = client._connection = _Connection(DATA)
6471

@@ -93,7 +100,7 @@ def test_quotas_w_kind_key(self):
93100
for key, value in DATA['quota'].items()}
94101
WITH_KIND = {'quota': DATA['quota'].copy()}
95102
WITH_KIND['quota']['kind'] = 'dns#quota'
96-
creds = object()
103+
creds = _make_credentials()
97104
client = self._make_one(self.PROJECT, creds)
98105
conn = client._connection = _Connection(WITH_KIND)
99106

@@ -130,7 +137,7 @@ def test_list_zones_defaults(self):
130137
'dnsName': DNS_2},
131138
]
132139
}
133-
creds = object()
140+
creds = _make_credentials()
134141
client = self._make_one(self.PROJECT, creds)
135142
conn = client._connection = _Connection(DATA)
136143

@@ -175,7 +182,7 @@ def test_list_zones_explicit(self):
175182
'dnsName': DNS_2},
176183
]
177184
}
178-
creds = object()
185+
creds = _make_credentials()
179186
client = self._make_one(self.PROJECT, creds)
180187
conn = client._connection = _Connection(DATA)
181188

@@ -203,7 +210,7 @@ def test_zone_explicit(self):
203210
from google.cloud.dns.zone import ManagedZone
204211
DESCRIPTION = 'DESCRIPTION'
205212
DNS_NAME = 'test.example.com'
206-
creds = object()
213+
creds = _make_credentials()
207214
client = self._make_one(self.PROJECT, creds)
208215
zone = client.zone(self.ZONE_NAME, DNS_NAME, DESCRIPTION)
209216
self.assertIsInstance(zone, ManagedZone)
@@ -215,7 +222,7 @@ def test_zone_explicit(self):
215222
def test_zone_w_dns_name_wo_description(self):
216223
from google.cloud.dns.zone import ManagedZone
217224
DNS_NAME = 'test.example.com'
218-
creds = object()
225+
creds = _make_credentials()
219226
client = self._make_one(self.PROJECT, creds)
220227
zone = client.zone(self.ZONE_NAME, DNS_NAME)
221228
self.assertIsInstance(zone, ManagedZone)
@@ -226,7 +233,7 @@ def test_zone_w_dns_name_wo_description(self):
226233

227234
def test_zone_wo_dns_name(self):
228235
from google.cloud.dns.zone import ManagedZone
229-
creds = object()
236+
creds = _make_credentials()
230237
client = self._make_one(self.PROJECT, creds)
231238
zone = client.zone(self.ZONE_NAME)
232239
self.assertIsInstance(zone, ManagedZone)

0 commit comments

Comments
 (0)