Merge pull request '[tests] Add unit tests with pytest' (#4) from unittest into master
All checks were successful
continuous-integration/drone/push Build is passing

Reviewed-on: #4
This commit is contained in:
kleph 2020-02-25 01:12:56 +01:00
commit 38d08a841f
6 changed files with 42 additions and 4 deletions

View file

@ -12,7 +12,7 @@ steps:
image: eeacms/pylint image: eeacms/pylint
commands: commands:
- pip install -r requirements.txt - pip install -r requirements.txt
- pylint *.py - pylint beer/*.py tests/*.py
- name: docker lint - name: docker lint
image: hadolint/hadolint image: hadolint/hadolint
@ -29,6 +29,20 @@ steps:
commands: commands:
- mdl --style all --warnings . - 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 kind: pipeline
name: build name: build
@ -45,7 +59,7 @@ steps:
from_secret: dockerhub_password from_secret: dockerhub_password
depends_on: depends_on:
- lint - unit tests
--- ---
kind: pipeline kind: pipeline

View file

@ -1,8 +1,8 @@
FROM python:slim FROM python:slim
RUN pip install flask RUN pip install flask
COPY beer.py /beer.py COPY /beer/beer.py /beer.py
COPY templates /templates COPY /beer/templates /templates
EXPOSE 5000 EXPOSE 5000
CMD ["python", "/beer.py"] CMD ["python", "/beer.py"]

View file

@ -1 +1,2 @@
Flask 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