Make testing style more consistent (#168)
Several overall style changes:
1. Avoid plain `Mock()` and `Mock(spec=thing)`., prefer `mock.create_autospec()`.
1. Don't `mock.patch` without `autospec`.
1. Don't give mock instances special names. Prefer `thing` over `thing_mock` and `mock_thing`.
1. When using `mock.patch`, use the same name as the item being patched to refer to the mock.
```python
with mock.patch('module.thing') as thing:
...
```
and
```
@mock.patch('module.thing')
def test(thing):
...
```
1. Test helper factories should follow the naming convention `make_thing()`.
1. Use `ThingStub` when creating semi-functioning subclasses for testing purposes.
diff --git a/tests/test__oauth2client.py b/tests/test__oauth2client.py
index 1d7a4a8..832b24f 100644
--- a/tests/test__oauth2client.py
+++ b/tests/test__oauth2client.py
@@ -112,16 +112,16 @@
old_credentials.service_account_id)
-class MockCredentials(object):
+class FakeCredentials(object):
pass
def test_convert_success():
- convert_function = mock.Mock()
+ convert_function = mock.Mock(spec=['__call__'])
conversion_map_patch = mock.patch.object(
_oauth2client, '_CLASS_CONVERSION_MAP',
- {MockCredentials: convert_function})
- credentials = MockCredentials()
+ {FakeCredentials: convert_function})
+ credentials = FakeCredentials()
with conversion_map_patch:
result = _oauth2client.convert(credentials)