docker-compose-ci.yml: adding api tests
This commit is contained in:
parent
e3b406c627
commit
fb109ced06
@ -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
|
||||||
|
2
Makefile
2
Makefile
@ -31,4 +31,4 @@ test-e2e:
|
|||||||
$(NPM) test
|
$(NPM) test
|
||||||
|
|
||||||
test-python:
|
test-python:
|
||||||
$(FLASK) test
|
$(FLASK) test_local
|
||||||
|
@ -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
|
||||||
|
@ -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
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