Skip to content

Commit

Permalink
fixes #57: Move the environment check in before serving
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxence Guindon committed Mar 20, 2024
1 parent b4429f4 commit 349412e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
35 changes: 18 additions & 17 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,6 @@
'validators': []
}

# Check: do environment variables exist?
# if connection_string is None:
# raise ServerError("Missing environment variable: NACHET_AZURE_STORAGE_CONNECTION_STRING")

# if endpoint_url is None:
# raise ServerError("Missing environment variable: NACHET_MODEL_ENDPOINT_REST_URL")

# if endpoint_api_key is None:
# raise ServerError("Missing environment variables: NACHET_MODEL_ENDPOINT_ACCESS_KEY")

# # Check: are environment variables correct?
# if not bool(re.match(connection_string_regex, connection_string)):
# raise ServerError("Incorrect environment variable: NACHET_AZURE_STORAGE_CONNECTION_STRING")

# if not bool(re.match(endpoint_url_regex, endpoint_url)):
# raise ServerError("Incorrect environment variable: NACHET_MODEL_ENDPOINT_ACCESS_KEY")

app = Quart(__name__)
app = cors(app, allow_origin="*", allow_methods=["GET", "POST", "OPTIONS"])

Expand Down Expand Up @@ -342,6 +325,24 @@ async def fetch_json(repo_URL, key, file_path):

@app.before_serving
async def before_serving():
# Check: do environment variables exist?
if connection_string is None:
raise ServerError("Missing environment variable: NACHET_AZURE_STORAGE_CONNECTION_STRING")

if endpoint_url is None:
raise ServerError("Missing environment variable: NACHET_MODEL_ENDPOINT_REST_URL")

if endpoint_api_key is None:
raise ServerError("Missing environment variables: NACHET_MODEL_ENDPOINT_ACCESS_KEY")

# Check: are environment variables correct?
if not bool(re.match(connection_string_regex, connection_string)):
raise ServerError("Incorrect environment variable: NACHET_AZURE_STORAGE_CONNECTION_STRING")

if not bool(re.match(endpoint_url_regex, endpoint_url)):
raise ServerError("Incorrect environment variable: NACHET_MODEL_ENDPOINT_ACCESS_KEY")


await fetch_json(NACHET_DATA, 'seeds', "seeds/all.json")
await fetch_json(NACHET_MODEL, 'endpoints', 'model_endpoints_metadata.json')

Expand Down
8 changes: 2 additions & 6 deletions tests/test_image_validation.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import unittest
import base64
import json
import asyncio

from app import app
from io import BytesIO
from PIL import Image
from app import app, json, base64, Image, io
from unittest.mock import patch, Mock


class TestImageValidation(unittest.TestCase):
def setUp(self):
self.test_client = app.test_client()

self.img_byte_array = BytesIO()
self.img_byte_array = io.BytesIO()
image = Image.new('RGB', (150, 150), 'blue')
self.image_header = "data:image/PNG;base64,"
image.save(self.img_byte_array, 'PNG')
Expand Down

0 comments on commit 349412e

Please sign in to comment.