Conversation
- Add comprehensive tests for Blitzortung class (65 tests) - Move application and connection pool setup to service/base.py - Make services injectable via constructor for testing - Keep BLITZORTUNG_TEST guard in service/base.py for test isolation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add try-except around log setup to handle permission errors gracefully. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix NameError by moving LogObserver definition before application setup. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Move Blitzortung and LogObserver classes to service/base.py - Keep webservice.py as minimal entry point for twistd - Tests now import from service/base.py Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Matches the new location of the Blitzortung class in service/base.py. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The tests import from service/base.py which has no side effects. The webservice.py is only loaded by twistd. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Not needed since tests use mocks and don't need this factory. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Refactors the Blitzortung JSON-RPC webservice implementation into a dedicated blitzortung.service.base module and adds a new unit test suite to improve coverage.
Changes:
- Added
blitzortung/service/base.pycontainingBlitzortungandLogObserver. - Refactored
blitzortung/cli/webservice.pyto import the new service module and start the server after connection pool creation. - Added
tests/service/test_base.pyto cover key service behaviors and helpers; updatedstart_webserviceentry point imports.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
tests/service/test_base.py |
Adds new tests for Blitzortung and LogObserver. |
blitzortung/service/base.py |
Introduces shared webservice implementation (moved from CLI module). |
blitzortung/cli/webservice.py |
Simplifies twistd entry module to use the extracted service implementation and async pool init. |
blitzortung/cli/start_webservice.py |
Adjusts twistd launcher imports for the refactored webservice module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add tests for jsonrpc_get_strikes_grid - Add tests for jsonrpc_get_global_strikes_grid - Add tests for jsonrpc_get_local_strikes_grid - Add tests for __check_period and __restart_period Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix test name: test_removes_header_for_max_version - Fix LogObserver test to not test buggy path - Add valid user-agent to forbidden IP test - Catch OSError and log instead of silent Exception handling - Remove manual startService() call (relies on setServiceParent) - Add back reactor installation for performance - Remove redundant import from start_webservice.py - Remove unused imports from service/base.py - Fix get_global_strikes_grid to use global_strike_grid_query Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The reactor was already installed by twistd, so importing 'reactor' gives the instance, not the module. Fixed by importing epollreactor or kqreactor module explicitly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| mock_strike_grid_query = Mock() | ||
| mock_strike_grid_query.create = Mock(return_value=(Mock(), Mock())) | ||
| mock_strike_grid_query.combine_result = Mock(return_value=Mock()) | ||
|
|
||
| forbidden_ips = {'192.168.1.100': True} | ||
|
|
||
| bt = Blitzortung( | ||
| mock_pool, | ||
| None, | ||
| strike_grid_query=mock_strike_grid_query, |
There was a problem hiding this comment.
These tests instantiate Blitzortung without providing strike_query/global_strike_grid_query/histogram_query. The Blitzortung constructor will then call blitzortung.service._query() which depends on blitzortung.INJECTOR; in unit tests this is likely uninitialized and can cause test failures. Pass mocks for all query dependencies (or patch blitzortung.service._query) to keep the test isolated.
| mock_strike_grid_query = Mock() | |
| mock_strike_grid_query.create = Mock(return_value=(Mock(), Mock())) | |
| mock_strike_grid_query.combine_result = Mock(return_value=Mock()) | |
| forbidden_ips = {'192.168.1.100': True} | |
| bt = Blitzortung( | |
| mock_pool, | |
| None, | |
| strike_grid_query=mock_strike_grid_query, | |
| mock_strike_query = Mock() | |
| mock_strike_grid_query = Mock() | |
| mock_strike_grid_query.create = Mock(return_value=(Mock(), Mock())) | |
| mock_strike_grid_query.combine_result = Mock(return_value=Mock()) | |
| mock_global_strike_grid_query = Mock() | |
| mock_histogram_query = Mock() | |
| forbidden_ips = {'192.168.1.100': True} | |
| bt = Blitzortung( | |
| mock_pool, | |
| None, | |
| strike_query=mock_strike_query, | |
| strike_grid_query=mock_strike_grid_query, | |
| global_strike_grid_query=mock_global_strike_grid_query, | |
| histogram_query=mock_histogram_query, |
- Fix reactor installation to catch ReactorAlreadyInstalledError in kqreactor branch - Fix referer check to use 'not request.getHeader(\'referer\')' - Fix X-Forwarded-For parsing to handle different separators - Improve test isolation by adding missing mocks for query dependencies Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Validates region is within 1-7 range to prevent KeyError when accessing grid[region]. Uses __force_range for consistency. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|



No description provided.