mirror of
https://github.com/hoshikawa2/nemo_guardrails_ci_cd.git
synced 2026-07-10 00:34:20 +00:00
first commit
This commit is contained in:
BIN
tests/__pycache__/conftest.cpython-312-pytest-9.0.2.pyc
Normal file
BIN
tests/__pycache__/conftest.cpython-312-pytest-9.0.2.pyc
Normal file
Binary file not shown.
BIN
tests/__pycache__/test_api_contract.cpython-312-pytest-9.0.2.pyc
Normal file
BIN
tests/__pycache__/test_api_contract.cpython-312-pytest-9.0.2.pyc
Normal file
Binary file not shown.
BIN
tests/__pycache__/test_e2e.cpython-312-pytest-9.0.2.pyc
Normal file
BIN
tests/__pycache__/test_e2e.cpython-312-pytest-9.0.2.pyc
Normal file
Binary file not shown.
BIN
tests/__pycache__/test_structural.cpython-312-pytest-9.0.2.pyc
Normal file
BIN
tests/__pycache__/test_structural.cpython-312-pytest-9.0.2.pyc
Normal file
Binary file not shown.
16
tests/conftest.py
Normal file
16
tests/conftest.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import os
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
from nemoguardrails import RailsConfig, LLMRails
|
||||
|
||||
os.environ.setdefault("OPENAI_API_KEY", "sk-fake")
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def project_root():
|
||||
return Path(__file__).resolve().parent.parent
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def rails(project_root):
|
||||
config_path = project_root / "config"
|
||||
config = RailsConfig.from_path(str(config_path))
|
||||
return LLMRails(config)
|
||||
19
tests/test_api_contract.py
Normal file
19
tests/test_api_contract.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from fastapi.testclient import TestClient
|
||||
from app.main import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
def test_health():
|
||||
r = client.get("/health")
|
||||
assert r.status_code == 200
|
||||
assert r.json()["status"] == "ok"
|
||||
|
||||
def test_chat_allowed_contract():
|
||||
r = client.post("/chat", json={
|
||||
"messages": [{"role": "user", "content": "quero cancelar plano"}]
|
||||
})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert "blocked" in body
|
||||
assert "output" in body
|
||||
assert "rails" in body
|
||||
21
tests/test_e2e.py
Normal file
21
tests/test_e2e.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from fastapi.testclient import TestClient
|
||||
from app.main import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
def test_e2e_toxicidade_bloqueada():
|
||||
r = client.post("/chat", json={
|
||||
"messages": [{"role": "user", "content": "vai se ferrar"}]
|
||||
})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["blocked"] is True
|
||||
|
||||
def test_e2e_pii_mascarado():
|
||||
r = client.post("/chat", json={
|
||||
"messages": [{"role": "user", "content": "Meu CPF é 169.323.728-86 e quero cancelar plano"}]
|
||||
})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["blocked"] is False
|
||||
assert "169.323.728-86" not in body["output"]
|
||||
7
tests/test_structural.py
Normal file
7
tests/test_structural.py
Normal file
@@ -0,0 +1,7 @@
|
||||
def test_config_loads(rails):
|
||||
assert rails is not None
|
||||
|
||||
def test_config_directory_exists(project_root):
|
||||
assert (project_root / "config" / "config.yml").exists()
|
||||
assert (project_root / "config" / "input.co").exists()
|
||||
assert (project_root / "config" / "output.co").exists()
|
||||
Reference in New Issue
Block a user