This repository has been archived by the owner on Jan 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrating test runner from `unittest2`/`nose` to `pytest`. The pytest runner is also compatible with both unittest and nose tests. Some of the benefits of PyTest include: * using plain asserts * function-based fixtures instead of setUp and tearDown * no strange camelCase methods
- Loading branch information
Showing
7 changed files
with
97 additions
and
70 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 _helpers | ||
|
||
__author__ = '[email protected] (Ali Afshar)' | ||
|
||
|
||
def setup_package(): | ||
"""Run on testing package.""" | ||
_helpers.positional_parameters_enforcement = _helpers.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,46 @@ | ||
# Copyright 2016 Google Inc. All rights reserved. | ||
# | ||
# 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 | ||
|
||
from six.moves import reload_module | ||
|
||
from oauth2client import util | ||
|
||
|
||
def set_up_gae_environment(gae_sdk_path): | ||
"""Set 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. | ||
sys.path.insert(0, gae_sdk_path) | ||
import dev_appserver | ||
dev_appserver.fix_sys_path() | ||
|
||
# Fixes timezone and other os-level items. | ||
import google.appengine.tools.os_compat # noqa: unused import | ||
|
||
|
||
def pytest_configure(config): | ||
"""Pytest hook function for setting up test session.""" | ||
# Set up Google SDK modules unless specified not to | ||
if not config.option.no_gae: | ||
set_up_gae_environment(config.option.sdk_path) | ||
# 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 |
---|---|---|
|
@@ -45,6 +45,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' | ||
|
@@ -58,6 +60,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