-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor/cloud local improvement (#58)
* some unittest fixes * adding static folder * creating info file
- Loading branch information
1 parent
70ab7f4
commit 0fc39b5
Showing
2 changed files
with
76 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|