[tests] Add unit tests with pytest #4
					 6 changed files with 42 additions and 4 deletions
				
			
		
							
								
								
									
										18
									
								
								.drone.yml
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								.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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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"]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1,2 @@
 | 
			
		|||
Flask
 | 
			
		||||
pytest
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										23
									
								
								tests/test_beer.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								tests/test_beer.py
									
									
									
									
									
										Normal 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
 | 
			
		||||
		Loading…
	
		Reference in a new issue