mirror of
				https://gitea.publichub.eu/oscar.krause/fastapi-dls.git
				synced 2025-11-04 07:36:08 +00:00 
			
		
		
		
	added api tests
This commit is contained in:
		@@ -16,9 +16,13 @@ build:
 | 
				
			|||||||
    - docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}/${CI_BUILD_REF_NAME}:${CI_BUILD_REF}
 | 
					    - docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}/${CI_BUILD_REF_NAME}:${CI_BUILD_REF}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
test:
 | 
					test:
 | 
				
			||||||
 | 
					  image: python:3.10-alpine
 | 
				
			||||||
  stage: test
 | 
					  stage: test
 | 
				
			||||||
 | 
					  before_script:
 | 
				
			||||||
 | 
					    - pip install pytest httpx
 | 
				
			||||||
 | 
					    - cd test
 | 
				
			||||||
  script:
 | 
					  script:
 | 
				
			||||||
    - echo "Nothing to do ..."
 | 
					    - pytest main.py
 | 
				
			||||||
 | 
					
 | 
				
			||||||
deploy:
 | 
					deploy:
 | 
				
			||||||
  stage: deploy
 | 
					  stage: deploy
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										23
									
								
								test/main.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								test/main.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					from starlette.testclient import TestClient
 | 
				
			||||||
 | 
					import importlib.util
 | 
				
			||||||
 | 
					import sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					MODULE, PATH = 'main.app', '../app/main.py'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					spec = importlib.util.spec_from_file_location(MODULE, PATH)
 | 
				
			||||||
 | 
					main = importlib.util.module_from_spec(spec)
 | 
				
			||||||
 | 
					sys.modules[MODULE] = main
 | 
				
			||||||
 | 
					spec.loader.exec_module(main)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					client = TestClient(main.app)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_index():
 | 
				
			||||||
 | 
					    response = client.get('/')
 | 
				
			||||||
 | 
					    assert response.status_code == 200
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_status():
 | 
				
			||||||
 | 
					    response = client.get('/status')
 | 
				
			||||||
 | 
					    assert response.status_code == 200
 | 
				
			||||||
 | 
					    assert response.json()['status'] == 'up'
 | 
				
			||||||
		Reference in New Issue
	
	Block a user