-
Notifications
You must be signed in to change notification settings - Fork 2
test: harden offline coverage, coverage gate, and nightly integration #39
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
Open
robertoecf
wants to merge
1
commit into
main
Choose a base branch
from
test/harden-reliability
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| name: Nightly integration | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: "0 6 * * *" | ||
| workflow_dispatch: | ||
|
|
||
| env: | ||
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true" | ||
|
|
||
| jobs: | ||
| integration: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python 3.12 | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.12" | ||
| cache: pip | ||
|
|
||
| - name: Install | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -e '.[dev]' | ||
|
|
||
| - name: Run integration tests | ||
| id: integration-tests | ||
| run: pytest -m integration -v 2>&1 | tee pytest-integration.log | ||
|
|
||
| - name: Upload failure log | ||
| if: steps.integration-tests.outcome == 'failure' | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: pytest-integration-log | ||
| path: pytest-integration.log | ||
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
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
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,133 @@ | ||
| """Thin API route smoke tests with all upstream traffic mocked.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import re | ||
|
|
||
| import httpx | ||
| import pytest | ||
| import respx | ||
| from fastapi.testclient import TestClient | ||
|
|
||
| from findata.api.app import app | ||
| from findata.http_client import clear_cache | ||
| from findata.sources.cvm import companies | ||
| from findata.sources.tesouro import bonds | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def _reset_module_caches() -> None: | ||
| clear_cache() | ||
| companies._companies_cache.invalidate() | ||
| bonds._bonds_cache.invalidate() | ||
|
|
||
|
|
||
| def _client() -> TestClient: | ||
| return TestClient(app) | ||
|
|
||
|
|
||
| @respx.mock | ||
| def test_ptax_usd_route() -> None: | ||
| respx.get(re.compile(r"https://olinda\.bcb\.gov\.br/.*/CotacaoDolarDia.*")).mock( | ||
| return_value=httpx.Response( | ||
| 200, | ||
| json={ | ||
| "value": [ | ||
| { | ||
| "cotacaoCompra": 4.91, | ||
| "cotacaoVenda": 4.92, | ||
| "dataHoraCotacao": "2024-01-02 13:10:00.000", | ||
| } | ||
| ] | ||
| }, | ||
| ) | ||
| ) | ||
|
|
||
| response = _client().get("/bcb/ptax/usd", params={"date": "2024-01-02"}) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.json()[0]["cotacao_compra"] == 4.91 | ||
|
|
||
|
|
||
| @respx.mock | ||
| def test_focus_annual_route() -> None: | ||
| respx.get(re.compile(r"https://olinda\.bcb\.gov\.br/.*/ExpectativasMercadoAnuais.*")).mock( | ||
| return_value=httpx.Response( | ||
| 200, | ||
| json={ | ||
| "value": [ | ||
| { | ||
| "Indicador": "IPCA", | ||
| "Data": "2024-01-02", | ||
| "DataReferencia": "2024", | ||
| "Media": 3.9, | ||
| "Mediana": 3.8, | ||
| } | ||
| ] | ||
| }, | ||
| ) | ||
| ) | ||
|
|
||
| response = _client().get("/bcb/focus/annual", params={"indicator": "IPCA"}) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.json()[0]["indicador"] == "IPCA" | ||
|
|
||
|
|
||
| @respx.mock | ||
| def test_ibge_indicator_route() -> None: | ||
| respx.get(re.compile(r"https://servicodados\.ibge\.gov\.br/api/v3/agregados/7060/.*")).mock( | ||
| return_value=httpx.Response( | ||
| 200, | ||
| json=[ | ||
| { | ||
| "variavel": "IPCA - Variação mensal", | ||
| "resultados": [ | ||
| { | ||
| "classificacoes": [], | ||
| "series": [ | ||
| { | ||
| "localidade": {"nome": "Brasil"}, | ||
| "serie": {"202401": "0.42"}, | ||
| } | ||
| ], | ||
| } | ||
| ], | ||
| } | ||
| ], | ||
| ) | ||
| ) | ||
|
|
||
| response = _client().get("/ibge/indicators/ipca_mensal", params={"periods": 1}) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.json()[0]["periodo"] == "202401" | ||
|
|
||
|
|
||
| @respx.mock | ||
| def test_tesouro_bonds_route() -> None: | ||
| csv_data = ( | ||
| b"Tipo Titulo;Data Vencimento;Data Base;Taxa Compra Manha;Taxa Venda Manha;" | ||
| b"PU Compra Manha;PU Venda Manha;PU Base Manha\n" | ||
| b"Tesouro Selic;01/03/2029;02/01/2024;0,10;0,11;100,00;99,00;99,50\n" | ||
| ) | ||
| respx.get(bonds.TESOURO_CSV_URL).mock(return_value=httpx.Response(200, content=csv_data)) | ||
|
|
||
| response = _client().get("/tesouro/bonds", params={"tipo": "Selic"}) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.json()[0]["tipo"] == "Tesouro Selic" | ||
|
|
||
|
|
||
| @respx.mock | ||
| def test_cvm_companies_route() -> None: | ||
| csv_data = ( | ||
| "CNPJ_CIA;DENOM_SOCIAL;DENOM_COMERC;CD_CVM;SIT;SETOR_ATIV;CATEG_REG;CONTROLE_ACIONARIO\n" | ||
| "00.000.000/0001-00;Companhia Teste SA;Teste;1234;ATIVO;Financeiro;A;PRIVADO\n" | ||
| ).encode("iso-8859-1") | ||
| respx.get(companies.COMPANIES_URL).mock(return_value=httpx.Response(200, content=csv_data)) | ||
|
|
||
| response = _client().get("/cvm/companies", params={"only_active": "true"}) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.json()[0]["nome_social"] == "Companhia Teste SA" |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: robertoecf/OpenFinData
Length of output: 694
🏁 Script executed:
Repository: robertoecf/OpenFinData
Length of output: 2263
Preserve pytest failures before uploading the failure log.
The run command exits with
tee’s status, so a failedpytestcan make the step succeed withoutpipefail. AddFailure()orcheck()to the upload condition when the job can be canceled, becausesteps.integration-tests.outcome == 'failure'can have no value if the job is canceled.🤖 Prompt for AI Agents