diff --git a/.drone.yml b/.drone.yml index b20fb1c..3961148 100644 --- a/.drone.yml +++ b/.drone.yml @@ -12,7 +12,7 @@ steps: image: eeacms/pylint commands: - pip install -r requirements.txt - - pylint *.py + - pylint beer/*.py tests/*.py - name: docker lint image: hadolint/hadolint @@ -29,6 +29,20 @@ steps: commands: - mdl --style all --warnings . +--- +kind: pipeline +name: unit tests + +steps: +- name: unit test + image: python:slim + commands: + - pip install -r requirements.txt + - python -m pytest tests + +depends_on: +- lint + --- kind: pipeline name: build @@ -45,7 +59,7 @@ steps: from_secret: dockerhub_password depends_on: -- lint +- unit tests --- kind: pipeline diff --git a/Dockerfile b/Dockerfile index d200d10..9a96d59 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ FROM python:slim RUN pip install flask -COPY beer.py /beer.py -COPY templates /templates +COPY /beer/beer.py /beer.py +COPY /beer/templates /templates EXPOSE 5000 CMD ["python", "/beer.py"] diff --git a/beer.py b/beer/beer.py similarity index 100% rename from beer.py rename to beer/beer.py diff --git a/templates/beer.html b/beer/templates/beer.html similarity index 100% rename from templates/beer.html rename to beer/templates/beer.html diff --git a/requirements.txt b/requirements.txt index e3e9a71..2ae9d04 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ Flask +pytest diff --git a/tests/test_beer.py b/tests/test_beer.py new file mode 100644 index 0000000..279dcf7 --- /dev/null +++ b/tests/test_beer.py @@ -0,0 +1,23 @@ +# pylint: disable=no-name-in-module, redefined-outer-name +""" Unit tests """ + +import pytest + +from beer import beer + + +@pytest.fixture +def client(): + """ create flask app """ + + beer.app.config['TESTING'] = True + with beer.app.test_client() as client: + yield client + + +def test_slash(client): + """Test wiwth no param""" + + response = client.get('/') + assert response.status_code == 200 + assert b'beer' in response.data