Skip to content

Commit 15fc5f3

Browse files
Michael Christensenim-michaelc
authored andcommitted
Increase test coverage
1 parent 4bea05d commit 15fc5f3

File tree

10 files changed

+346
-229
lines changed

10 files changed

+346
-229
lines changed

src/amazon-keyspaces-mcp-server/awslabs/amazon_keyspaces_mcp_server/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ def _build_service_characteristics(self) -> Dict[str, Any]:
456456

457457
def close(self) -> None:
458458
"""Close the session."""
459-
if hasattr(self, 'session') and self.session:
460-
if self.session.cluster:
461-
self.session.cluster.shutdown()
462-
self.session.shutdown()
459+
if self._session:
460+
if self._session.cluster:
461+
self._session.cluster.shutdown()
462+
self._session.shutdown()
463463
logger.info('Closed session')

src/amazon-keyspaces-mcp-server/awslabs/amazon_keyspaces_mcp_server/services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async def execute_read_only_query(self, keyspace_name: str, query: str) -> Dict[
7272
+ query[table_name_start:]
7373
)
7474

75-
return self.cassandra_client.execute_read_only_query(full_query)
75+
return await self.cassandra_client.execute_read_only_query(full_query)
7676

7777

7878
class SchemaService:

src/amazon-keyspaces-mcp-server/tests/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
#
3-
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
4-
# with the License. A copy of the License is located at
3+
# Licensed under the Apache License, Version 2.0 (the "License").
4+
# You may not use this file except in compliance with the License.
5+
# A copy of the License is located at
56
#
67
# http://www.apache.org/licenses/LICENSE-2.0
78
#
8-
# or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
9-
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
9+
# or in the 'license' file accompanying this file.
10+
# This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
11+
# OR CONDITIONS OF ANY KIND, express or implied.
12+
# See the License for the specific language governing permissions
1013
# and limitations under the License.
1114
"""
1215
Test package for keyspaces-mcp.

src/amazon-keyspaces-mcp-server/tests/test_client.py

Lines changed: 82 additions & 49 deletions
Large diffs are not rendered by default.
Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
#
3-
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
4-
# with the License. A copy of the License is located at
3+
# Licensed under the Apache License, Version 2.0 (the "License").
4+
# You may not use this file except in compliance with the License.
5+
# A copy of the License is located at
56
#
67
# http://www.apache.org/licenses/LICENSE-2.0
78
#
8-
# or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
9-
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
9+
# or in the 'license' file accompanying this file.
10+
# This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
11+
# OR CONDITIONS OF ANY KIND, express or implied.
12+
# See the License for the specific language governing permissions
1013
# and limitations under the License.
1114
"""Tests for the awslabs.amazon-keyspaces-mcp-server package."""
1215

@@ -19,31 +22,23 @@ class TestInit:
1922

2023
def test_version(self):
2124
"""Test that __version__ is defined and follows semantic versioning."""
22-
# Import the module
25+
# pylint: disable=import-outside-toplevel
2326
import awslabs.amazon_keyspaces_mcp_server
2427

25-
# Check that __version__ is defined
2628
assert hasattr(awslabs.amazon_keyspaces_mcp_server, '__version__')
27-
28-
# Check that __version__ is a string
2929
assert isinstance(awslabs.amazon_keyspaces_mcp_server.__version__, str)
3030

31-
# Check that __version__ follows semantic versioning (major.minor.patch)
3231
version_pattern = r'^\d+\.\d+\.\d+$'
33-
assert re.match(version_pattern, awslabs.amazon_keyspaces_mcp_server.__version__), (
34-
f"Version '{awslabs.amazon_keyspaces_mcp_server.__version__}' does not follow semantic versioning"
32+
version = awslabs.amazon_keyspaces_mcp_server.__version__
33+
assert re.match(version_pattern, version), (
34+
f"Version '{version}' does not follow semantic versioning"
3535
)
3636

3737
def test_module_reload(self):
3838
"""Test that the module can be reloaded."""
39-
# Import the module
39+
# pylint: disable=import-outside-toplevel
4040
import awslabs.amazon_keyspaces_mcp_server
4141

42-
# Store the original version
4342
original_version = awslabs.amazon_keyspaces_mcp_server.__version__
44-
45-
# Reload the module
4643
importlib.reload(awslabs.amazon_keyspaces_mcp_server)
47-
48-
# Check that the version is still the same
4944
assert awslabs.amazon_keyspaces_mcp_server.__version__ == original_version

src/amazon-keyspaces-mcp-server/tests/test_main.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
#
3-
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
4-
# with the License. A copy of the License is located at
3+
# Licensed under the Apache License, Version 2.0 (the "License").
4+
# You may not use this file except in compliance with the License.
5+
# A copy of the License is located at
56
#
67
# http://www.apache.org/licenses/LICENSE-2.0
78
#
8-
# or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
9-
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
9+
# or in the 'license' file accompanying this file.
10+
# This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
11+
# OR CONDITIONS OF ANY KIND, express or implied.
12+
# See the License for the specific language governing permissions
1013
# and limitations under the License.
1114
"""Tests for the main function in server.py."""
1215

13-
from awslabs.amazon_keyspaces_mcp_server.server import main
16+
import inspect
1417
from unittest.mock import patch
1518

19+
from awslabs.amazon_keyspaces_mcp_server.server import main
20+
1621

1722
class TestMain:
1823
"""Tests for the main function."""
@@ -27,26 +32,16 @@ def test_main_default(self, mock_run):
2732
2. The mcp.run method is called once
2833
3. No transport parameter is passed to mcp.run
2934
"""
30-
# Call the main function
3135
main()
32-
33-
# Check that mcp.run was called with the correct arguments
3436
mock_run.assert_called_once()
3537
assert mock_run.call_args[1].get('transport') is None
3638

3739
def test_module_execution(self):
3840
"""Test the module execution when run as __main__."""
39-
# This test directly executes the code in the if __name__ == '__main__': block
40-
# to ensure coverage of that line
41-
42-
# Get the source code of the module
43-
import inspect
41+
# pylint: disable=import-outside-toplevel
4442
from awslabs.amazon_keyspaces_mcp_server import server
4543

46-
# Get the source code
4744
source = inspect.getsource(server)
48-
49-
# Check that the module has the if __name__ == '__main__': block
5045
assert "if __name__ == '__main__':" in source
5146
assert 'main()' in source
5247

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Tests for models module."""
16+
17+
import unittest
18+
19+
from awslabs.amazon_keyspaces_mcp_server.models import QueryInput
20+
21+
22+
class TestModels(unittest.TestCase):
23+
"""Test cases for models."""
24+
25+
def test_sanitize_query_with_hidden_characters(self):
26+
"""Test query sanitization removes hidden unicode characters."""
27+
input_data = QueryInput(
28+
keyspace='test',
29+
query='SELECT\u200B * FROM\uFEFF users\u0000'
30+
)
31+
self.assertEqual(input_data.query, 'SELECT * FROM users')
32+
33+
34+
if __name__ == '__main__':
35+
unittest.main()

0 commit comments

Comments
 (0)