Skip to content

Commit 8a5b53c

Browse files
[executors] fix: make fetcher parameter optional for ApiQueryExecutor
1 parent e29b302 commit 8a5b53c

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

libs/garf_executors/garf_executors/api_executor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ def __init__(self, fetcher: report_fetcher.ApiReportFetcher) -> None:
5151

5252
@classmethod
5353
def from_fetcher_alias(
54-
cls, source: str, fetcher_parameters: dict[str, str]
54+
cls, source: str, fetcher_parameters: dict[str, str] | None = None
5555
) -> ApiQueryExecutor:
56+
if not fetcher_parameters:
57+
fetcher_parameters = {}
5658
concrete_api_fetcher = fetchers.get_report_fetcher(source)
5759
return ApiQueryExecutor(concrete_api_fetcher(**fetcher_parameters))
5860

libs/garf_executors/tests/unit/test_api_executor.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,23 @@
1414
from __future__ import annotations
1515

1616
import json
17-
import os
17+
import pathlib
1818

1919
import pytest
2020

2121
from garf_core import api_clients, parsers, report_fetcher
22+
from garf_core.fetchers import fake as fake_fetcher
2223
from garf_executors import api_executor
2324
from garf_io.writers import json_writer
2425

26+
_TEST_DATA = [
27+
{'customer_id': 1},
28+
{'customer_id': 2},
29+
{'customer_id': 3},
30+
]
31+
32+
_TEST_QUERY = 'SELECT customer.id FROM customer'
33+
2534

2635
class TestApiQueryExecutor:
2736
@pytest.fixture
@@ -43,27 +52,37 @@ def test_json_writer(self, tmp_path):
4352
return json_writer.JsonWriter(destination_folder=tmp_path)
4453

4554
def test_execute_returns_success(self, executor, tmp_path):
46-
query_text = 'SELECT customer.id FROM customer'
47-
expected_result = [
48-
{'customer_id': 1},
49-
{'customer_id': 2},
50-
{'customer_id': 3},
51-
]
52-
5355
context = api_executor.ApiExecutionContext(
5456
writer='json',
5557
writer_parameters={'destination_folder': str(tmp_path)},
5658
)
5759
executor.execute(
58-
query=query_text,
60+
query=_TEST_QUERY,
5961
title='test',
6062
context=context,
6163
)
62-
with open(
63-
os.path.join(context.writer_client.destination_folder, 'test.json'),
64+
with pathlib.Path.open(
65+
pathlib.Path(context.writer_client.destination_folder) / 'test.json',
6466
'r',
6567
encoding='utf-8',
6668
) as f:
6769
result = json.load(f)
6870

69-
assert result == expected_result
71+
assert result == _TEST_DATA
72+
73+
def test_from_fetcher_alias_returns_initialized_executor(self, tmp_path):
74+
tmp_file = tmp_path / 'test.json'
75+
with pathlib.Path.open(
76+
tmp_file,
77+
'w',
78+
encoding='utf-8',
79+
) as f:
80+
json.dump(_TEST_DATA, f)
81+
82+
executor = api_executor.ApiQueryExecutor.from_fetcher_alias(
83+
source='fake',
84+
fetcher_parameters={
85+
'json_location': tmp_file,
86+
},
87+
)
88+
assert isinstance(executor.fetcher, fake_fetcher.FakeApiReportFetcher)

0 commit comments

Comments
 (0)