Skip to content
Snippets Groups Projects
Commit bdbc2848 authored by Riccardo Boero's avatar Riccardo Boero :innocent:
Browse files

Fixing mocked data dir in testing

parent a0ffa3ac
No related branches found
No related tags found
No related merge requests found
Pipeline #2006 failed
import tempfile import tempfile
import requests import os
import threading import threading
import time import time
from polygonqueryonraster.app import GeoTIFFService from polygonqueryonraster.app import GeoTIFFService
...@@ -7,24 +7,27 @@ from polygonqueryonraster.app import GeoTIFFService ...@@ -7,24 +7,27 @@ from polygonqueryonraster.app import GeoTIFFService
def test_flask_app(): def test_flask_app():
# Create a temporary directory for testing # Create a temporary directory for testing
with tempfile.TemporaryDirectory() as tempdir: with tempfile.TemporaryDirectory() as tempdir:
# Create a dummy subdirectory in the temporary directory to avoid StopIteration # Optionally, create a dummy subdirectory in the temporary directory to simulate subdirectories
os.makedirs(os.path.join(tempdir, 'dummy_subdir')) os.makedirs(os.path.join(tempdir, 'dummy_subdir'))
# Start the Flask app # Initialize the service with the temporary directory
service = GeoTIFFService(tempdir, port=5001) service = GeoTIFFService(tempdir, port=5001)
# Start the Flask app in a separate thread
thread = threading.Thread(target=service.run) thread = threading.Thread(target=service.run)
thread.start() thread.start()
# Give it time to start # Give the server some time to start
time.sleep(2) time.sleep(2)
try: try:
# Send a request to the Flask API # Test that the Flask app responds correctly
import requests
response = requests.get('http://127.0.0.1:5001/api') response = requests.get('http://127.0.0.1:5001/api')
assert response.status_code == 200 assert response.status_code == 200
assert response.json()["message"] == "Hello, this is a simple REST API!" assert response.json()["message"] == "Hello, this is a simple REST API!"
finally: finally:
# Stop the Flask server # Stop the Flask app
thread.join(timeout=1) thread.join(timeout=1)
if __name__ == '__main__': if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment