Conversation
|
I'll fix up the lint errors in a change I'm making that adds some tests. |
|
@tswast SG, just ping when you're ready for review. |
|
@jonparrott Okay, ready for review. I added tests that mock out the flow using a service account like we discussed in chat. |
There was a problem hiding this comment.
I'd be great to not have this in the repository, is there any reason for it?
There was a problem hiding this comment.
Removed.
Not needed after I changed the tests to mock out user credentials. I'll make sure the docs say to put such a file here.
There was a problem hiding this comment.
auth_query doesn't ring well to me as a good name. Maybe authenticate_and_query?
There was a problem hiding this comment.
you can use py.test's monkeypatch fixture for this or decorate with @mock.patch('google_auth_oauthlib.flow.InstalledAppFlow', new=MockFlow).
There was a problem hiding this comment.
Better yet, I'd actually prefer you to write a new fixture for this using Mock's autospec. This will ensure that even if google-auth-oauthlib's API changes, our test will catch the interface change despite the mocking:
@pytest.fixture
def mock_flow():
flow_patch = mock.patch('google_oauthlib_flow.InstalledAppFlow', autospec=True)
with flow_patch as flow_mock:
flow_mock.credentials = google.auth.default()[0]
yield flow_mockThere was a problem hiding this comment.
Done, autospec is quite cool.
There was a problem hiding this comment.
No need for the comments. :)
There was a problem hiding this comment.
No need for this test. We're really not after exhaustive coverage.
Mocks out user credentials using the Application Default Credentials, but uses the same scopes.
|
Thanks for doing this, @tswast! |
…loudPlatform/python-docs-samples#925) * BigQuery: user credentials to run a query. * BigQuery user creds sample: add tests. Mocks out user credentials using the Application Default Credentials, but uses the same scopes.
…loudPlatform/python-docs-samples#925) * BigQuery: user credentials to run a query. * BigQuery user creds sample: add tests. Mocks out user credentials using the Application Default Credentials, but uses the same scopes.
…rm/python-docs-samples#925) * BigQuery: user credentials to run a query. * BigQuery user creds sample: add tests. Mocks out user credentials using the Application Default Credentials, but uses the same scopes.
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
I'm not sure how to test this one.
Is it possible to add tests that only run locally not on Jenkins, Travis, or Circle?