Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Use tox for testing Python
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorbaptista committed Jan 4, 2018
1 parent 3eaf252 commit 05d229f
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 40 deletions.
28 changes: 14 additions & 14 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ DATABASE_URL=postgres://<user>:<pass>@localhost:5432/goodtables
TEST_DATABASE_URL=postgres://<user>:<pass>@localhost:5432/goodtables_test
BROKER_URL=redis://localhost:6379/10
RESULT_BACKEND=redis://localhost:6379/11
FLASK_SECRET_KEY=change_me
GTIO_SECRET_KEY=change_me
GITHUB_API_TOKEN=change_me
GITHUB_HOOK_SECRET=change_me
GITHUB_CLIENT_ID=change_me
GITHUB_CLIENT_SECRET=change_me
S3_GT_ACCESS_KEY_ID=change_me
S3_GT_SECRET_ACCESS_KEY=change_me
S3_GT_AWS_REGION=change_me
S3_GT_ACCOUNT_ID=change_me
S3_LAMBDA_ARN=change_me
S3_LAMBDA_HOOK_SECRET=change_me
SENTRY_DSN=change_me
GOOGLE_ANALYTICS_CODE=change_me
FLASK_SECRET_KEY=changeme
GTIO_SECRET_KEY=g2PKWio2rEmNiM1X8mpgCt40wunLJti0SMOT-MfIYjU=
GITHUB_API_TOKEN=changeme
GITHUB_HOOK_SECRET=changeme
GITHUB_CLIENT_ID=changeme
GITHUB_CLIENT_SECRET=changeme
S3_GT_ACCESS_KEY_ID=changeme
S3_GT_SECRET_ACCESS_KEY=changeme
S3_GT_AWS_REGION=changeme
S3_GT_ACCOUNT_ID=changeme
S3_LAMBDA_ARN=changeme
S3_LAMBDA_HOOK_SECRET=changeme
GOOGLE_ANALYTICS_CODE=changeme
# SENTRY_DSN=https://<user>:<pass>@sentry.io/<project>
18 changes: 3 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,16 @@ services:
env:
global:
- TESTING=True
- BASE_URL=http://localhost:5000
- TEST_DATABASE_URL=postgres://postgres@localhost:5432/goodtables_test
- BROKER_URL=redis://localhost:6379/10
- RESULT_BACKEND=redis://localhost:6379/11
- FLASK_SECRET_KEY=test-key
- "GTIO_SECRET_KEY=g2PKWio2rEmNiM1X8mpgCt40wunLJti0SMOT-MfIYjU="
- GITHUB_HOOK_SECRET=test-github-hook-secret
- GITHUB_CLIENT_ID=test-github-client-id
- GITHUB_CLIENT_SECRET=test-github-client-secret
- S3_GT_ACCESS_KEY_ID=test
- S3_GT_SECRET_ACCESS_KEY=test
- S3_GT_AWS_REGION=test
- S3_GT_ACCOUNT_ID=test
- S3_LAMBDA_ARN=test
- S3_LAMBDA_HOOK_SECRET=test

before_install:
- nvm install 6
- nvm use 6

install:
- make install
- cp .env.example .env
- pip install flask
- make install-frontend
- make install-dev
- psql -c 'create database goodtables_test;' -U postgres
- make migrate
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ install-backend: ## Install the dependencies for the backend app
pip3 install --upgrade --no-cache-dir --exists-action w -r requirements.txt

install-dev: ## Install the additional development dependencies for the app
pip3 install --upgrade --no-cache-dir -r requirements.dev.txt -r requirements.doc.txt
pip3 install --upgrade --no-cache-dir tox

install-frontend: ## Install the dependencies for frontend development and compilation
npm install

install: install-backend install-frontend ## Install backend and frontend dependencies

lint-backend: ## Run lint checker on the backend app
pylama goodtablesio
tox -e lint

lint-frontend: ## Run lint checker on frontend app
eslint --ext js,vue frontend

lint: lint-backend lint-frontend ## Run all lint checkers

test-unit-backend: ## Run the unit tests for the backend app
py.test --cov goodtablesio --cov-report term-missing
tox

test-unit-frontend: ## Run the unit tests for the frontend app
NODE_ENV=testing karma start
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ after every source code change. Web page should be reloaded manually.

### Testing

Before running the tests, you need to create a test database, and add its credentials to
the `TEST_DATABASE_URL` environment variable in your `.env` file. Considering a
database named `goodtables_test` owned by the Postgres user `goodtables`, that
has password `password`, the `TEST_DATABASE_URL` would be
`postgres://goodtables:password@localhost:5432/goodtables_test`.

You also need to install the `tox` Python dependency by running `pip install tox`.

To run all checks:

```bash
Expand Down
8 changes: 0 additions & 8 deletions requirements.dev.txt

This file was deleted.

46 changes: 46 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[tox]
package = goodtablesio
envlist =
py35

[testenv]
deps =
-r{toxinidir}/requirements.txt
factory-boy
pip-tools
pytest
pytest-cov
pytest-env
coverage
setenv =
TESTING = True
passenv =
BASE_URL
TEST_DATABASE_URL
BROKER_URL
RESULT_BACKEND
FLASK_SECRET_KEY
GTIO_SECRET_KEY
GITHUB_HOOK_SECRET
GITHUB_CLIENT_ID
GITHUB_CLIENT_SECRET
S3_GT_ACCESS_KEY_ID
S3_GT_SECRET_ACCESS_KEY
S3_GT_AWS_REGION
S3_GT_ACCOUNT_ID
S3_LAMBDA_ARN
S3_LAMBDA_HOOK_SECRET
commands =
alembic upgrade head
py.test \
--cov {[tox]package} \
--cov-report term-missing \
{posargs}

[testenv:lint]
deps =
pylama
commands =
pylama \
{toxinidir}/{[tox]package} \
{posargs}

0 comments on commit 05d229f

Please sign in to comment.