run tests as part of the build; simplify dockerfile; prep for bitbucket;

This commit is contained in:
Greg Gauthier 2021-02-25 13:41:02 +00:00
parent f09a368ec9
commit bfbe8589d6
5 changed files with 25 additions and 14 deletions

View File

@ -1,21 +1,18 @@
# set base image (host OS) # set base image (host OS)
FROM python:3.9 FROM python:3.9
# set the working directory in the container WORKDIR /
WORKDIR /code COPY service/__init__.py /service/
COPY service/requirements.txt /service/
COPY service/simple.py /service/
# copy the dependencies file to the working directory COPY test/test_simple.py /test/
COPY requirements.txt .
# install dependencies # install dependencies
RUN pip install -r requirements.txt RUN pip install -r /service/requirements.txt
# copy the content of the local src directory to the working directory # Run the tests as the final check
COPY test/ . RUN export PYTHONPATH=$PYTHONPATH:./;pytest -v /test/test_*.py -r A
COPY src/ .
# Run the tests first
CMD [ "pytest", "-v test_*.py"]
# command to run on container start # command to run on container start
CMD [ "python", "./server.py" ] CMD [ "python", "/service/simple.py" ]

3
service/__init__.py Normal file
View File

@ -0,0 +1,3 @@
# Things and such
from .simple import app

View File

@ -61,4 +61,4 @@ def hashit(name):
if __name__ == "__main__": if __name__ == "__main__":
app.run(host="0.0.0.0", port=80) app.run(host="0.0.0.0", port=5000)

View File

@ -1,5 +1,6 @@
import json import json
from app.src.simple import app import pytest
from service.simple import app, hashit
class TestSimple: class TestSimple:
@ -24,3 +25,13 @@ class TestSimple:
resp = self.app.get('/randoms') resp = self.app.get('/randoms')
rjson = json.loads(resp.data) rjson = json.loads(resp.data)
assert len(rjson['string']) <= 80 assert len(rjson['string']) <= 80
@pytest.mark.skip(reason="hash values diverge during unit testing")
def test_hashit(self):
test_name = "George"
test_hash = "-127751659231289515"
response = hashit(test_name)
response_hash = response["hash"]
assert response_hash == test_hash