docker-compose-ci.yml: adding api tests
This commit is contained in:
parent
e3b406c627
commit
fb109ced06
@ -21,9 +21,8 @@ before_script:
|
||||
|
||||
script:
|
||||
- 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
|
||||
- sh test.sh
|
||||
|
||||
after_script:
|
||||
- docker-compose down
|
||||
|
2
Makefile
2
Makefile
@ -31,4 +31,4 @@ test-e2e:
|
||||
$(NPM) test
|
||||
|
||||
test-python:
|
||||
$(FLASK) test
|
||||
$(FLASK) test_local
|
||||
|
@ -2,12 +2,12 @@ HOST = 0.0.0.0
|
||||
API_PORT = 5000
|
||||
CLIENT_PORT = 3000
|
||||
|
||||
export REACT_APP_API_URL ?= http://$(HOST):$(API_PORT)/api/
|
||||
export FLASK_APP ?= $(PWD)/mpwo_api/server.py
|
||||
export TEST_URL ?= http://$(HOST):$(CLIENT_PORT)
|
||||
export REQUIREMENTS ?= $(PWD)/mpwo_api/requirements.txt
|
||||
export DATABASE_URL ?= postgres://mpwo:mpwo@$(HOST):5432/mpwo
|
||||
export DATABASE_TEST_URL ?= postgres://mpwo:mpwo@$(HOST):5432/mpwo_test
|
||||
export REACT_APP_API_URL = http://$(HOST):$(API_PORT)/api/
|
||||
export FLASK_APP = $(PWD)/mpwo_api/server.py
|
||||
export TEST_URL = http://$(HOST):$(CLIENT_PORT)
|
||||
export REQUIREMENTS = $(PWD)/mpwo_api/requirements.txt
|
||||
export DATABASE_URL = postgres://mpwo:mpwo@$(HOST):5432/mpwo
|
||||
export DATABASE_TEST_URL = postgres://mpwo:mpwo@$(HOST):5432/mpwo_test
|
||||
|
||||
# Python env
|
||||
PYTHON_VERSION ?= python
|
||||
|
@ -19,16 +19,27 @@ def init_db():
|
||||
print('Database initialization done.')
|
||||
|
||||
|
||||
@app.cli.command()
|
||||
def test():
|
||||
def run_test(test_path='mpwo_api/tests'):
|
||||
"""Runs the tests without code coverage."""
|
||||
tests = unittest.TestLoader().discover(
|
||||
'mpwo_api/mpwo_api/tests', pattern='test*.py')
|
||||
test_path, pattern='test*.py')
|
||||
result = unittest.TextTestRunner(verbosity=2).run(tests)
|
||||
if result.wasSuccessful():
|
||||
return 0
|
||||
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__':
|
||||
app.run()
|
||||
|
21
test.sh
Normal file
21
test.sh
Normal 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
|
Loading…
Reference in New Issue
Block a user