Skip to content

Installation and test procedure

Martin 'Hasan' Bramwell edited this page Jan 7, 2014 · 18 revisions

These steps explain how to install and test my version of Anton's gspread: To ensure safe testing, this includes using virtualenv. They describe how to prepare a temporary, disposable virtual environment that will not affect your permanent Python configuration.

Prerequisites

sudo apt-get -y install unzip python-pip python-nose
#
sudo pip install oauth2client virtualenv virtualenvwrapper

Prepare virtual environment

export WORKON_HOME=~/.python_vms
mkdir $WORKON_HOME
# 
pip completion --bash >> ~/.bashrc
echo "export WORKON_HOME=$WORKON_HOME" >> ~/.bashrc
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
echo "alias mkvirtualenv='mkvirtualenv --no-site-packages --distribute'" >> ~/.bashrc
echo "export PIP_VIRTUALENV_BASE=$WORKON_HOME" >> ~/.bashrc
source ~/.bashrc
#
mkdir -p projects
cd projects

Get a copy of gspread

wget -O gspread.zip https://github.com/FleetingClouds/gspread/archive/master.zip
unzip gspread.zip
rm -f gspread.zip
mv gspread-master gspread

Controlling virtual environments

Make a new one:

mkvirtualenv test

Stop using it:

workon test

Use an existing one:

deactivate

Delete one:

rmvirtualenv test

Prepare test configuration

Make a copy of the example configuration

cd /home/yourself/projects/gspread
cp tests/tests.config.example tests/tests.config

Edit the UID/pwd details to begin to access Google Drive. Run the tests, expecting errors:

nosetests

You will see "SpreadsheetNotFound" errors, for nearly all the tests.

Fill in all the remaining details, and test again. Explanations are interspersed with the settings fields.

Google OAuth authentication

To use Google OAuth authentication, please follow the instructions, How to get, use and refresh OAuth access tokens for gspread.

When your OAuth configuration is correct you can run, tests/get_google_oauth2_creds.py. However it expects to find a JSON file on disk containing your OAuth ID and client secret. That is the same JSON file mentioned in the OAuth instructions page mentioned above.

The wizard will ask for the full URL of your spreadsheet. Don't bother to edit it; the "wizard" extracts what it needs.

You will be asked :

Shall we try to open a page in your browser?  (Y/y)  :

The wizard can launch the correct page in your browser if you are running Linux with a GUI on the same machine as the tests. If something goes wrong if you answer 'Y', just answer with 'N' and it will return the URL of Google's OAuth "Request for Permission" page.

It will then ask :

Enter verification code: 

Provide the code returned when you accept to give permission.

Clone this wiki locally