|
| 1 | +# This is test code, globally disable docstrings. |
| 2 | +# pylint: disable=missing-docstring |
1 | 3 | import unittest2 |
2 | 4 |
|
3 | 5 |
|
4 | | -class TestCredentials(unittest2.TestCase): |
| 6 | +class TestCredentials(unittest2.TestCase): # pylint: disable=R0904 |
5 | 7 |
|
6 | | - def _getTargetClass(self): |
| 8 | + def _getTargetClass(self): # pylint: disable=invalid-name,no-self-use |
7 | 9 | from gcloud.credentials import Credentials |
8 | 10 | return Credentials |
9 | 11 |
|
10 | | - def test_get_for_service_account_wo_scope(self): |
| 12 | + def test_get_for_service_account_wo_scope(self): # pylint: disable=C0103 |
11 | 13 | from tempfile import NamedTemporaryFile |
12 | 14 | from gcloud import credentials |
| 15 | + # pylint: disable=invalid-name |
13 | 16 | CLIENT_EMAIL = 'phred@example.com' |
14 | 17 | PRIVATE_KEY = 'SEEkR1t' |
| 18 | + # pylint: enable=invalid-name |
15 | 19 | cls = self._getTargetClass() |
16 | 20 | client = _Client() |
17 | 21 | with _Monkey(credentials, client=client): |
18 | | - with NamedTemporaryFile() as f: |
19 | | - f.write(PRIVATE_KEY) |
20 | | - f.flush() |
21 | | - found = cls.get_for_service_account(CLIENT_EMAIL, f.name) |
| 22 | + with NamedTemporaryFile() as file_obj: |
| 23 | + file_obj.write(PRIVATE_KEY) |
| 24 | + file_obj.flush() |
| 25 | + found = cls.get_for_service_account(CLIENT_EMAIL, |
| 26 | + file_obj.name) |
| 27 | + # pylint: disable=protected-access |
22 | 28 | self.assertTrue(found is client._signed) |
23 | | - self.assertEqual(client._called_with, |
24 | | - {'service_account_name': CLIENT_EMAIL, |
25 | | - 'private_key': PRIVATE_KEY, |
26 | | - 'scope': None, |
27 | | - }) |
| 29 | + expected_called_with = {'service_account_name': CLIENT_EMAIL, |
| 30 | + 'private_key': PRIVATE_KEY, |
| 31 | + 'scope': None} |
| 32 | + self.assertEqual(client._called_with, expected_called_with) |
| 33 | + # pylint: enable=protected-access |
28 | 34 |
|
29 | | - def test_get_for_service_account_w_scope(self): |
| 35 | + def test_get_for_service_account_w_scope(self): # pylint: disable=C0103 |
30 | 36 | from tempfile import NamedTemporaryFile |
31 | 37 | from gcloud import credentials |
| 38 | + # pylint: disable=invalid-name |
32 | 39 | CLIENT_EMAIL = 'phred@example.com' |
33 | 40 | PRIVATE_KEY = 'SEEkR1t' |
34 | 41 | SCOPE = 'SCOPE' |
| 42 | + # pylint: enable=invalid-name |
35 | 43 | cls = self._getTargetClass() |
36 | 44 | client = _Client() |
37 | 45 | with _Monkey(credentials, client=client): |
38 | | - with NamedTemporaryFile() as f: |
39 | | - f.write(PRIVATE_KEY) |
40 | | - f.flush() |
41 | | - found = cls.get_for_service_account(CLIENT_EMAIL, f.name, |
42 | | - SCOPE) |
| 46 | + with NamedTemporaryFile() as file_obj: |
| 47 | + file_obj.write(PRIVATE_KEY) |
| 48 | + file_obj.flush() |
| 49 | + found = cls.get_for_service_account(CLIENT_EMAIL, |
| 50 | + file_obj.name, SCOPE) |
| 51 | + # pylint: disable=protected-access |
43 | 52 | self.assertTrue(found is client._signed) |
44 | | - self.assertEqual(client._called_with, |
45 | | - {'service_account_name': CLIENT_EMAIL, |
46 | | - 'private_key': PRIVATE_KEY, |
47 | | - 'scope': SCOPE, |
48 | | - }) |
| 53 | + expected_called_with = {'service_account_name': CLIENT_EMAIL, |
| 54 | + 'private_key': PRIVATE_KEY, |
| 55 | + 'scope': SCOPE} |
| 56 | + self.assertEqual(client._called_with, expected_called_with) |
| 57 | + # pylint: enable=protected-access |
49 | 58 |
|
50 | 59 |
|
51 | | -class _Client(object): |
52 | | - |
| 60 | +class _Client(object): # pylint: disable=too-few-public-methods |
53 | 61 | def __init__(self): |
54 | 62 | self._signed = object() |
55 | 63 |
|
56 | | - def SignedJwtAssertionCredentials(self, **kw): |
| 64 | + def SignedJwtAssertionCredentials(self, **kw): # pylint: disable=C0103 |
| 65 | + # pylint: disable=attribute-defined-outside-init |
57 | 66 | self._called_with = kw |
| 67 | + # pylint: enable=attribute-defined-outside-init |
58 | 68 | return self._signed |
59 | 69 |
|
60 | 70 |
|
61 | | -class _Monkey(object): |
| 71 | +class _Monkey(object): # pylint: disable=too-few-public-methods |
| 72 | + |
62 | 73 | # context-manager for replacing module names in the scope of a test. |
63 | 74 |
|
64 | 75 | def __init__(self, module, **kw): |
|
0 commit comments