- Updates CONTRIBUTING.md to explain how to set-up and run these tests. - Requires a version of httplib2 that has not been released on PyPI yet in order to work on Python 3. - Simply creates 3 different token types (JSON key for svc. acct., P12 key for svc. acct., JSON key for user acct.) and then authorizes an httplib2.Http object to hit the USERINFO API.
6.0 KiB
Contributing
- Please sign one of the contributor license agreements below.
- Fork the repo, develop and test your code changes, add docs.
- Make sure that your commit messages clearly describe the changes.
- Send a pull request.
Here are some guidelines for hacking on oauth2client.
Using a Development Checkout
You’ll have to create a development environment to hack on
oauth2client, using a Git checkout:
-
While logged into your GitHub account, navigate to the
oauth2clientrepo on GitHub. -
Fork and clone the
oauth2clientrepository to your GitHub account by clicking the "Fork" button. -
Clone your fork of
oauth2clientfrom your GitHub account to your local computer, substituting your account username and specifying the destination ashack-on-oauth2client. For example:$ cd ${HOME} $ git clone git@github.com:USERNAME/oauth2client.git hack-on-oauth2client $ cd hack-on-oauth2client $ # Configure remotes such that you can pull changes from the oauth2client $ # repository into your local repository. $ git remote add upstream https://github.com:google/oauth2client $ # fetch and merge changes from upstream into master $ git fetch upstream $ git merge upstream/master
Now your local repo is set up such that you will push changes to your GitHub repo, from which you can submit a pull request.
-
Create a virtualenv in which to install
oauth2client:$ cd ~/hack-on-oauth2client $ virtualenv -ppython2.7 envNote that very old versions of virtualenv (virtualenv versions below, say, 1.10 or thereabouts) require you to pass a
--no-site-packagesflag to get a completely isolated environment.You can choose which Python version you want to use by passing a
-pflag tovirtualenv. For example,virtualenv -ppython2.7chooses the Python 2.7 interpreter to be installed.From here on in within these instructions, the
~/hack-on-oauth2client/envvirtual environment you created above will be referred to as$VENV. To use the instructions in the steps that follow literally, use theexport VENV=~/hack-on-oauth2client/envcommand. -
Install
oauth2clientfrom the checkout into the virtualenv usingsetup.py develop. Runningsetup.py developmust be done while the current working directory is theoauth2clientcheckout directory:$ cd ~/hack-on-oauth2client $ $VENV/bin/python setup.py develop
Running Tests
-
To run all tests for
oauth2clienton a single Python version, runnosetestsfrom your development virtualenv (See Using a Development Checkout above). -
To run the full set of
oauth2clienttests on all platforms, installtoxinto a system Python. Thetoxconsole script will be installed into the scripts location for that Python. While in theoauth2clientcheckout root directory (it containstox.ini), invoke thetoxconsole script. This will read thetox.inifile and execute the tests on multiple Python versions and platforms; while it runs, it creates a virtualenv for each version/platform combination. For example:$ sudo pip install tox $ cd ~/hack-on-oauth2client $ tox
Running System Tests
-
To run system tests you can execute:
$ tox -e system-tests $ tox -e system-tests3This alone will not run the tests. You'll need to change some local auth settings and download some service account configuration files from your project to run all the tests.
-
System tests will be run against an actual project and so you'll need to provide some environment variables to facilitate this.
OAUTH2CLIENT_TEST_JSON_KEY_PATH: The path to a service account JSON key file; seetests/data/gcloud/application_default_credentials.jsonas an example. Such a file can be downloaded directly from the developer's console by clicking "Generate new JSON key". See private key docs for more details.OAUTH2CLIENT_TEST_P12_KEY_PATH: The path to a service account P12/PKCS12 key file. You can download this in the same way as a JSON key, just select "P12 Key" as your "Key type" when downloading.OAUTH2CLIENT_TEST_P12_KEY_EMAIL: The service account email corresponding to the P12/PKCS12 key file.OAUTH2CLIENT_TEST_USER_KEY_PATH: The path to a JSON key file for a user. If this is not set, the file created by runninggcloud auth loginwill be used. Seetests/data/gcloud/application_default_credentials_authorized_user.jsonfor an example.OAUTH2CLIENT_TEST_USER_KEY_EMAIL: The user account email corresponding to the user JSON key file.
-
Examples of these can be found in
scripts/local_test_setup.sample. We recommend copying this toscripts/local_test_setup, editing the values and sourcing them into your environment:$ source scripts/local_test_setup
Contributor License Agreements
Before we can accept your pull requests you'll need to sign a Contributor License Agreement (CLA):
- If you are an individual writing original source code and you own the intellectual property, then you'll need to sign an individual CLA.
- If you work for a company that wants to allow you to contribute your work, then you'll need to sign a corporate CLA.
You can sign these electronically (just scroll to the bottom). After that, we'll be able to accept your pull requests.