Skip to content

Commit 1fcc7ad

Browse files
committed
unittests
1 parent 4a06268 commit 1fcc7ad

File tree

4 files changed

+150
-0
lines changed

4 files changed

+150
-0
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ jobs:
4141
python -m pip install -e .
4242
python -m pip install build
4343
python -m build
44+
- name: Test
45+
run: |
46+
python -m pip install -r requirements-dev.txt
47+
pytest -vs --container containers.intersystems.com/intersystems/iris-community:latest-preview
4448
- name: Create Beta Release
4549
id: create_release
4650
if: github.event_name == 'push'

requirements-dev.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pytest
2+
pytest-asyncio
3+
testcontainers-iris

tests/conftest.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import pytest
2+
from testcontainers.iris import IRISContainer
3+
4+
5+
def pytest_addoption(parser):
6+
group = parser.getgroup("iris")
7+
8+
group.addoption(
9+
"--embedded",
10+
action="store_true",
11+
help="Use embedded mode",
12+
)
13+
14+
group.addoption(
15+
"--iris-host",
16+
action="store",
17+
default="localhost",
18+
help="Hostname",
19+
)
20+
21+
group.addoption(
22+
"--iris-port",
23+
action="store",
24+
default=1972,
25+
type=int,
26+
help="Port",
27+
)
28+
29+
group.addoption(
30+
"--iris-namespace",
31+
action="store",
32+
default="USER",
33+
help="Namespace",
34+
)
35+
36+
group.addoption(
37+
"--iris-username",
38+
action="store",
39+
default="_SYSTEM",
40+
help="Username",
41+
)
42+
43+
group.addoption(
44+
"--iris-password",
45+
action="store",
46+
default="SYS",
47+
help="Password",
48+
)
49+
50+
group.addoption(
51+
"--container",
52+
action="store",
53+
default=None,
54+
type=str,
55+
help="Docker image with IRIS",
56+
)
57+
58+
59+
def pytest_configure(config: pytest.Config):
60+
global iris
61+
iris = None
62+
if not config.option.container:
63+
return
64+
config.option.embedded = False
65+
print("Starting IRIS container:", config.option.container)
66+
try:
67+
iris = IRISContainer(
68+
config.option.container,
69+
username="test",
70+
password="test",
71+
namespace="TEST",
72+
)
73+
iris.start()
74+
print("Started on port:", iris.get_exposed_port(1972))
75+
print(iris.get_connection_url())
76+
config.option.iris_host = "localhost"
77+
config.option.iris_username = iris.username
78+
config.option.iris_password = iris.password
79+
config.option.iris_namespace = iris.namespace
80+
config.option.iris_port = int(iris.get_exposed_port(1972))
81+
except Exception as ex:
82+
iris = None
83+
pytest.exit("Failed to start IRIS container: " + str(ex))
84+
85+
86+
def pytest_unconfigure(config):
87+
global iris
88+
if iris:
89+
print("Stopping IRIS container")
90+
iris.stop()

tests/test_server.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import sys
2+
import pytest
3+
from mcp.client.session import ClientSession
4+
from mcp.client.stdio import StdioServerParameters, stdio_client
5+
from mcp_server_iris.server import server
6+
7+
8+
@pytest.fixture
9+
def iris_config(request):
10+
return {
11+
"IRIS_HOSTNAME": request.config.option.iris_host,
12+
"IRIS_PORT": str(request.config.option.iris_port),
13+
"IRIS_NAMESPACE": request.config.option.iris_namespace,
14+
"IRIS_USERNAME": request.config.option.iris_username,
15+
"IRIS_PASSWORD": request.config.option.iris_password,
16+
}
17+
18+
19+
def test_server_initialization():
20+
"""Test that the server initializes correctly."""
21+
assert server.name == "InterSystems IRIS MCP Server"
22+
23+
24+
@pytest.mark.asyncio
25+
async def test_list_tools():
26+
"""Test that list_tools returns expected tools."""
27+
tools = await server.list_tools()
28+
assert len(tools) > 0
29+
30+
31+
@pytest.mark.asyncio
32+
async def test_params_in_tool():
33+
tools = await server.list_tools()
34+
execute_sql_tool = next(t for t in tools if t.name == "execute_sql")
35+
props = list(execute_sql_tool.inputSchema["properties"].keys())
36+
assert len(props) == 2
37+
assert props[0] == "query"
38+
assert props[1] == "params"
39+
40+
41+
@pytest.mark.asyncio
42+
async def test_call_tool_execute_sql(iris_config):
43+
"""Test calling execute_sql with a query."""
44+
async with stdio_client(StdioServerParameters(command=sys.executable, args=["-m", "mcp_server_iris"], env=iris_config)) as (read, write):
45+
async with ClientSession(read, write) as session:
46+
await session.initialize()
47+
_ = await session.call_tool(
48+
"execute_sql",
49+
{
50+
"query": "select $namespace, $zversion",
51+
"params": [],
52+
},
53+
)

0 commit comments

Comments
 (0)