Skip to content

🧪 Add test for check_error#42

Merged
rnovatorov merged 3 commits intomainfrom
add-check-error-tests-3453424892746361646
Apr 1, 2026
Merged

🧪 Add test for check_error#42
rnovatorov merged 3 commits intomainfrom
add-check-error-tests-3453424892746361646

Conversation

@rnovatorov
Copy link
Copy Markdown
Member

🎯 What: The testing gap addressed
The enapter.http.api.errors.check_error function and the associated Error and MultiError classes lacked comprehensive unit testing to verify their expected behaviors under different HTTP response conditions.

📊 Coverage: What scenarios are now tested

  1. Happy Path: Returns without exception when response.is_success is True.
  2. Generic/Non-JSON Error Path: Properly delegates to response.raise_for_status() when a non-success response doesn't contain a JSON payload.
  3. Single API Error: Correctly raises a singular Error with parsed message, code, and details when the API returns an error DTO with exactly one error.
  4. Multiple API Errors: Correctly aggregates and raises a MultiError when the API returns an error DTO with a list of errors.
  5. Error DTO Parsing Edge Cases: Tests empty payload fields and lists to ensure exceptions are raised logically or fallbacks (<no message>) are used.

Result: The improvement in test coverage
src/enapter/http/api/errors.py is now rigorously tested, improving confidence when parsing various shapes of HTTP errors from the Enapter API. Tested the functionality using pytest-asyncio and httpx.Response mocks properly equipped with request properties.


PR created automatically by Jules for task 3453424892746361646 started by @rnovatorov

Added comprehensive unit tests for the `enapter.http.api.errors.check_error` function. Covered all logical branches, including successful responses, generic server errors (non-JSON payloads triggering raise_for_status), and API-specific errors (single and multiple errors from DTO). Also added coverage for empty payloads parsing.

Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Ran `black tests/unit/test_http/test_api/test_errors.py` to fix formatting violations that were causing the CI `make check` step to fail. Now lines involving `httpx.Response` object creation are properly wrapped to respect the line length limit.

Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com>
@rnovatorov
Copy link
Copy Markdown
Member Author

Thx @jules, nice PR! Could you test that check_error reads the response body? This is important for streamed responses.

@google-labs-jules
Copy link
Copy Markdown
Contributor

Thx @jules, nice PR! Could you test that check_error reads the response body? This is important for streamed responses.

Added a new unit test, test_check_error_reads_body, to mock and assert that response.aread() is called properly when checking errors! This verifies the response body is always consumed for streamed requests.

Addresses PR feedback by adding `test_check_error_reads_body` which verifies that `response.aread()` is called when `response.is_success` is False, ensuring the body is completely read for streamed responses. Also fixed PEP8 import order.

Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com>
@rnovatorov rnovatorov marked this pull request as ready for review April 1, 2026 12:44
@rnovatorov rnovatorov merged commit eded498 into main Apr 1, 2026
7 checks passed
@rnovatorov rnovatorov deleted the add-check-error-tests-3453424892746361646 branch April 1, 2026 12:44
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.

1 participant