diff --git a/tests/api/info.txt b/tests/api/info.txt new file mode 100644 index 0000000..b8ec4c8 --- /dev/null +++ b/tests/api/info.txt @@ -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" + ] +} \ No newline at end of file diff --git a/tests/api/test_ratelimit.py b/tests/api/test_ratelimit.py index 964287c..eea55ea 100644 --- a/tests/api/test_ratelimit.py +++ b/tests/api/test_ratelimit.py @@ -1,4 +1,8 @@ -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" @@ -6,22 +10,36 @@ 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" + \ No newline at end of file