-
Notifications
You must be signed in to change notification settings - Fork 17
fix: Fix n8n integration test mocking issues #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,10 +10,22 @@ class TestN8nWorkflowTool: | |
|
|
||
| @pytest.fixture | ||
| def mock_httpx(self): | ||
| # Mock httpx in sys.modules to catch lazy imports | ||
| with patch.dict('sys.modules', {'httpx': MagicMock()}) as mock_modules: | ||
| mock_httpx = mock_modules['httpx'] | ||
| yield mock_httpx | ||
| """Mock httpx module for testing.""" | ||
| mock_module = MagicMock() | ||
|
|
||
| # Create proper exception classes | ||
| mock_module.TimeoutException = type('TimeoutException', (Exception,), {}) | ||
|
|
||
| class MockHTTPStatusError(Exception): | ||
| def __init__(self, message, request=None, response=None): | ||
| super().__init__(message) | ||
| self.request = request | ||
| self.response = response | ||
|
|
||
| mock_module.HTTPStatusError = MockHTTPStatusError | ||
|
|
||
| with patch.dict('sys.modules', {'httpx': mock_module}) as mock_modules: | ||
| yield mock_module | ||
|
|
||
| def test_import_n8n_tools(self): | ||
| """Test that n8n tools can be imported.""" | ||
|
|
@@ -69,7 +81,8 @@ def test_n8n_workflow_missing_httpx(self): | |
| from praisonai_tools.n8n import N8nWorkflowTool | ||
|
|
||
| tool = N8nWorkflowTool() | ||
| with patch('praisonai_tools.n8n.n8n_workflow.httpx', None): | ||
| # Mock the import failure using sys.modules approach | ||
| with patch.dict('sys.modules', {'httpx': None}): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The patch on |
||
| with patch('builtins.__import__', side_effect=ImportError("No module named 'httpx'")): | ||
| result = tool.run(workflow_id="test-workflow") | ||
|
Comment on lines
+85
to
87
|
||
| assert "httpx not installed" in result["error"] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
patch.dict('sys.modules', {'httpx': mock_module}) as mock_modulesbindsmock_modulesbut it’s never used, which adds noise (and can trip linters). Drop theas mock_modulesbinding (or use it) to keep the fixture minimal.