This repository has been archived by the owner on Nov 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Maintainer of pytest_gae needs to merge open PR and push to PyPI. In the mean time, get code directly from GitHub mirror.
- Loading branch information
Showing
7 changed files
with
161 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ docs/_build | |
|
||
# Test files | ||
.tox/ | ||
.cache/ | ||
|
||
# Django test database | ||
db.sqlite3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +0,0 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Test package set-up.""" | ||
|
||
from oauth2client import util | ||
|
||
__author__ = '[email protected] (Ali Afshar)' | ||
|
||
|
||
def setup_package(): | ||
"""Run on testing package.""" | ||
util.positional_parameters_enforcement = util.POSITIONAL_EXCEPTION | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
""" | ||
Common testing tools for OAuth2Client tests. | ||
""" | ||
|
||
import sys | ||
import tempfile | ||
|
||
import pytest | ||
from six.moves import reload_module | ||
|
||
from oauth2client import util | ||
|
||
|
||
def setup_sdk_imports(): | ||
"""Sets up appengine SDK third-party imports.""" | ||
if 'google' in sys.modules: | ||
# Some packages, such as protobuf, clobber the google | ||
# namespace package. This prevents that. | ||
reload_module(sys.modules['google']) | ||
|
||
# This sets up google-provided libraries. | ||
import dev_appserver | ||
dev_appserver.fix_sys_path() | ||
|
||
# Fixes timezone and other os-level items. | ||
import google.appengine.tools.os_compat | ||
(google.appengine.tools.os_compat) | ||
|
||
|
||
def setup_testbed(): | ||
"""Sets up the GAE testbed and enables common stubs.""" | ||
from google.appengine.datastore import datastore_stub_util | ||
from google.appengine.ext import testbed as gaetestbed | ||
|
||
# Setup the datastore and memcache stub. | ||
# First, create an instance of the Testbed class. | ||
tb = gaetestbed.Testbed() | ||
# Then activate the testbed, which prepares the service stubs for | ||
# use. | ||
tb.activate() | ||
# Create a consistency policy that will simulate the High | ||
# Replication consistency model. | ||
policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy( | ||
probability=1.0) | ||
# Initialize the datastore stub with this policy. | ||
tb.init_datastore_v3_stub( | ||
datastore_file=tempfile.mkstemp()[1], | ||
consistency_policy=policy) | ||
tb.init_memcache_stub() | ||
|
||
# Setup remaining stubs. | ||
tb.init_urlfetch_stub() | ||
tb.init_app_identity_stub() | ||
tb.init_blobstore_stub() | ||
tb.init_user_stub() | ||
tb.init_logservice_stub() | ||
# tb.init_taskqueue_stub(root_path='tests/resources') | ||
tb.init_taskqueue_stub() | ||
tb.taskqueue_stub = tb.get_stub(gaetestbed.TASKQUEUE_SERVICE_NAME) | ||
|
||
return tb | ||
|
||
|
||
# py.test helpers | ||
|
||
@pytest.yield_fixture | ||
def testbed(): | ||
"""py.test fixture for the GAE testbed.""" | ||
testbed = setup_testbed() | ||
yield testbed | ||
testbed.deactivate() | ||
|
||
|
||
@pytest.fixture | ||
def login(testbed): | ||
"""py.test fixture for logging in GAE users.""" | ||
def _login(email='[email protected]', id='123', is_admin=False): | ||
testbed.setup_env( | ||
user_email=email, | ||
user_id=id, | ||
user_is_admin='1' if is_admin else '0', | ||
overwrite=True) | ||
return _login | ||
|
||
|
||
def pytest_configure(): | ||
"""Pytest hook function for setting up test session.""" | ||
# Google SDK modules only needed in GAE or GCE | ||
try: | ||
setup_sdk_imports() | ||
except ImportError: | ||
pass | ||
# Default of POSITIONAL_WARNING is too verbose for testing | ||
util.positional_parameters_enforcement = util.POSITIONAL_EXCEPTION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,8 @@ def datafile(filename): | |
class ServiceAccountCredentialsTests(unittest2.TestCase): | ||
|
||
def setUp(self): | ||
self.orig_signer = crypt.Signer | ||
self.orig_verifier = crypt.Verifier | ||
self.client_id = '123' | ||
self.service_account_email = '[email protected]' | ||
self.private_key_id = 'ABCDEF' | ||
|
@@ -59,6 +61,10 @@ def setUp(self): | |
client_id=self.client_id, | ||
) | ||
|
||
def tearDown(self): | ||
crypt.Signer = self.orig_signer | ||
crypt.Verifier = self.orig_verifier | ||
|
||
def test__to_json_override(self): | ||
signer = object() | ||
creds = service_account.ServiceAccountCredentials( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters