Skip to content

Commit

Permalink
Refactor/cloud local improvement (#58)
Browse files Browse the repository at this point in the history
* some unittest fixes

* adding static folder

* creating info file
  • Loading branch information
Abellegese authored Mar 7, 2025
1 parent 70ab7f4 commit 0fc39b5
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 16 deletions.
42 changes: 42 additions & 0 deletions tests/api/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"card": {
"Identifier": "eos3b5e",
"Slug": "molecular-weight",
"Status": "Ready",
"Title": "Molecular weight",
"Description": "The model is simply an implementation of the function Descriptors.MolWt of the chemoinformatics package RDKIT. It takes as input a small molecule (SMILES) and calculates its molecular weight in g/mol.\n",
"Mode": "Pretrained",
"Input": [
"Compound"
],
"Input Shape": "Single",
"Task": [
"Regression"
],
"Output": [
"Other value"
],
"Output Type": [
"Float"
],
"Output Shape": "Single",
"Interpretation": "Calculated molecular weight (g/mol)",
"Tag": [
"Molecular weight"
],
"Publication": "https://www.rdkit.org/docs/RDKit_Book.html",
"Source Code": "https://github.com/rdkit/rdkit",
"License": "BSD-3.0",
"Contributor": "miquelduranfrigola",
"S3": "https://ersilia-models-zipped.s3.eu-central-1.amazonaws.com/eos3b5e.zip",
"DockerHub": "https://hub.docker.com/r/ersiliaos/eos3b5e",
"Docker Architecture": [
"AMD64"
]
},
"model_id": "eos3b5e",
"Slug": "molecular-weight",
"api_list": [
"run"
]
}
50 changes: 34 additions & 16 deletions tests/api/test_ratelimit.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
import os, sys
import os
import sys
import json
import pytest

os.environ["ENVIRONMENT"] = "local"
os.environ["RATE_LIMIT"] = "2/minute"
os.environ["REDIS_URI"] = "redis://localhost:6379"

sys.path.insert(0, "../../src/ersilia_pack")

from fastapi.testclient import TestClient

from src.ersilia_pack.templates.app import app




client = TestClient(app)


def test_rate_limiting():
resp_one = client.get("/card")
assert resp_one.status_code == 200, f"Expected 200, got {resp_one.status_code}"

resp_two = client.get("/card")
assert resp_two.status_code == 200, f"Expected 200, got {resp_two.status_code}"

resp_three = client.get("/card")
assert resp_three.status_code == 429, f"Expected 429, got {resp_three.status_code}"
assert "Retry-After" in resp_three.headers, "Missing Retry-After header"
@pytest.fixture
def create_information_file():
current_dir = os.path.dirname(os.path.abspath(__file__))
target_file_path = os.path.normpath(os.path.join(current_dir, "../../src/ersilia_pack/information.json"))

txt_file_path = os.path.join(current_dir, "info.txt")

with open(txt_file_path, "r") as txt_file:
data = json.load(txt_file)

with open(target_file_path, "w") as f:
json.dump(data, f, indent=4)

yield

if os.path.exists(target_file_path):
os.remove(target_file_path)

def test_rate_limiting(create_information_file):
resp_one = client.get("/card")
assert resp_one.status_code == 200, f"Expected 200, got {resp_one.status_code}"

resp_two = client.get("/card")
assert resp_two.status_code == 200, f"Expected 200, got {resp_two.status_code}"

resp_three = client.get("/card")
assert resp_three.status_code == 429, f"Expected 429, got {resp_three.status_code}"
assert "Retry-After" in resp_three.headers, "Missing Retry-After header"

0 comments on commit 0fc39b5

Please sign in to comment.