File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44import json
55from api .services .cevs_aggregator import compute_cevs_for_company
66from flask import Flask
7- from api .api_server import app as flask_app , load_api_keys
7+ from api .api_server import app as flask_app
88
99
1010def test_global_edgar_endpoint_smoke (monkeypatch ):
11- # Langkah 1: Atur konfigurasi dengan string kunci mentah dari environment
12- flask_app . config [ 'API_KEYS' ] = os . getenv ( 'API_KEYS' )
13- # Langkah 2 (KRITIS): Panggil kembali fungsi parsing untuk memperbarui daftar kunci yang valid
14- load_api_keys ( flask_app )
15- client = flask_app . test_client ()
16-
11+ """
12+ Smoke test for the /global/edgar endpoint.
13+ Uses monkeypatch to ensure API keys are loaded correctly.
14+ """
15+ # Ambil kunci dari environment yang disediakan oleh CI/workflow
16+ api_keys_str = os . getenv ( 'API_KEYS' )
1717 api_key = os .getenv ('TEST_API_KEY' )
18+ if not api_keys_str or not api_key :
19+ pytest .fail ("API_KEYS or TEST_API_KEY environment variables not set in CI." )
20+
21+ # Gunakan monkeypatch untuk mengatur environment variable secara paksa untuk tes ini
22+ monkeypatch .setenv ('API_KEYS' , api_keys_str )
23+
24+ client = flask_app .test_client ()
1825 headers = {'X-API-KEY' : api_key }
1926
2027 resp = client .get ("/global/edgar?country=United%20States&pollutant=PM2.5&window=3" , headers = headers )
Original file line number Diff line number Diff line change 77import os
88import pytest
99from flask import Flask
10- from api .api_server import app as flask_app , load_api_keys
10+ from api .api_server import app as flask_app
1111
1212
1313class TestGlobalRoutes :
1414 """Test all /global/* endpoints for basic functionality and response structure."""
1515
1616 @pytest .fixture
17- def client (self ):
18- """Flask test client for making API requests."""
19- # Langkah 1: Atur konfigurasi dengan string kunci mentah dari environment
20- flask_app .config ['API_KEYS' ] = os .getenv ('API_KEYS' )
21- # Langkah 2 (KRITIS): Panggil kembali fungsi parsing untuk memperbarui daftar kunci yang valid
22- load_api_keys (flask_app )
17+ def client (self , monkeypatch ):
18+ """
19+ Flask test client with patched environment variables.
20+ This ensures the app sees the correct API keys during tests.
21+ """
22+ # Ambil kunci dari environment yang disediakan oleh CI/workflow
23+ api_keys_str = os .getenv ('API_KEYS' )
24+ if not api_keys_str :
25+ pytest .fail ("API_KEYS environment variable not set in CI." )
26+
27+ # Gunakan monkeypatch untuk mengatur environment variable secara paksa untuk tes ini
28+ monkeypatch .setenv ('API_KEYS' , api_keys_str )
29+
30+ # Sekarang, aman untuk membuat test client karena environment sudah benar
2331 return flask_app .test_client ()
2432
2533 @pytest .fixture
You can’t perform that action at this time.
0 commit comments