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