docker-compose-ci.yml: adding api tests

This commit is contained in:
SamR1 2018-01-13 13:00:05 +01:00
parent e3b406c627
commit fb109ced06
5 changed files with 43 additions and 12 deletions

View File

@ -21,9 +21,8 @@ before_script:
script: script:
- psql -c 'create database mpwo_test;' -U postgres - psql -c 'create database mpwo_test;' -U postgres
- echo $DATABASE_TEST_URL
- psql -c '\list' -U postgres
- docker-compose -f docker-compose-ci.yml run api flask init_db - docker-compose -f docker-compose-ci.yml run api flask init_db
- sh test.sh
after_script: after_script:
- docker-compose down - docker-compose down

View File

@ -31,4 +31,4 @@ test-e2e:
$(NPM) test $(NPM) test
test-python: test-python:
$(FLASK) test $(FLASK) test_local

View File

@ -2,12 +2,12 @@ HOST = 0.0.0.0
API_PORT = 5000 API_PORT = 5000
CLIENT_PORT = 3000 CLIENT_PORT = 3000
export REACT_APP_API_URL ?= http://$(HOST):$(API_PORT)/api/ export REACT_APP_API_URL = http://$(HOST):$(API_PORT)/api/
export FLASK_APP ?= $(PWD)/mpwo_api/server.py export FLASK_APP = $(PWD)/mpwo_api/server.py
export TEST_URL ?= http://$(HOST):$(CLIENT_PORT) export TEST_URL = http://$(HOST):$(CLIENT_PORT)
export REQUIREMENTS ?= $(PWD)/mpwo_api/requirements.txt export REQUIREMENTS = $(PWD)/mpwo_api/requirements.txt
export DATABASE_URL ?= postgres://mpwo:mpwo@$(HOST):5432/mpwo export DATABASE_URL = postgres://mpwo:mpwo@$(HOST):5432/mpwo
export DATABASE_TEST_URL ?= postgres://mpwo:mpwo@$(HOST):5432/mpwo_test export DATABASE_TEST_URL = postgres://mpwo:mpwo@$(HOST):5432/mpwo_test
# Python env # Python env
PYTHON_VERSION ?= python PYTHON_VERSION ?= python

View File

@ -19,16 +19,27 @@ def init_db():
print('Database initialization done.') print('Database initialization done.')
@app.cli.command() def run_test(test_path='mpwo_api/tests'):
def test():
"""Runs the tests without code coverage.""" """Runs the tests without code coverage."""
tests = unittest.TestLoader().discover( tests = unittest.TestLoader().discover(
'mpwo_api/mpwo_api/tests', pattern='test*.py') test_path, pattern='test*.py')
result = unittest.TextTestRunner(verbosity=2).run(tests) result = unittest.TextTestRunner(verbosity=2).run(tests)
if result.wasSuccessful(): if result.wasSuccessful():
return 0 return 0
return 1 return 1
@app.cli.command()
def test(test_path='mpwo_api/tests'):
"""Runs the tests without code coverage."""
run_test()
@app.cli.command()
def test_local():
"""Runs the tests without code coverage in local machine w/ make."""
run_test('mpwo_api/mpwo_api/tests')
if __name__ == '__main__': if __name__ == '__main__':
app.run() app.run()

21
test.sh Normal file
View File

@ -0,0 +1,21 @@
#!/bin/bash
fails=''
inspect() {
if [ $1 -ne 0 ]; then
fails="${fails} $2"
fi
}
docker-compose -f docker-compose-ci.yml run api flask test
inspect $? api
if [ -n "${fails}" ];
then
echo "Tests failed: ${fails}"
exit 1
else
echo "Tests passed!"
exit 0
fi