[tests] Add unit tests with pytest
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is failing

This commit is contained in:
kleph 2020-02-24 23:20:20 +01:00
parent 2ba3a12b92
commit 9b34a898a3
6 changed files with 42 additions and 4 deletions

View file

@ -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

View file

@ -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"]

View file

@ -1 +1,2 @@
Flask
pytest

23
tests/test_beer.py Normal file
View file

@ -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'<title>beer</title>' in response.data