Skip to content

Explicit auth tests #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ sudo: false
language: python

env:
- PYTHON=2.7 PANDAS=0.19.2 COVERAGE='false' LINT='true' PYENV_VERSION=2.7.14
- PYTHON=3.5 PANDAS=0.18.1 COVERAGE='true' LINT='false' PYENV_VERSION=3.5.4
- PYTHON=3.6 PANDAS=0.20.1 COVERAGE='false' LINT='false' PYENV_VERSION=3.6.1
- PYTHON=3.6 PANDAS=MASTER COVERAGE='false' LINT='true' PYENV_VERSION=3.6.1
- PYTHON=2.7 PANDAS=0.19.2 COVERAGE='false' LINT='true' PYENV_VERSION=2.7.14 AUTH='s_path'
- PYTHON=3.5 PANDAS=0.18.1 COVERAGE='true' LINT='false' PYENV_VERSION=3.5.4 AUTH='s_path'
- PYTHON=3.6 PANDAS=0.20.1 COVERAGE='false' LINT='false' PYENV_VERSION=3.6.1 AUTH='s_cred'
- PYTHON=3.6 PANDAS=MASTER COVERAGE='false' LINT='true' PYENV_VERSION=3.6.1 AUTH='s_cred'

before_install:
- echo "before_install"
Expand Down
12 changes: 11 additions & 1 deletion nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import nox


PANDAS_PRE_WHEELS = (
'https://7933911d6844c6c53a7d-47bd50c35cd79bd838daf386af554a83'
'.ssl.cf2.rackcdn.com')
Expand All @@ -21,6 +20,12 @@ def default(session):
'pytest',
os.path.join('.', 'tests', 'unit'),
os.path.join('.', 'tests', 'system.py'),
os.path.join('.', 'tests', 'unit'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like unit tests got included twice.

"-m 'not local_auth and not {}'".format(
's_cred_auth'
if os.environ['AUTH'] == 's_path' else
's_path_auth'
),
'--quiet',
'--cov=pandas_gbq',
'--cov=tests.unit',
Expand All @@ -37,6 +42,11 @@ def unit(session):
session.run(
'pytest',
os.path.join('.', 'tests', 'unit'),
"-m 'not local_auth and not {}'".format(
's_cred_auth'
if os.environ['AUTH'] == 's_path' else
's_path_auth'
),
'--quiet',
'--cov=pandas_gbq',
'--cov=tests.unit',
Expand Down
28 changes: 21 additions & 7 deletions tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
TABLE_ID = 'new_test'


def _skip_local_auth_if_in_travis_env():
if _in_travis_environment():
pytest.skip("Cannot run local auth in travis environment")


def _skip_if_no_private_key_path():
if not _get_private_key_path():
pytest.skip("Cannot run integration tests without a "
Expand Down Expand Up @@ -172,6 +167,26 @@ def test_generate_bq_schema_deprecated():
gbq.generate_bq_schema(df)


@pytest.fixture(params=[
pytest.param('local', marks=pytest.mark.local_auth),
pytest.param('service_path', marks=pytest.mark.s_path_auth),
pytest.param('service_creds', marks=pytest.mark.s_cred_auth),
])
def auth_type(request):

auth = request.param

if auth == 'local':
pass
elif auth == 'service_path':
_skip_if_no_private_key_path()
elif auth == 'service_creds':
_skip_if_no_private_key_contents()
else:
raise ValueError
return auth


@pytest.fixture()
def credentials():
_skip_if_no_private_key_contents()
Expand Down Expand Up @@ -205,6 +220,7 @@ def test_should_be_able_to_get_results_from_query(self, gbq_connector):
assert pages is not None


@pytest.mark.local_auth
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like test_get_application_default_credentials_does_not_throw_error and test_get_application_default_credentials_returns_credentials are working just fine on Travis if you want to move this to the test_get_user_account_credentials_XXX methods.

class TestAuth(object):

@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -236,15 +252,13 @@ def test_get_application_default_credentials_returns_credentials(self):
assert default_project is not None

def test_get_user_account_credentials_bad_file_returns_credentials(self):
_skip_local_auth_if_in_travis_env()

from google.auth.credentials import Credentials
with mock.patch('__main__.open', side_effect=IOError()):
credentials = self.sut.get_user_account_credentials()
assert isinstance(credentials, Credentials)

def test_get_user_account_credentials_returns_credentials(self):
_skip_local_auth_if_in_travis_env()

from google.auth.credentials import Credentials
credentials = self.sut.get_user_account_credentials()
Expand Down