server/tests: integrate testing into Docker
This commit is contained in:
		
							parent
							
								
									edf9083552
								
							
						
					
					
						commit
						1231469a35
					
				| @ -1,7 +1,13 @@ | ||||
| **/.gitignore | ||||
| .dockerignore | ||||
| # Linter configs | ||||
| .pylintrc | ||||
| Dockerfile | ||||
| config.yaml | ||||
| mypy.ini | ||||
| setup.cfg | ||||
| 
 | ||||
| dev-requirements.txt | ||||
| 
 | ||||
| # Docker build files | ||||
| Dockerfile | ||||
| .dockerignore | ||||
| hooks/ | ||||
| 
 | ||||
| # User configured config file | ||||
| config.yaml | ||||
| @ -9,8 +9,6 @@ domain: # example: http://example.com | ||||
| user_agent: | ||||
| # used to salt the users' password hashes and generate filenames for static content | ||||
| secret: change | ||||
| # required for running the test suite | ||||
| test_database: 'sqlite:///:memory:' | ||||
| 
 | ||||
| # Delete thumbnails and source files on post delete | ||||
| # Original functionality is no, to mitigate the impacts of admins going | ||||
|  | ||||
							
								
								
									
										23
									
								
								server/hooks/test
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										23
									
								
								server/hooks/test
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,23 @@ | ||||
| #!/bin/sh | ||||
| set -e | ||||
| 
 | ||||
| docker build \ | ||||
| 	--build-arg BASE_IMAGE=${IMAGE_NAME} \ | ||||
| 	--file - \ | ||||
| 	--tag ${IMAGE_NAME}-test \ | ||||
| 	. <<'EOF' | ||||
| ARG BASE_IMAGE | ||||
| FROM ${BASE_IMAGE} | ||||
| WORKDIR /opt/app | ||||
| USER root | ||||
| RUN pip3 install --no-cache-dir pytest-cov freezegun | ||||
| USER app | ||||
| ENV POSTGRES_HOST=x \ | ||||
|     POSTGRES_USER=x \ | ||||
|     POSTGRES_PASSWORD=x \ | ||||
|     ESEARCH_HOST=x | ||||
| CMD ["pytest", "szurubooru/", \ | ||||
| 	"--cov-report=term-missing", "--cov=szurubooru", "--tb=short"] | ||||
| EOF | ||||
| 
 | ||||
| docker run --rm -t ${IMAGE_NAME}-test | ||||
| @ -1,3 +0,0 @@ | ||||
| [tool:pytest] | ||||
| testpaths=szurubooru | ||||
| addopts=--cov-report=term-missing --cov=szurubooru --tb=short | ||||
| @ -32,11 +32,8 @@ class QueryCounter: | ||||
|         return self._statements | ||||
| 
 | ||||
| 
 | ||||
| if not config.config['test_database']: | ||||
|     raise RuntimeError('Test database not configured.') | ||||
| 
 | ||||
| _query_counter = QueryCounter() | ||||
| _engine = sa.create_engine(config.config['test_database']) | ||||
| _engine = sa.create_engine('sqlite:///:memory:') | ||||
| model.Base.metadata.drop_all(bind=_engine) | ||||
| model.Base.metadata.create_all(bind=_engine) | ||||
| sa.event.listen( | ||||
| @ -66,9 +63,9 @@ def query_counter(): | ||||
|     return _query_counter | ||||
| 
 | ||||
| 
 | ||||
| @pytest.fixture | ||||
| def query_logger(): | ||||
|     if pytest.config.option.verbose > 0: | ||||
| @pytest.fixture(scope='session') | ||||
| def query_logger(pytestconfig): | ||||
|     if pytestconfig.option.verbose > 0: | ||||
|         import logging | ||||
|         import coloredlogs | ||||
|         coloredlogs.install( | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Shyam Sunder
						Shyam Sunder