Skip to content

Commit

Permalink
chore: add postgresql tests in travis
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Crocfer <nicolas.crocfer@corp.ovh.com>
  • Loading branch information
ncrocfer committed Oct 16, 2020
1 parent 1023968 commit d3884ac
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
dist: bionic
language: python

env:
global:
- DIRECTOR_HOME=${TRAVIS_BUILD_DIR}/tests/workflows/
jobs:
- DB=sqlite DIRECTOR_DATABASE_URI=sqlite:////tmp/tests.db
- DB=postgres DIRECTOR_DATABASE_URI=postgresql://localhost:5432/tests

python:
- "3.6"
- "3.7"
- "3.8"

services:
- redis-server
- postgresql

before_install:
- pip install black==20.8b1
Expand All @@ -23,6 +29,8 @@ install:
before_script:
- black --check director
- (cd docs && mkdocs build)
- sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'DROP DATABASE IF EXISTS tests;' -U postgres; fi"
- sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'CREATE DATABASE tests;' -U postgres; fi"

script:
- director celery worker -P solo -D
Expand Down
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ To test Celery Director in real conditions we decided to use an executing `worke
$ (venv) git clone https://github.com/ovh/director && cd director
$ (venv) python setup.py develop
$ (venv) export DIRECTOR_HOME=`pwd`/tests/workflows/
$ (venv) director celery worker
$ (venv) director celery worker -P solo -D
```

Configuration (database, redis...) can be customized in the `$DIRECTOR_HOME/.env` file.
Expand Down
14 changes: 9 additions & 5 deletions tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@
from director.models.users import User


def test_crud(app, client, no_worker):
def test_crud(app, client):
# Create user
user = User(username="test_user", password=generate_password_hash("root_test1"))
user.save()

# Read user
user = User.query.filter_by(username="test_user").first()
with app.app_context():
user = User.query.filter_by(username="test_user").first()
assert user.username == "test_user"
assert check_password_hash(user.password, "root_test1")

# Update user
user.password = generate_password_hash("root_test2")
user.update()
user.save()

user = User.query.filter_by(username="test_user").first()
with app.app_context():
user = User.query.filter_by(username="test_user").first()
assert check_password_hash(user.password, "root_test2")

# Delete user
user.delete()

user = User.query.filter_by(username="test_user").first()
assert user == None
with app.app_context():
user = User.query.filter_by(username="test_user").first()
assert user is None
2 changes: 1 addition & 1 deletion tests/workflows/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DIRECTOR_API_URL="http://127.0.0.1:8000/api"
DIRECTOR_DATABASE_URI="sqlite:////tmp/director_test.db"
DIRECTOR_DATABASE_URI=${DIRECTOR_DATABASE_URI:-sqlite:////tmp/tests.db}
DIRECTOR_BROKER_URI="redis://localhost:6379/0"
DIRECTOR_RESULT_BACKEND_URI="redis://localhost:6379/1"
DIRECTOR_WORKFLOWS_PER_PAGE=15

0 comments on commit d3884ac

Please sign in to comment.