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 all 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
10 changes: 7 additions & 3 deletions 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,7 +20,12 @@ def default(session):
'pytest',
os.path.join('.', 'tests', 'unit'),
os.path.join('.', 'tests', 'system.py'),
'--quiet',
"-m 'not local_auth and not {}'".format(
's_cred_auth'
if os.environ.get('AUTH') == 's_path' else
's_path_auth'
),
'-v', # Verbose so we can see which tests time out.
'--cov=pandas_gbq',
'--cov=tests.unit',
'--cov-report',
Expand All @@ -37,7 +41,7 @@ def unit(session):
session.run(
'pytest',
os.path.join('.', 'tests', 'unit'),
'--quiet',
'-v', # Verbose so we can see which tests time out.
'--cov=pandas_gbq',
'--cov=tests.unit',
'--cov-report',
Expand Down
31 changes: 22 additions & 9 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 @@ -235,17 +250,15 @@ def test_get_application_default_credentials_returns_credentials(self):
assert isinstance(credentials, Credentials)
assert default_project is not None

@pytest.mark.local_auth
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)

@pytest.mark.local_auth
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()
assert isinstance(credentials, Credentials)
Expand Down