Skip to content

Improve WrappedResponse compatibility and safe repr#20

Open
rvalyi wants to merge 3 commits intomainfrom
codex/analyze-and-suggest-improvements-for-brazil-fiscal-client
Open

Improve WrappedResponse compatibility and safe repr#20
rvalyi wants to merge 3 commits intomainfrom
codex/analyze-and-suggest-improvements-for-brazil-fiscal-client

Conversation

@rvalyi
Copy link
Copy Markdown
Member

@rvalyi rvalyi commented Mar 8, 2026

Motivation

  • Make migration from the legacy erpbrasil.edoc API smoother by exposing familiar attributes on the new WrappedResponse while allowing cleaner future names.
  • Provide a text accessor on wrapped HTTP responses so callers that expect requests.Response.text keep working.
  • Prevent __repr__ from failing or showing uninitialized state when uf is omitted by ensuring it is initialized.

Description

  • Replace direct Logger instantiation with logging.getLogger(__name__) for idiomatic module logger usage.
  • Add WrappedHTTPResponse.text property that decodes content to a string with replacement on errors to mirror requests.Response.text.
  • Add alias properties on WrappedResponse: request_obj, request_xml, response_obj, and response, which return the existing legacy attributes (envio_raiz, envio_xml, resposta, retorno) to support a progressive API rename.
  • Initialize self.uf to None in FiscalClient.__init__ so repr(client) is stable when uf is not provided.
  • Add two unit tests in tests/test_fiscal_client.py: test_wrapped_response_aliases to validate aliases and test_repr_with_no_uf to validate repr behavior.

Testing

  • Added unit tests: test_wrapped_response_aliases and test_repr_with_no_uf in tests/test_fiscal_client.py.
  • Ran python -m compileall brazil_fiscal_client tests, which succeeded.
  • Ran pytest -q, which failed during collection due to a missing external dependency in the environment: ModuleNotFoundError: No module named 'nfelib', so full test execution could not be completed here.

Codex Task

rvalyi added 2 commits March 11, 2026 00:32
### Motivation

- Make migration from the legacy erpbrasil.edoc API smoother by exposing familiar attributes on the new `WrappedResponse` while allowing cleaner future names.
- Provide a `text` accessor on wrapped HTTP responses so callers that expect `requests.Response.text` keep working.
- Prevent `__repr__` from failing or showing uninitialized state when `uf` is omitted by ensuring it is initialized.

### Description

- Replace direct `Logger` instantiation with `logging.getLogger(__name__)` for idiomatic module logger usage.
- Add `WrappedHTTPResponse.text` property that decodes `content` to a string with replacement on errors to mirror `requests.Response.text`.
- Add alias properties on `WrappedResponse`: `request_obj`, `request_xml`, `response_obj`, and `response`, which return the existing legacy attributes (`envio_raiz`, `envio_xml`, `resposta`, `retorno`) to support a progressive API rename.
- Initialize `self.uf` to `None` in `FiscalClient.__init__` so `repr(client)` is stable when `uf` is not provided.
- Add two unit tests in `tests/test_fiscal_client.py`: `test_wrapped_response_aliases` to validate aliases and `test_repr_with_no_uf` to validate `repr` behavior.

### Testing

- Added unit tests: `test_wrapped_response_aliases` and `test_repr_with_no_uf` in `tests/test_fiscal_client.py`.
- Ran `python -m compileall brazil_fiscal_client tests`, which succeeded.
- Ran `pytest -q`, which failed during collection due to a missing external dependency in the environment: `ModuleNotFoundError: No module named 'nfelib'`, so full test execution could not be completed here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant