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 1 commit into
OCA:14.0from
klodr:14.0-fix-currency_rate_update_xe
Open

[14.0][FIX] currency_rate_update_xe: send User-Agent, raise on HTTP error, mock tests#220
klodr wants to merge 1 commit 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!

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