forked from maziggy/bambuddy
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(obico): distinguish missing verdicts #172
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| """API regressions for Obico printer verdicts and permission redaction (#141).""" | ||
|
|
||
| from unittest.mock import AsyncMock, MagicMock, patch | ||
|
|
||
| import pytest | ||
| from httpx import AsyncClient | ||
|
|
||
| from backend.app.api.routes.obico import ( | ||
| TestConnectionRequest as ObicoTestConnectionRequest, | ||
| get_printer_status, | ||
| test_connection as obico_test_connection, | ||
| ) | ||
| from backend.app.services.obico_detection import obico_detection_service | ||
| from backend.app.services.obico_smoothing import PrintState | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def clear_detection_state(): | ||
| obico_detection_service._states.clear() | ||
| obico_detection_service._last_class.clear() | ||
| obico_detection_service._errors.clear() | ||
| obico_detection_service._last_error = None | ||
| yield | ||
| obico_detection_service._states.clear() | ||
| obico_detection_service._last_class.clear() | ||
| obico_detection_service._errors.clear() | ||
| obico_detection_service._last_error = None | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| @pytest.mark.integration | ||
| async def test_printer_status_exposes_error_class_and_reason_without_reporting_safe( | ||
| async_client: AsyncClient, | ||
| ): | ||
| obico_detection_service._states[1] = PrintState() | ||
| obico_detection_service._errors[1] = "Obico ML API rejected the token (401)." | ||
| loaded = {"enabled": True, "enabled_printers": None} | ||
|
|
||
| with patch.object( | ||
| obico_detection_service, | ||
| "_load_settings", | ||
| new=AsyncMock(return_value=loaded), | ||
| ): | ||
| response = await async_client.get("/api/v1/obico/printer-status") | ||
|
|
||
| assert response.status_code == 200 | ||
| entry = response.json()["per_printer"]["1"] | ||
| assert entry["class"] == "error" | ||
| assert entry["error"] == "Obico ML API rejected the token (401)." | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_printer_reader_without_settings_permission_gets_class_but_not_internal_reason(): | ||
| obico_detection_service._states[1] = PrintState() | ||
| obico_detection_service._errors[1] = "ML API http://192.168.8.9:3333 refused" | ||
| obico_detection_service._last_error = obico_detection_service._errors[1] | ||
| user = MagicMock() | ||
| user.has_permission.return_value = False | ||
| loaded = {"enabled": True, "enabled_printers": None} | ||
|
|
||
| with patch.object( | ||
| obico_detection_service, | ||
| "_load_settings", | ||
| new=AsyncMock(return_value=loaded), | ||
| ): | ||
| data = await get_printer_status(user=user) | ||
|
|
||
| assert data["per_printer"][1]["class"] == "error" | ||
| assert data["per_printer"][1]["error"] is None | ||
| assert data["last_error"] is None | ||
| assert "192.168.8.9" not in str(data) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_connection_without_payload_values_checks_saved_configuration(): | ||
| loaded = { | ||
| "ml_url": "http://saved-obico:3333", | ||
| "ml_token": "saved-token", | ||
| } | ||
| with ( | ||
| patch.object( | ||
| obico_detection_service, | ||
| "_load_settings", | ||
| new=AsyncMock(return_value=loaded), | ||
| ), | ||
| patch.object( | ||
| obico_detection_service, | ||
| "test_connection", | ||
| new=AsyncMock(return_value={"ok": True}), | ||
| ) as probe, | ||
| ): | ||
| result = await obico_test_connection(ObicoTestConnectionRequest()) | ||
|
|
||
| assert result == {"ok": True} | ||
| probe.assert_awaited_once_with("http://saved-obico:3333", "saved-token") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.