Skip to content

test: exhaustive pytest coverage#57

Open
deacon-mp wants to merge 1 commit intomasterfrom
test/exhaustive-pytest-coverage
Open

test: exhaustive pytest coverage#57
deacon-mp wants to merge 1 commit intomasterfrom
test/exhaustive-pytest-coverage

Conversation

@deacon-mp
Copy link
Copy Markdown
Contributor

Summary

  • Adds comprehensive pytest test suite covering all manx Python modules (82 tests)
  • Tests terminal API endpoints (splash, get_sessions, sessions, get_history, get_abilities, dynamically_compile)
  • Tests websocket Handle class (run method, session resolution, report logging)
  • Tests TermService initialization and TCP contact selection
  • Tests plugin hook enable/disable, route registration, and special payload setup
  • Includes conftest.py with shared fixtures, mock services, and Caldera framework stubs
  • Covers edge cases: empty inputs, missing data, invalid session IDs, exception handling

Test plan

  • Run pytest tests/ -v to verify all tests pass
  • Run pytest --cov=app tests/ to verify coverage

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a comprehensive pytest suite for the Manx plugin, aiming to cover the HTTP terminal API handlers, websocket terminal handler behavior, service initialization, and plugin hook registration.

Changes:

  • Add new pytest test modules for TermApi, Handle, TermService, and hook.enable.
  • Add a shared conftest.py with Caldera/aiohttp stubs and common fixtures/mocks.
  • Add pytest.ini to configure test discovery and asyncio behavior.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/conftest.py Shared fixtures plus Caldera/aiohttp stubs and import-path bootstrapping for plugins.manx.*.
tests/test_term_api.py Tests TermApi endpoint handlers and dynamically_compile behavior.
tests/test_h_terminal.py Tests websocket Handle.run behavior: session resolution, report logging, JSON response format.
tests/test_term_svc.py Tests TermService initialization and TCP contact selection behavior.
tests/test_hook.py Tests plugin module attributes and enable() route/handle/payload registration.
pytest.ini Configures pytest to run tests under tests/ with asyncio auto mode.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


auth_svc = AsyncMock()
file_svc = AsyncMock()
file_svc.find_file_path = AsyncMock(return_value=('manx', '/tmp/manx-pytest/shells/manx.go'))
Comment on lines +86 to +112
# aiohttp / aiohttp_jinja2 ------------------------------------------------
if 'aiohttp' not in sys.modules:
aiohttp_mod = MagicMock()

class _FakeWebResponse:
def __init__(self, data=None, **kwargs):
self.data = data
self.body = json.dumps(data).encode() if data else b''
self.content_type = 'application/json'

aiohttp_mod.web.json_response = lambda d: _FakeWebResponse(data=d)
aiohttp_mod.web.Response = _FakeWebResponse
sys.modules['aiohttp'] = aiohttp_mod
sys.modules['aiohttp.web'] = aiohttp_mod.web

if 'aiohttp_jinja2' not in sys.modules:
jinja2_mod = MagicMock()

def _fake_template(name):
"""Decorator that just passes through the coroutine."""
def decorator(fn):
return fn
return decorator

jinja2_mod.template = _fake_template
sys.modules['aiohttp_jinja2'] = jinja2_mod

Comment on lines +16 to +39
_repo_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
_plugins_root = os.path.dirname(_repo_root) # parent of manx-pytest

# We need "plugins.manx" to resolve. Create namespace package.
sys.path.insert(0, _plugins_root)

# Ensure the 'plugins' package exists as a namespace
import importlib
if 'plugins' not in sys.modules:
# Create a namespace package pointing to the parent dir
import types
plugins_pkg = types.ModuleType('plugins')
plugins_pkg.__path__ = [os.path.join(_plugins_root)]
plugins_pkg.__package__ = 'plugins'
sys.modules['plugins'] = plugins_pkg

# Ensure plugins.manx points to this repo
if 'plugins.manx' not in sys.modules:
import types
manx_pkg = types.ModuleType('plugins.manx')
manx_pkg.__path__ = [_repo_root]
manx_pkg.__package__ = 'plugins.manx'
sys.modules['plugins.manx'] = manx_pkg

Comment on lines +101 to +105
async def test_returns_json_response(self, api, mock_request):
resp = await api.get_sessions(mock_request())
data = resp.data
assert 'sessions' in data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants