Skip to content

[14.0][FIX] currency_rate_update_xe: send User-Agent, raise on HTTP error, mock tests - #220

Open
klodr wants to merge 2 commits into
OCA:14.0from
klodr:14.0-fix-currency_rate_update_xe
Open

klodr wants to merge 2 commits into
OCA:14.0from
klodr:14.0-fix-currency_rate_update_xe

Conversation

@klodr

@klodr klodr commented Jun 20, 2026

Copy link
Copy Markdown

Backport to 14.0 of the xe.com fix from #216 (16.0) and #218 (17.0), made hermetic.

Problem

test_cron / test_wizard fail with AssertionError: 0 != 1: xe.com now returns 403 for requests without a User-Agent, and 404 on the dated endpoint (?date=<today>). The scheduled run always ends on today, so no rate is produced.

Fix (as discussed in #216 / #218)

  • _request_data: send a User-Agent, add a request timeout and raise_for_status() → an HTTP error surfaces as a clean UserError instead of being parsed as empty HTML.
  • _get_historical_rate: fall back to the latest endpoint (no ?date=) for today/future days, as _get_latest_rate already does.

Tests made hermetic

The tests no longer hit xe.com: _request_data is mocked, and the latest/historical fallback, the HTML parsing and the HTTP-error path are all covered. This removes the dependency on the live website — the actual cause of the recurring red CI raised in the comments of #216 / #218.

Context

This also unblocks the CI of #219 (currency_rate_update_wise), currently held red only by these unrelated xe failures. wise relies on a stable authenticated JSON API rather than HTML scraping, so its own tests are already deterministic.

Refs #216, #218.

…rror, mock tests

xe.com now returns HTTP 403 for requests without a User-Agent, and HTTP 404 for
the dated endpoint (?date=YYYY-MM-DD) when the date is today or in the future.
The scheduled run always ends on today, so test_cron / test_wizard failed with
"0 != 1" (no rate produced).

Backport to 14.0 of the fix from OCA#216 (16.0) and OCA#218 (17.0):
- _request_data: send a User-Agent header, add a request timeout and
  raise_for_status(), so an HTTP error surfaces as a clean UserError instead of
  being silently parsed as empty HTML;
- _get_historical_rate: fall back to the latest endpoint (no ?date=) for today
  and future days, as _get_latest_rate already does.

The tests are also made hermetic: the HTTP layer is mocked (no real call to
xe.com), covering the latest/historical fallback, the HTML parsing and the
HTTP-error path. The test no longer depends on the live website, which is the
root cause of the recurring CI failures raised in the comments of OCA#216 and OCA#218.

Signed-off-by: Claude Perrin <klodr@users.noreply.github.com>
@OCA-git-bot OCA-git-bot added mod:currency_rate_update_xe Module currency_rate_update_xe series:14.0 labels Jun 20, 2026
@klodr

klodr commented Jun 20, 2026

Copy link
Copy Markdown
Author

@OCA/currency-maintainers @DarioLodeiros could you please review? This backports to 14.0 the xe.com fix from #216/#218 (User-Agent + latest-endpoint fallback) and additionally makes the tests hermetic (HTTP mocked), so they no longer depend on the live website. test with OCB/test with Odoo are green; the remaining pre-commit red is the pkg_resources infra issue fixed by #221. Thanks!

… ImportError

setuptools-odoo 3.1.8 imports the removed `pkg_resources` module, so the
`setuptools-odoo-make-default` and `setuptools-odoo-get-requirements` hooks fail
with `ModuleNotFoundError: No module named 'pkg_resources'` on recent
setuptools (>= 81). This makes the pre-commit check red on every PR currently
opened against this branch.

Bump the hook to 3.3.2, same as OCA#217 for 16.0.

Signed-off-by: Claude Perrin <klodr@users.noreply.github.com>
@klodr

klodr commented Sep 12, 2026

Copy link
Copy Markdown
Author

Folded #221 into this PR, because the two were deadlocking each other:

pre-commit test with Odoo / test with OCB
this PR (xe fix) ❌ setuptools-odoo → pkg_resources ImportError ✅ ✅
#221 (setuptools-odoo 3.1.8 → 3.3.2) ✅ ❌ ❌ (the very xe tests this PR fixes)

Each one fixed the check the other was failing, so neither could ever go green on its own — and since the CI runs the whole repo's test suite, the two failing currency_rate_update_xe tests were keeping every open 14.0 PR red.

The one-line .pre-commit-config.yaml bump from #221 is now the second commit here, so this branch should be green end to end. #221 will be closed as redundant.

@OCA/currency-maintainers — this is the unblocking change for the 14.0 branch; once it lands, the other pending 14.0 PRs should go green on rebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:currency_rate_update_xe Module currency_rate_update_xe series:14.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants