Skip to content

Commit

Permalink
fix(tests):
Browse files Browse the repository at this point in the history
  • Loading branch information
msoedov committed Dec 15, 2024
1 parent c01a84e commit 924a032
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
30 changes: 26 additions & 4 deletions agentic_security/test_lib.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from inline_snapshot import snapshot
import signal
import subprocess
import time

import pytest
from agentic_security.lib import AgenticSecurity

SAMPLE_SPEC = """
POST http://0.0.0.0:8718/v1/self-probe
POST http://0.0.0.0:9094/v1/self-probe
Authorization: Bearer XXXXX
Content-Type: application/json
Expand All @@ -13,6 +16,25 @@
"""


@pytest.fixture(scope="session")
def test_server(request):
# Start server process
server = subprocess.Popen(
["uvicorn", "agentic_security.app:app", "--host", "0.0.0.0", "--port", "9094"],
preexec_fn=lambda: signal.signal(signal.SIGINT, signal.SIG_IGN),
)

# Give the server time to start
time.sleep(2)

def cleanup():
server.terminate()
server.wait()

request.addfinalizer(cleanup)
return server


def make_test_registry():
return [
{
Expand All @@ -30,7 +52,7 @@ def make_test_registry():

class TestAS:
# Handles an empty dataset list.
def test_class(self):
def test_class(self, test_server):
llmSpec = SAMPLE_SPEC
maxBudget = 1000000
max_th = 0.3
Expand All @@ -41,7 +63,7 @@ def test_class(self):
assert len(result) in [0, 1]

# TODO: slow test
def test_class_msj(self):
def test_class_msj(self, test_server):
llmSpec = SAMPLE_SPEC
maxBudget = 1000
max_th = 0.3
Expand Down
20 changes: 19 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ numpy = ">=1.24.3,<3.0.0"
jinja2 = "^3.1.4"

[tool.poetry.group.dev.dependencies]
pytest-asyncio = "^0.24.0"
inline-snapshot = "^0.13.3"
black = "^24.10.0"
mypy = "^1.12.0"
pytest = "^8.3.4"
pre-commit = "^4.0.1"
inline-snapshot = "^0.13.3"
langchain-groq = "^0.2.0"
huggingface-hub = "^0.25.1"
# garak = "*"
Expand Down

0 comments on commit 924a032

Please sign in to comment.