25 lines
864 B
Python
25 lines
864 B
Python
from app import create_app
|
|
from app.config import Config
|
|
from pathlib import Path
|
|
|
|
|
|
class TestConfig(Config):
|
|
TESTING = True
|
|
MODELS_DIR = Path("tests/fixtures/empty-models")
|
|
DATA_DIR = Path("tests/fixtures/empty-data")
|
|
|
|
|
|
def test_route_contract_and_error_format(monkeypatch):
|
|
monkeypatch.setattr("app.ModelRegistry.scan", lambda self: None)
|
|
app = create_app(TestConfig)
|
|
client = app.test_client()
|
|
|
|
assert client.get("/api/v1/health").status_code == 200
|
|
response = client.get("/api/v1/predict?commodity=unknown&market=pasar_tanjung")
|
|
assert response.status_code == 404
|
|
assert response.json["error"]["code"] == "UNKNOWN_COMMODITY"
|
|
|
|
response = client.get("/api/v1/predict?commodity=rawit&market=pasar_tanjung&horizon=2")
|
|
assert response.status_code == 400
|
|
assert response.json["error"]["code"] == "INVALID_HORIZON"
|