Developing Websauna

Prerequisites

In order to develop Websauna, the following requirements need to be installed on your system:

  • GCC, make, and similar
  • Python 3.5 with development headers
  • virtualenv
  • pip
  • git
  • Google Chrome
  • chromedriver
  • PostgreSQL
  • Redis

Ubuntu

apt-get install build-essential python-dev python-virtualenv python-pip git redis postgresql

Install from GitHub

Considering a local work folder name Websauna, clone websauna and websauna.ansible repositories from the GitHub:

cd Websauna
git clone [email protected]:websauna/websauna.ansible.git
git clone [email protected]:websauna/websauna.git

Now, create a virtualenv and install websauna into it.

cd websauna
python3.5 -m venv venv
source venv/bin/activate
pip install -e ".[test, dev, celery, utils, notebook]"

Building docs

To generate Sphinx docs locally, run the following:

cd docs
make all

Documentation will be generated inside the build/html folder.

Note

To publish the documentation use make world instead.

Running tests

Unit tests are PyTest based. They use Selenium browser automation framework and Splinter simplified element interaction.

First test run

Create setup-test-secrets.bash (git ignored) with following content:

RANDOM_VALUE="x"
FACEBOOK_CONSUMER_KEY="x"
FACEBOOK_CONSUMER_SECRET="x"
FACEBOOK_USER="x"
FACEBOOK_PASSWORD="x"

export RANDOM_VALUE
export FACEBOOK_CONSUMER_KEY
export FACEBOOK_CONSUMER_SECRET
export FACEBOOK_USER
export FACEBOOK_PASSWORD

Enable it in your shell:

source setup-test-secrets.bash

Tests assume that you have Redis running, make sure you do:

redis-server

Running all tests silently using a headless test browser:

py.test --ini=websauna/conf/test.ini --splinter-webdriver=chrome --splinter-headless=true

Note

Pytest sensible defaults are set on the setup.cfg file, on the top level of websauna repository.

Tox

Tox is used to run tests against multiple versions of Python.

To run tests locally using tox:

tox -- --ini=websauna/conf/test.ini

More examples

Run tests using Tox. Here is a Tox run using Python 3.5 and Chrome:

tox -e py35 -- --ini=websauna/conf/test.ini -x --splinter-webdriver=chrome

Running a single test case with pdb breakpoint support:

py.test -s --ini=test.ini --splinter-webdriver=phantomjs -k test_login_inactive

Running functional tests with an alternative browser:

py.test --ini=websauna/conf/test.ini --splinter-webdriver=firefox websauna/tests/test_frontpage.py